From f008d9366cfd8f8c6d590d2c1f0d8a3930d26a28 Mon Sep 17 00:00:00 2001
From: MM20 <15646950+MM2-0@users.noreply.github.com>
Date: Sun, 11 Aug 2024 22:34:45 +0200
Subject: [PATCH] Add hints for dragn and drop arrangable preferences
---
.../filterbar/FilterBarSettingsScreen.kt | 27 +++++-
.../SearchActionsSettingsScreen.kt | 90 +++++++++++++++++--
.../SearchActionsSettingsScreenVM.kt | 4 +-
core/i18n/src/main/res/values/strings.xml | 1 +
4 files changed, 114 insertions(+), 8 deletions(-)
diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/filterbar/FilterBarSettingsScreen.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/filterbar/FilterBarSettingsScreen.kt
index 4b5a5b9a..ad0d67b5 100644
--- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/filterbar/FilterBarSettingsScreen.kt
+++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/filterbar/FilterBarSettingsScreen.kt
@@ -2,9 +2,13 @@ package de.mm20.launcher2.ui.settings.filterbar
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.animation.core.animateDpAsState
+import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.rounded.ArrowBack
+import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.rounded.ArrowBack
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.HorizontalDivider
@@ -19,6 +23,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
+import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
@@ -86,7 +91,7 @@ fun FilterBarSettingsScreen() {
activity?.onBackPressed()
}
}) {
- Icon(imageVector = Icons.Rounded.ArrowBack, contentDescription = "Back")
+ Icon(imageVector = Icons.AutoMirrored.Rounded.ArrowBack, contentDescription = "Back")
}
},
)
@@ -103,6 +108,26 @@ fun FilterBarSettingsScreen() {
modifier = Modifier
.fillMaxSize()
) {
+ item(
+ key = "disabled-info"
+ ) {
+ Row(
+ modifier = Modifier
+ .padding(start = 28.dp, top = 16.dp, end = 16.dp, bottom = 16.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Icon(Icons.Outlined.Info, null,
+ modifier = Modifier.padding(end = 24.dp).size(16.dp),
+ tint = MaterialTheme.colorScheme.secondary
+ )
+ Text(
+ modifier = Modifier,
+ text = stringResource(R.string.hint_drag_and_drop_reorder),
+ style = MaterialTheme.typography.titleSmall,
+ color = MaterialTheme.colorScheme.secondary
+ )
+ }
+ }
for (i in 0 until KeyboardFilterBarItem.entries.size) {
val item = enabledItems!!.getOrNull(i) ?: disabledItems[i - enabledItems!!.size]
val prevItem = enabledItems!!.getOrNull(i - 1) ?: disabledItems.getOrNull(i - enabledItems!!.size - 1)
diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/SearchActionsSettingsScreen.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/SearchActionsSettingsScreen.kt
index 9c2087df..60ca4cd3 100644
--- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/SearchActionsSettingsScreen.kt
+++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/SearchActionsSettingsScreen.kt
@@ -7,16 +7,24 @@ import androidx.browser.customtabs.CustomTabsIntent
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.rounded.Add
import androidx.compose.material.icons.rounded.ArrowBack
+import androidx.compose.material.icons.rounded.Delete
+import androidx.compose.material.icons.rounded.Edit
import androidx.compose.material.icons.rounded.HelpOutline
+import androidx.compose.material.icons.rounded.MoreVert
import androidx.compose.material3.CenterAlignedTopAppBar
+import androidx.compose.material3.DropdownMenu
+import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
@@ -27,6 +35,10 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
@@ -66,7 +78,7 @@ fun SearchActionsSettingsScreen() {
onDragStart = {
it.key != "divider" && !(it.key as String).startsWith("disabled-")
},
- onItemMove = { from, to -> viewModel.moveItem(from.index, to.index) }
+ onItemMove = { from, to -> viewModel.moveItem(from.index - 1, to.index - 1) }
)
val searchActions by viewModel.searchActions.collectAsState()
@@ -102,11 +114,14 @@ fun SearchActionsSettingsScreen() {
CustomTabsIntent.Builder()
.setDefaultColorSchemeParams(
CustomTabColorSchemeParams.Builder()
- .setToolbarColor(colorScheme.primaryContainer.toArgb())
- .setSecondaryToolbarColor(colorScheme.secondaryContainer.toArgb())
- .build()
+ .setToolbarColor(colorScheme.primaryContainer.toArgb())
+ .setSecondaryToolbarColor(colorScheme.secondaryContainer.toArgb())
+ .build()
+ )
+ .build().launchUrl(
+ context,
+ Uri.parse("https://kvaesitso.mm20.de/docs/user-guide/search/quickactions")
)
- .build().launchUrl(context, Uri.parse("https://kvaesitso.mm20.de/docs/user-guide/search/quickactions"))
}) {
Icon(
imageVector = Icons.Rounded.HelpOutline,
@@ -124,6 +139,26 @@ fun SearchActionsSettingsScreen() {
modifier = Modifier
.fillMaxSize()
) {
+ item(
+ key = "disabled-info"
+ ) {
+ Row(
+ modifier = Modifier
+ .padding(start = 28.dp, top = 16.dp, end = 16.dp, bottom = 16.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Icon(Icons.Outlined.Info, null,
+ modifier = Modifier.padding(end = 24.dp).size(16.dp),
+ tint = MaterialTheme.colorScheme.secondary
+ )
+ Text(
+ modifier = Modifier,
+ text = stringResource(R.string.hint_drag_and_drop_reorder),
+ style = MaterialTheme.typography.titleSmall,
+ color = MaterialTheme.colorScheme.secondary
+ )
+ }
+ }
items(
items = searchActions,
key = { it.key }
@@ -146,6 +181,51 @@ fun SearchActionsSettingsScreen() {
title = item.label,
onClick = {
viewModel.editAction(item)
+ },
+ controls = {
+ var showDropdown by remember { mutableStateOf(false) }
+ IconButton(
+ onClick = {
+ showDropdown = true
+ }
+ ) {
+ Icon(Icons.Rounded.MoreVert, stringResource(R.string.edit))
+ DropdownMenu(
+ expanded = showDropdown,
+ onDismissRequest = { showDropdown = false }
+ ) {
+ DropdownMenuItem(
+ leadingIcon = {
+ Icon(
+ Icons.Rounded.Edit,
+ contentDescription = null
+ )
+ },
+ text = {
+ Text(stringResource(R.string.edit))
+ },
+ onClick = {
+ viewModel.editAction(item)
+ showDropdown = false
+ }
+ )
+ DropdownMenuItem(
+ leadingIcon = {
+ Icon(
+ Icons.Rounded.Delete,
+ contentDescription = null
+ )
+ },
+ text = {
+ Text(stringResource(R.string.menu_delete))
+ },
+ onClick = {
+ viewModel.removeAction(item)
+ showDropdown = false
+ }
+ )
+ }
+ }
}
)
} else {
diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/SearchActionsSettingsScreenVM.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/SearchActionsSettingsScreenVM.kt
index 5619813f..4e65b87a 100644
--- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/SearchActionsSettingsScreenVM.kt
+++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/SearchActionsSettingsScreenVM.kt
@@ -54,8 +54,8 @@ class SearchActionsSettingsScreenVM : ViewModel(), KoinComponent {
fun moveItem(fromIndex: Int, toIndex: Int) {
val actions = searchActions.value?.toMutableList() ?: return
- if (fromIndex > actions.lastIndex) return
- if (toIndex > actions.lastIndex) return
+ if (fromIndex > actions.lastIndex || fromIndex < 0) return
+ if (toIndex > actions.lastIndex || toIndex < 0) return
val item = actions.removeAt(fromIndex)
actions.add(toIndex, item)
searchActionService.saveSearchActionBuilders(actions)
diff --git a/core/i18n/src/main/res/values/strings.xml b/core/i18n/src/main/res/values/strings.xml
index 274fee58..114be008 100644
--- a/core/i18n/src/main/res/values/strings.xml
+++ b/core/i18n/src/main/res/values/strings.xml
@@ -991,4 +991,5 @@
Private space is locked.
Unlock
Lock private space
+ Hold and drag items to rearrange them
\ No newline at end of file