Add hints for dragn and drop arrangable preferences

This commit is contained in:
MM20 2024-08-11 22:34:45 +02:00
parent 8de1732e1b
commit f008d9366c
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
4 changed files with 114 additions and 8 deletions

View File

@ -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)

View File

@ -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()
@ -106,7 +118,10 @@ fun SearchActionsSettingsScreen() {
.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 {

View File

@ -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)

View File

@ -991,4 +991,5 @@
<string name="profile_private_profile_state_locked">Private space is locked.</string>
<string name="profile_private_profile_action_unlock">Unlock</string>
<string name="profile_private_profile_action_lock">Lock private space</string>
<string name="hint_drag_and_drop_reorder">Hold and drag items to rearrange them</string>
</resources>