fix: colors and commonize things

This commit is contained in:
FunkyMuse 2023-09-25 17:11:01 +02:00
parent c900309502
commit 3a3e6aa83d
4 changed files with 75 additions and 28 deletions

View file

@ -2,15 +2,11 @@ package com.simplemobiletools.commons.dialogs
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.window.DialogProperties
@ -19,9 +15,7 @@ import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState
import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState
import com.simplemobiletools.commons.compose.extensions.MyDevices
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.compose.theme.Shapes
import com.simplemobiletools.commons.models.BlockedNumber
import kotlinx.coroutines.android.awaitFrame
@Composable
fun AddOrEditBlockedNumberAlertDialog(
@ -30,11 +24,14 @@ fun AddOrEditBlockedNumberAlertDialog(
deleteBlockedNumber: (String) -> Unit,
addBlockedNumber: (String) -> Unit
) {
val keyboardController = LocalSoftwareKeyboardController.current
val focusRequester = remember { FocusRequester() }
var textFieldValue by remember { mutableStateOf(blockedNumber?.number.orEmpty()) }
AlertDialog(
modifier = Modifier.fillMaxWidth(0.9f),
containerColor = dialogContainerColor,
modifier = Modifier
.dialogWidth
.dialogBorder,
properties = DialogProperties(usePlatformDefaultWidth = false),
onDismissRequest = alertDialogState::hide,
confirmButton = {
@ -63,7 +60,7 @@ fun AddOrEditBlockedNumberAlertDialog(
Text(text = stringResource(id = R.string.cancel))
}
},
shape = Shapes.medium,
shape = dialogShape,
text = {
OutlinedTextField(
modifier = Modifier
@ -74,7 +71,10 @@ fun AddOrEditBlockedNumberAlertDialog(
textFieldValue = it
},
supportingText = {
Text(text = stringResource(id = R.string.add_blocked_number_helper_text))
Text(
text = stringResource(id = R.string.add_blocked_number_helper_text),
color = MaterialTheme.colorScheme.onSurface
)
},
label = {
Text(text = stringResource(id = R.string.number))
@ -82,14 +82,9 @@ fun AddOrEditBlockedNumberAlertDialog(
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Phone)
)
},
tonalElevation = dialogElevation
)
LaunchedEffect(Unit) {
//await two frames to render the scrim and the dialog
awaitFrame()
awaitFrame()
keyboardController?.show()
focusRequester.requestFocus()
}
ShowKeyboardWhenDialogIsOpenedAndRequestFocus(focusRequester = focusRequester)
}
@Composable

View file

@ -4,7 +4,6 @@ import android.app.Activity
import android.text.Html
import android.text.method.LinkMovementMethod
import androidx.appcompat.app.AlertDialog
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
@ -24,7 +23,6 @@ import com.simplemobiletools.commons.compose.extensions.MyDevices
import com.simplemobiletools.commons.compose.screens.LinkifyText
import com.simplemobiletools.commons.compose.screens.stringFromHTML
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.compose.theme.Shapes
import com.simplemobiletools.commons.databinding.DialogTextviewBinding
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.getStringsPackageName
@ -75,7 +73,10 @@ fun AppSideLoadedAlertDialog(
val context = LocalContext.current
val url = remember { "https://play.google.com/store/apps/details?id=${context.getStringsPackageName()}" }
AlertDialog(
modifier = Modifier.fillMaxWidth(0.9f),
containerColor = dialogContainerColor,
modifier = Modifier
.dialogWidth
.dialogBorder,
properties = DialogProperties(usePlatformDefaultWidth = false),
onDismissRequest = alertDialogState::hide,
confirmButton = {
@ -94,7 +95,7 @@ fun AppSideLoadedAlertDialog(
Text(text = stringResource(id = R.string.cancel))
}
},
shape = Shapes.medium,
shape = dialogShape,
text = {
val source = stringResource(id = R.string.sideloaded_app, url)
LinkifyText(fontSize = 16.sp, removeUnderlines = false) {
@ -109,6 +110,7 @@ fun AppSideLoadedAlertDialog(
fontWeight = FontWeight.Bold,
)
},
tonalElevation = dialogElevation
)
}
@ -116,11 +118,6 @@ fun AppSideLoadedAlertDialog(
@MyDevices
private fun AppSideLoadedAlertDialogPreview() {
AppThemeSurface {
AddOrEditBlockedNumberAlertDialog(
blockedNumber = null,
deleteBlockedNumber = {},
addBlockedNumber = {},
alertDialogState = rememberAlertDialogState()
)
AppSideLoadedAlertDialog(alertDialogState = rememberAlertDialogState(), onDownloadClick = {}, onCancelClick = {})
}
}

View file

@ -0,0 +1,54 @@
package com.simplemobiletools.commons.dialogs
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.SoftwareKeyboardController
import androidx.compose.ui.unit.dp
import com.simplemobiletools.commons.compose.theme.LocalTheme
import com.simplemobiletools.commons.compose.theme.Shapes
import com.simplemobiletools.commons.compose.theme.light_grey_stroke
import com.simplemobiletools.commons.compose.theme.model.Theme
import kotlinx.coroutines.android.awaitFrame
val dialogContainerColor
@ReadOnlyComposable
@Composable get() = when (LocalTheme.current) {
is Theme.BlackAndWhite -> Color.Black
else -> MaterialTheme.colorScheme.surface
}
val dialogShape get() = Shapes.medium
val dialogElevation = 0.dp
val Modifier.dialogWidth: Modifier
get() = then(Modifier.fillMaxWidth(0.9f))
val Modifier.dialogBorder: Modifier
@ReadOnlyComposable
@Composable get() =
when (LocalTheme.current) {
is Theme.BlackAndWhite -> then(Modifier.border(1.dp, light_grey_stroke, Shapes.medium))
else -> Modifier
}
@Composable
fun ShowKeyboardWhenDialogIsOpenedAndRequestFocus(
keyboardController: SoftwareKeyboardController? = LocalSoftwareKeyboardController.current,
focusRequester: FocusRequester?
) {
LaunchedEffect(Unit) {
//await two frames to render the scrim and the dialog
awaitFrame()
awaitFrame()
keyboardController?.show()
focusRequester?.requestFocus()
}
}

View file

@ -89,6 +89,7 @@ class MainActivity : BaseSimpleActivity() {
override fun onResume() {
super.onResume()
setupToolbar(binding.mainToolbar)
AppSideloadedDialog(this) {
}