From 8a13804faf7b51be8e4f2de1945d8d7b3945d2db Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Tue, 23 Jul 2024 12:09:27 +0300 Subject: [PATCH] Add Edit Actions submenu in settings --- .../latin/uix/actions/MoreActions.kt | 46 ++++++++++++------- .../latin/uix/settings/pages/Typing.kt | 28 ++++++++--- 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/java/src/org/futo/inputmethod/latin/uix/actions/MoreActions.kt b/java/src/org/futo/inputmethod/latin/uix/actions/MoreActions.kt index d8a2c956e..43e43ce7f 100644 --- a/java/src/org/futo/inputmethod/latin/uix/actions/MoreActions.kt +++ b/java/src/org/futo/inputmethod/latin/uix/actions/MoreActions.kt @@ -71,7 +71,9 @@ fun ActionItem(action: Action, modifier: Modifier = Modifier, dragIcon: Boolean Icon( painterResource(id = R.drawable.move), contentDescription = null, - modifier = dragIconModifier.size(16.dp).align(Alignment.TopEnd), + modifier = dragIconModifier + .size(16.dp) + .align(Alignment.TopEnd), tint = LocalContentColor.current.copy(alpha = 0.6f) ) } @@ -125,7 +127,9 @@ fun MoreActionsView() { } LazyVerticalGrid( - modifier = Modifier.fillMaxWidth().padding(8.dp), + modifier = Modifier + .fillMaxWidth() + .padding(8.dp), columns = GridCells.Adaptive(98.dp), horizontalArrangement = Arrangement.spacedBy(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp) @@ -143,14 +147,18 @@ val CategoryTitleStyle = Typography.titleMedium.copy(fontWeight = FontWeight.W50 @OptIn(ExperimentalFoundationApi::class) @Composable -fun ActionsEditor() { +fun ActionsEditor(header: @Composable () -> Unit) { val context = LocalContext.current val view = LocalView.current - val initialList: List = remember { - context.getSettingBlocking(ActionsSettings).toActionEditorItems().ensureWellFormed().filter { - it !is ActionEditorItem.Item || it.action.shownInEditor + val initialList: List = if(!LocalInspectionMode.current) { + remember { + context.getSettingBlocking(ActionsSettings).toActionEditorItems().ensureWellFormed().filter { + it !is ActionEditorItem.Item || it.action.shownInEditor + } } + } else { + DefaultActionSettings.flattenToActionEditorItems() } val list = remember { initialList.toMutableStateList() } @@ -162,10 +170,12 @@ fun ActionsEditor() { view.performHapticFeedback(HapticFeedbackConstants.SEGMENT_FREQUENT_TICK) } - DisposableEffect(Unit) { - onDispose { - val map = list.toActionMap() - context.updateSettingsWithNewActions(map) + if(!LocalInspectionMode.current) { + DisposableEffect(Unit) { + onDispose { + val map = list.toActionMap() + context.updateSettingsWithNewActions(map) + } } } @@ -204,12 +214,12 @@ fun ActionsEditor() { ReorderableItem(reorderableLazyListState, key = it.toKey(), enabled = it.category != ActionCategory.entries[0]) { _ -> Column { if (it.category == ActionCategory.entries[0]) { - Box(Modifier.defaultMinSize(minHeight = 72.dp), contentAlignment = Alignment.BottomStart) { - if (actionMap[ActionCategory.ActionKey]?.let { it.size > 1 } == true) { - Tip("Only one Action Key can be set, anything after the first is ignored") - } else if (actionMap[ActionCategory.PinnedKey]?.let { it.size > 4 } == true) { - Tip("You have more pinned actions than seems reasonable. Consider moving some to favorites") - } + header() + + if (actionMap[ActionCategory.ActionKey]?.let { it.size > 1 } == true) { + Tip("Only one Action Key can be set, anything after the first is ignored") + } else if (actionMap[ActionCategory.PinnedKey]?.let { it.size > 4 } == true) { + Tip("You have more pinned actions than seems reasonable. Consider moving some to favorites") } } Text(it.category.name(context), modifier = Modifier.padding(top = 24.dp), style = CategoryTitleStyle, color = LocalContentColor.current.copy(alpha = 0.6f)) @@ -231,7 +241,9 @@ fun ActionEditor() { color = MaterialTheme.colorScheme.background, shape = RoundedCornerShape(32.dp, 32.dp, 0.dp, 0.dp) ) { - ActionsEditor() + ActionsEditor { + ScreenTitle(title = "Edit actions") + } } } diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Typing.kt b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Typing.kt index 01476d0dc..16420281c 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Typing.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Typing.kt @@ -4,6 +4,7 @@ import android.content.Context import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.gestures.detectDragGestures import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.lazy.LazyItemScope import androidx.compose.foundation.lazy.LazyListScope @@ -60,6 +61,8 @@ import org.futo.inputmethod.latin.uix.KeyboardHeightMultiplierSetting import org.futo.inputmethod.latin.uix.PreferenceUtils import org.futo.inputmethod.latin.uix.SHOW_EMOJI_SUGGESTIONS import org.futo.inputmethod.latin.uix.SettingsKey +import org.futo.inputmethod.latin.uix.actions.ActionEditor +import org.futo.inputmethod.latin.uix.actions.ActionsEditor import org.futo.inputmethod.latin.uix.actions.ClipboardHistoryEnabled import org.futo.inputmethod.latin.uix.getSettingBlocking import org.futo.inputmethod.latin.uix.settings.DataStoreItem @@ -96,6 +99,16 @@ fun NavGraphBuilder.addTypingNavigation( composable("typing") { TypingScreen(navController) } composable("resize") { ResizeScreen(navController) } composable("longPress") { LongPressScreen(navController) } + composable("actionEdit") { ActionEditorScreen(navController) } +} + +@Preview(showBackground = true) +@Composable +fun ActionEditorScreen(navController: NavHostController = rememberNavController()) { + Column { + ScreenTitle("Edit Actions", showBack = true, navController) + ActionsEditor { } + } } @Preview(showBackground = true) @@ -328,13 +341,6 @@ fun LongPressScreen(navController: NavHostController = rememberNavController()) ) } - /* - SettingToggleDataStore( - title = "Spacebar language switcher", - subtitle = "Show the language switching menu when long-pressing the space", - setting = KeyHintsSetting - )*/ - longPressKeyLayoutEditor( context = context, setting = setting, @@ -444,6 +450,14 @@ fun TypingScreen(navController: NavHostController = rememberNavController()) { icon = painterResource(id = R.drawable.keyboard) ) + NavigationItem( + title = "Edit Actions", + subtitle = "Edit favorite actions, pinned actions, and the action key next to the spacebar", + style = NavigationItemStyle.Misc, + navigate = { navController.navigate("actionEdit") }, + icon = painterResource(id = R.drawable.smile) + ) + SettingToggleDataStore( title = "Show action/suggestions bar", subtitle = "Show the bar containing suggestions. Recommended to keep enabled",