mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 14:02:44 +00:00
add start for layout edit dialog
This commit is contained in:
parent
33e03cedd0
commit
e2ebd32f25
5 changed files with 80 additions and 11 deletions
|
@ -79,7 +79,7 @@ fun loadCustomLayout(layoutContent: String, layoutName: String, languageTag: Str
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkLayout(layoutContent: String, context: Context): Boolean {
|
fun checkLayout(layoutContent: String, context: Context): Boolean {
|
||||||
val params = KeyboardParams()
|
val params = KeyboardParams()
|
||||||
params.mId = KeyboardLayoutSet.getFakeKeyboardId(KeyboardId.ELEMENT_ALPHABET)
|
params.mId = KeyboardLayoutSet.getFakeKeyboardId(KeyboardId.ELEMENT_ALPHABET)
|
||||||
params.mPopupKeyTypes.add(POPUP_KEYS_LAYOUT)
|
params.mPopupKeyTypes.add(POPUP_KEYS_LAYOUT)
|
||||||
|
|
|
@ -14,9 +14,10 @@ import helium314.keyboard.latin.utils.prefs
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
// todo (roughly in order)
|
// todo (roughly in order)
|
||||||
// make all prefs actually work
|
|
||||||
// default buttons for toolbar key(s) customizer, icon customizer, and toolbar reorder dialog
|
// default buttons for toolbar key(s) customizer, icon customizer, and toolbar reorder dialog
|
||||||
// make a dialog wrapper that has a default button?
|
// 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
|
// 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)
|
// make the pref lists more compact (compare with old settings)
|
||||||
// try making text size similar to old state (also in dialogs)
|
// try making text size similar to old state (also in dialogs)
|
||||||
|
|
|
@ -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)
|
||||||
|
)
|
||||||
|
}
|
|
@ -40,6 +40,7 @@ fun TextInputDialog(
|
||||||
backgroundColor: Color = MaterialTheme.colorScheme.surface,
|
backgroundColor: Color = MaterialTheme.colorScheme.surface,
|
||||||
contentColor: Color = contentColorFor(backgroundColor),
|
contentColor: Color = contentColorFor(backgroundColor),
|
||||||
properties: DialogProperties = DialogProperties(),
|
properties: DialogProperties = DialogProperties(),
|
||||||
|
singleLine: Boolean = true,
|
||||||
keyboardType: KeyboardType = KeyboardType.Unspecified,
|
keyboardType: KeyboardType = KeyboardType.Unspecified,
|
||||||
checkTextValid: (text: String) -> Boolean = { it.isNotBlank() }
|
checkTextValid: (text: String) -> Boolean = { it.isNotBlank() }
|
||||||
) {
|
) {
|
||||||
|
@ -73,7 +74,7 @@ fun TextInputDialog(
|
||||||
modifier = Modifier.fillMaxWidth().focusRequester(focusRequester),
|
modifier = Modifier.fillMaxWidth().focusRequester(focusRequester),
|
||||||
label = textInputLabel,
|
label = textInputLabel,
|
||||||
keyboardOptions = KeyboardOptions(keyboardType = keyboardType),
|
keyboardOptions = KeyboardOptions(keyboardType = keyboardType),
|
||||||
singleLine = true
|
singleLine = singleLine
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
shape = shape,
|
shape = shape,
|
||||||
|
@ -90,7 +91,8 @@ private fun Preview() {
|
||||||
onDismissRequest = {},
|
onDismissRequest = {},
|
||||||
onConfirmed = {},
|
onConfirmed = {},
|
||||||
title = { Text("Title") },
|
title = { Text("Title") },
|
||||||
initialText = "some text",
|
initialText = "some text\nand another line",
|
||||||
|
singleLine = false,
|
||||||
textInputLabel = { Text("fill it") }
|
textInputLabel = { Text("fill it") }
|
||||||
)
|
)
|
||||||
}
|
}
|
|
@ -29,6 +29,7 @@ import helium314.keyboard.settings.SettingsDestination
|
||||||
import helium314.keyboard.settings.SliderPreference
|
import helium314.keyboard.settings.SliderPreference
|
||||||
import helium314.keyboard.settings.SwitchPreference
|
import helium314.keyboard.settings.SwitchPreference
|
||||||
import helium314.keyboard.settings.Theme
|
import helium314.keyboard.settings.Theme
|
||||||
|
import helium314.keyboard.settings.dialogs.TextInputDialog
|
||||||
import helium314.keyboard.settings.keyboardNeedsReload
|
import helium314.keyboard.settings.keyboardNeedsReload
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -50,12 +51,11 @@ fun AdvancedSettingsScreen(
|
||||||
SettingsActivity2.allPrefs.map[Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY]!!.Preference()
|
SettingsActivity2.allPrefs.map[Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY]!!.Preference()
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
||||||
SettingsActivity2.allPrefs.map[Settings.PREF_SHOW_SETUP_WIZARD_ICON]!!.Preference()
|
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_SYMBOL_SPACE]!!.Preference() // todo: this is ugly
|
||||||
SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_EMOJI]!!.Preference()
|
SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_EMOJI]!!.Preference() // todo: this is ugly
|
||||||
SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_CLIP]!!.Preference()
|
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_CUSTOM_CURRENCY_KEY]!!.Preference()
|
||||||
SettingsActivity2.allPrefs.map[Settings.PREF_MORE_POPUP_KEYS]!!.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_SYMBOLS_NUMBER_LAYOUTS]!!.Preference()
|
||||||
SettingsActivity2.allPrefs.map[NonSettingsPrefs.CUSTOM_FUNCTIONAL_LAYOUTS]!!.Preference()
|
SettingsActivity2.allPrefs.map[NonSettingsPrefs.CUSTOM_FUNCTIONAL_LAYOUTS]!!.Preference()
|
||||||
SettingsActivity2.allPrefs.map[NonSettingsPrefs.BACKUP_RESTORE]!!.Preference()
|
SettingsActivity2.allPrefs.map[NonSettingsPrefs.BACKUP_RESTORE]!!.Preference()
|
||||||
|
@ -179,7 +179,12 @@ fun createAdvancedPrefs(context: Context) = listOf(
|
||||||
name = it.title,
|
name = it.title,
|
||||||
onClick = { showDialog = true }
|
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) {
|
PrefDef(context, NonSettingsPrefs.CUSTOM_FUNCTIONAL_LAYOUTS, R.string.customize_functional_key_layouts) {
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
@ -187,7 +192,7 @@ fun createAdvancedPrefs(context: Context) = listOf(
|
||||||
name = it.title,
|
name = it.title,
|
||||||
onClick = { showDialog = true }
|
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) {
|
PrefDef(context, NonSettingsPrefs.BACKUP_RESTORE, R.string.backup_restore_title) {
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
@ -195,7 +200,7 @@ fun createAdvancedPrefs(context: Context) = listOf(
|
||||||
name = it.title,
|
name = it.title,
|
||||||
onClick = { showDialog = true }
|
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) {
|
PrefDef(context, NonSettingsPrefs.DEBUG_SETTINGS, R.string.debug_settings_title) {
|
||||||
Preference(
|
Preference(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue