Always show all widget page options

This commit is contained in:
MM20
2026-04-06 12:38:10 +02:00
parent 112c13e236
commit f688334433
2 changed files with 24 additions and 51 deletions

View File

@@ -20,6 +20,7 @@ import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
@@ -67,11 +68,12 @@ internal fun GesturePreference(
) {
var showSheet by remember { mutableStateOf(false) }
val value = if (value is GestureAction.Widgets && widgetOptions.none { it.id == value.target }) {
GestureAction.NoAction
} else {
value
}
val value =
if (value is GestureAction.Widgets && widgetOptions.none { it.id == value.target }) {
GestureAction.NoAction
} else {
value
}
val iconService: IconService = koinInject()
val iconSize = 24.dp.toPixels().toInt()
@@ -169,24 +171,21 @@ internal fun GesturePreference(
if (options.contains(GestureAction.Widgets::class)) {
for (widget in widgetOptions) {
GestureItem(
title = if (widget.isNewPage) {
stringResource(R.string.gesture_action_widgets_new)
} else {
getActionLabel(
LocalResources.current,
GestureAction.Widgets(widget.id),
shortcutOptions
)
},
icon = if (widget.isNewPage) R.drawable.widgets_add_24px else R.drawable.widgets_24px,
title = getActionLabel(
LocalResources.current,
GestureAction.Widgets(widget.id),
shortcutOptions
),
icon = R.drawable.widgets_24px,
selected = value is GestureAction.Widgets && value.target == widget.id,
onClick = {
onValueChanged(GestureAction.Widgets(widget.id), null)
onValueChanged(
GestureAction.Widgets(widget.id),
null
)
showSheet = false
},
summary = if (widget.isNewPage) {
null
} else if (widget.widgets.isEmpty()) {
summary = if (widget.widgets.isEmpty()) {
stringResource(R.string.gesture_action_widgets_empty)
} else {
ListFormatter.getInstance().format(
@@ -360,7 +359,7 @@ private fun GestureItem(
if (summary != null) {
Text(
text = summary,
color = textColor,
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodyMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis

View File

@@ -107,17 +107,6 @@ internal class GestureSettingsScreenVM : ViewModel(), KoinComponent {
val widgetOptions: Flow<List<WidgetPageOption>> =
combine(uiSettings.homeScreenWidgets, gestureSettings) { home, gestures ->
val options = mutableListOf<WidgetPageOption>()
val usedTargets = setOfNotNull(
(gestures.swipeUp as? GestureAction.Widgets)?.target,
(gestures.swipeRight as? GestureAction.Widgets)?.target,
(gestures.swipeLeft as? GestureAction.Widgets)?.target,
(gestures.swipeDown as? GestureAction.Widgets)?.target,
(gestures.doubleTap as? GestureAction.Widgets)?.target,
(gestures.longPress as? GestureAction.Widgets)?.target,
(gestures.homeButton as? GestureAction.Widgets)?.target,
)
// We want to provide at most one "new screen" option
var newScreenOptionAdded = false
for (target in WidgetScreenTarget.entries) {
// Never offer the default screen as an option when widgets on home is enabled
if (home && target == WidgetScreenTarget.Default) continue
@@ -125,27 +114,13 @@ internal class GestureSettingsScreenVM : ViewModel(), KoinComponent {
parent = target.id,
).first()
if (widgets.isNotEmpty() || usedTargets.contains(target)) {
options += WidgetPageOption(
widgets = widgets,
id = target,
isNewPage = false,
)
} else if (!newScreenOptionAdded) {
options += WidgetPageOption(
id = target,
widgets = emptyList(),
isNewPage = true,
)
newScreenOptionAdded = true
}
options += WidgetPageOption(
widgets = widgets,
id = target,
)
}
options.sortedWith { a, b ->
if (a.isNewPage) return@sortedWith 1
if (b.isNewPage) return@sortedWith -1
a.id.compareTo(b.id)
}
options
}
@@ -162,5 +137,4 @@ internal class GestureSettingsScreenVM : ViewModel(), KoinComponent {
internal data class WidgetPageOption(
val id: WidgetScreenTarget,
val widgets: List<Widget>,
val isNewPage: Boolean,
)