mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Add Edit Actions submenu in settings
This commit is contained in:
parent
52084de79b
commit
8a13804faf
@ -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,15 +147,19 @@ 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<ActionEditorItem> = remember {
|
||||
val initialList: List<ActionEditorItem> = 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() }
|
||||
val lazyListState = rememberLazyGridState()
|
||||
@ -162,12 +170,14 @@ fun ActionsEditor() {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.SEGMENT_FREQUENT_TICK)
|
||||
}
|
||||
|
||||
if(!LocalInspectionMode.current) {
|
||||
DisposableEffect(Unit) {
|
||||
onDispose {
|
||||
val map = list.toActionMap()
|
||||
context.updateSettingsWithNewActions(map)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val actionMap = list.toActionMap()
|
||||
|
||||
@ -204,14 +214,14 @@ 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) {
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user