mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-21 17:24:14 +00:00
move dialogs to separate files and folder
This commit is contained in:
parent
85438ea33d
commit
e7c2301643
3 changed files with 62 additions and 35 deletions
|
@ -0,0 +1,59 @@
|
|||
package helium314.keyboard.settings.dialogs
|
||||
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.contentColorFor
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import helium314.keyboard.latin.R
|
||||
|
||||
// taken from StreetComplete
|
||||
/** Slight specialization of an alert dialog: AlertDialog with OK and Cancel button. Both buttons
|
||||
* call [onDismissRequest] and the OK button additionally calls [onConfirmed]. */
|
||||
@Composable
|
||||
fun ConfirmationDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
onConfirmed: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
title: @Composable (() -> Unit)? = null,
|
||||
text: @Composable (() -> Unit)? = null,
|
||||
confirmButtonText: String = stringResource(android.R.string.ok),
|
||||
cancelButtonText: String = stringResource(android.R.string.cancel),
|
||||
shape: Shape = MaterialTheme.shapes.medium,
|
||||
backgroundColor: Color = MaterialTheme.colorScheme.surface,
|
||||
contentColor: Color = contentColorFor(backgroundColor),
|
||||
properties: DialogProperties = DialogProperties(),
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onConfirmed(); onDismissRequest() }) { Text(confirmButtonText) }
|
||||
},
|
||||
modifier = modifier,
|
||||
dismissButton = { TextButton(onClick = onDismissRequest) { Text(cancelButtonText) } },
|
||||
title = title,
|
||||
text = text,
|
||||
shape = shape,
|
||||
containerColor = backgroundColor,
|
||||
textContentColor = contentColor,
|
||||
properties = properties,
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun PreviewConfirmDialog() {
|
||||
ConfirmationDialog(
|
||||
onDismissRequest = { },
|
||||
onConfirmed = {},
|
||||
confirmButtonText = "I don't care",
|
||||
text = { Text(stringResource(R.string.disable_personalized_dicts_message)) }
|
||||
)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package helium314.keyboard.settings
|
||||
package helium314.keyboard.settings.dialogs
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
|
@ -32,38 +32,6 @@ import androidx.compose.ui.unit.dp
|
|||
import androidx.compose.ui.window.DialogProperties
|
||||
|
||||
// taken from StreetComplete
|
||||
/** Slight specialization of an alert dialog: AlertDialog with OK and Cancel button. Both buttons
|
||||
* call [onDismissRequest] and the OK button additionally calls [onConfirmed]. */
|
||||
@Composable
|
||||
fun ConfirmationDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
onConfirmed: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
title: @Composable (() -> Unit)? = null,
|
||||
text: @Composable (() -> Unit)? = null,
|
||||
confirmButtonText: String = stringResource(android.R.string.ok),
|
||||
cancelButtonText: String = stringResource(android.R.string.cancel),
|
||||
shape: Shape = MaterialTheme.shapes.medium,
|
||||
backgroundColor: Color = MaterialTheme.colorScheme.surface,
|
||||
contentColor: Color = contentColorFor(backgroundColor),
|
||||
properties: DialogProperties = DialogProperties(),
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onConfirmed(); onDismissRequest() }) { Text(confirmButtonText) }
|
||||
},
|
||||
modifier = modifier,
|
||||
dismissButton = { TextButton(onClick = onDismissRequest) { Text(cancelButtonText) } },
|
||||
title = title,
|
||||
text = text,
|
||||
shape = shape,
|
||||
containerColor = backgroundColor,
|
||||
textContentColor = contentColor,
|
||||
properties = properties,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> ListPickerDialog(
|
||||
onDismissRequest: () -> Unit,
|
|
@ -26,8 +26,6 @@ import helium314.keyboard.latin.settings.UserDictionaryListFragment
|
|||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||
import helium314.keyboard.latin.utils.Log
|
||||
import helium314.keyboard.settings.AllPrefs
|
||||
import helium314.keyboard.settings.ConfirmationDialog
|
||||
import helium314.keyboard.settings.ListPickerDialog
|
||||
import helium314.keyboard.settings.NonSettingsPrefs
|
||||
import helium314.keyboard.settings.PrefDef
|
||||
import helium314.keyboard.settings.Preference
|
||||
|
@ -36,6 +34,8 @@ import helium314.keyboard.settings.SearchPrefScreen
|
|||
import helium314.keyboard.settings.SettingsActivity2
|
||||
import helium314.keyboard.settings.SwitchPreference
|
||||
import helium314.keyboard.settings.Theme
|
||||
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
||||
import helium314.keyboard.settings.dialogs.ListPickerDialog
|
||||
import helium314.keyboard.settings.getActivity
|
||||
import helium314.keyboard.settings.themeChanged
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue