diff --git a/app/src/main/java/helium314/keyboard/latin/utils/CustomLayoutUtils.kt b/app/src/main/java/helium314/keyboard/latin/utils/CustomLayoutUtils.kt index 1b7329af4..35b48c18c 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/CustomLayoutUtils.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/CustomLayoutUtils.kt @@ -79,7 +79,7 @@ fun loadCustomLayout(layoutContent: String, layoutName: String, languageTag: Str .show() } -private fun checkLayout(layoutContent: String, context: Context): Boolean { +fun checkLayout(layoutContent: String, context: Context): Boolean { val params = KeyboardParams() params.mId = KeyboardLayoutSet.getFakeKeyboardId(KeyboardId.ELEMENT_ALPHABET) params.mPopupKeyTypes.add(POPUP_KEYS_LAYOUT) diff --git a/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt b/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt index f2d4add07..e6a20f0b0 100644 --- a/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt +++ b/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt @@ -14,9 +14,10 @@ import helium314.keyboard.latin.utils.prefs import kotlinx.coroutines.flow.MutableStateFlow // todo (roughly in order) -// make all prefs actually work // default buttons for toolbar key(s) customizer, icon customizer, and toolbar reorder dialog // make a dialog wrapper that has a default button? +// yes, definitely need a 3 button dialog... +// make all prefs actually work // try moving the recomposition of pref change somewhere else, so it's not duplicated everywhere // make the pref lists more compact (compare with old settings) // try making text size similar to old state (also in dialogs) diff --git a/app/src/main/java/helium314/keyboard/settings/dialogs/LayoutEditDialog.kt b/app/src/main/java/helium314/keyboard/settings/dialogs/LayoutEditDialog.kt new file mode 100644 index 000000000..95194ab64 --- /dev/null +++ b/app/src/main/java/helium314/keyboard/settings/dialogs/LayoutEditDialog.kt @@ -0,0 +1,61 @@ +package helium314.keyboard.settings.dialogs + +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import helium314.keyboard.latin.R +import helium314.keyboard.latin.utils.checkLayout +import helium314.keyboard.latin.utils.getCustomLayoutFile +import helium314.keyboard.latin.utils.getLayoutDisplayName +import helium314.keyboard.latin.utils.onCustomLayoutFileListChanged +import helium314.keyboard.settings.keyboardNeedsReload + +// todo: height MUST respect keyboard, or it's impossible to fill the bottom part +@Composable +fun LayoutEditDialog( + onDismissRequest: () -> Unit, + layoutName: String, + startContent: String? = null, + displayName: String? = null +) { + val ctx = LocalContext.current + val file = getCustomLayoutFile(layoutName, ctx) + val initialText = startContent ?: file.readText() + var showDeleteConfirmation by remember { mutableStateOf(false) } + // todo: try make it really full width, at least if we have a json file + // todo: ok button should be "save" + // todo: if displayName not null, there is an existing file + TextInputDialog( + onDismissRequest = onDismissRequest, + onConfirmed = { + file.parentFile?.mkdir() + file.writeText(it) + onCustomLayoutFileListChanged() + keyboardNeedsReload = true + }, + initialText = initialText, + singleLine = false, + title = { Text(displayName ?: getLayoutDisplayName(layoutName)) }, + checkTextValid = { + checkLayout(it, ctx) // todo: toast with reason why it doesn't work -> should re-do getting the reason + }, + // todo: delete button if displayName not null and file exists + ) + if (showDeleteConfirmation) + ConfirmationDialog( + onDismissRequest = { showDeleteConfirmation = false }, + onConfirmed = { + onDismissRequest() + file.delete() + onCustomLayoutFileListChanged() + keyboardNeedsReload = true + }, + text = { Text(stringResource(R.string.delete_layout, displayName ?: "")) }, + confirmButtonText = stringResource(R.string.delete) + ) +} diff --git a/app/src/main/java/helium314/keyboard/settings/dialogs/TextInputDialog.kt b/app/src/main/java/helium314/keyboard/settings/dialogs/TextInputDialog.kt index cf00e2c17..3dce756e6 100644 --- a/app/src/main/java/helium314/keyboard/settings/dialogs/TextInputDialog.kt +++ b/app/src/main/java/helium314/keyboard/settings/dialogs/TextInputDialog.kt @@ -40,6 +40,7 @@ fun TextInputDialog( backgroundColor: Color = MaterialTheme.colorScheme.surface, contentColor: Color = contentColorFor(backgroundColor), properties: DialogProperties = DialogProperties(), + singleLine: Boolean = true, keyboardType: KeyboardType = KeyboardType.Unspecified, checkTextValid: (text: String) -> Boolean = { it.isNotBlank() } ) { @@ -73,7 +74,7 @@ fun TextInputDialog( modifier = Modifier.fillMaxWidth().focusRequester(focusRequester), label = textInputLabel, keyboardOptions = KeyboardOptions(keyboardType = keyboardType), - singleLine = true + singleLine = singleLine ) }, shape = shape, @@ -90,7 +91,8 @@ private fun Preview() { onDismissRequest = {}, onConfirmed = {}, title = { Text("Title") }, - initialText = "some text", + initialText = "some text\nand another line", + singleLine = false, textInputLabel = { Text("fill it") } ) } \ No newline at end of file diff --git a/app/src/main/java/helium314/keyboard/settings/screens/AdvancedScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/AdvancedScreen.kt index 0773d5dac..e81a0f1d0 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/AdvancedScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/AdvancedScreen.kt @@ -29,6 +29,7 @@ import helium314.keyboard.settings.SettingsDestination import helium314.keyboard.settings.SliderPreference import helium314.keyboard.settings.SwitchPreference import helium314.keyboard.settings.Theme +import helium314.keyboard.settings.dialogs.TextInputDialog import helium314.keyboard.settings.keyboardNeedsReload @Composable @@ -50,12 +51,11 @@ fun AdvancedSettingsScreen( SettingsActivity2.allPrefs.map[Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY]!!.Preference() if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) SettingsActivity2.allPrefs.map[Settings.PREF_SHOW_SETUP_WIZARD_ICON]!!.Preference() - SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_SYMBOL_SPACE]!!.Preference() - SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_EMOJI]!!.Preference() - SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_CLIP]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_SYMBOL_SPACE]!!.Preference() // todo: this is ugly + SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_EMOJI]!!.Preference() // todo: this is ugly + SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_CLIP]!!.Preference() // todo: this is ugly SettingsActivity2.allPrefs.map[Settings.PREF_CUSTOM_CURRENCY_KEY]!!.Preference() SettingsActivity2.allPrefs.map[Settings.PREF_MORE_POPUP_KEYS]!!.Preference() - SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_EMOJI]!!.Preference() SettingsActivity2.allPrefs.map[NonSettingsPrefs.CUSTOM_SYMBOLS_NUMBER_LAYOUTS]!!.Preference() SettingsActivity2.allPrefs.map[NonSettingsPrefs.CUSTOM_FUNCTIONAL_LAYOUTS]!!.Preference() SettingsActivity2.allPrefs.map[NonSettingsPrefs.BACKUP_RESTORE]!!.Preference() @@ -179,7 +179,12 @@ fun createAdvancedPrefs(context: Context) = listOf( name = it.title, onClick = { showDialog = true } ) -// if (showDialog) todo: show the currency customizer + if (showDialog) // todo: first the selection dialog, then the edit dialog + TextInputDialog( + onDismissRequest = { showDialog = false }, + onConfirmed = { }, // todo + initialText = LocalContext.current.assets.open("layouts/dvorak.json").bufferedReader().readText() + ) }, PrefDef(context, NonSettingsPrefs.CUSTOM_FUNCTIONAL_LAYOUTS, R.string.customize_functional_key_layouts) { var showDialog by remember { mutableStateOf(false) } @@ -187,7 +192,7 @@ fun createAdvancedPrefs(context: Context) = listOf( name = it.title, onClick = { showDialog = true } ) -// if (showDialog) todo: show the currency customizer +// if (showDialog) todo: show the customizer }, PrefDef(context, NonSettingsPrefs.BACKUP_RESTORE, R.string.backup_restore_title) { var showDialog by remember { mutableStateOf(false) } @@ -195,7 +200,7 @@ fun createAdvancedPrefs(context: Context) = listOf( name = it.title, onClick = { showDialog = true } ) -// if (showDialog) todo: show the currency customizer +// if (showDialog) todo: show the dialog }, PrefDef(context, NonSettingsPrefs.DEBUG_SETTINGS, R.string.debug_settings_title) { Preference(