Add preference for compact tag buttons

Close #645
This commit is contained in:
MM20 2024-11-22 21:49:45 +01:00
parent cd803974de
commit 930897f1d6
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
14 changed files with 102 additions and 18 deletions

View File

@ -49,6 +49,7 @@ fun FavoritesTagSelector(
reverse: Boolean, reverse: Boolean,
onSelectTag: (String?) -> Unit, onSelectTag: (String?) -> Unit,
scrollState: ScrollState, scrollState: ScrollState,
compact: Boolean,
expanded: Boolean, expanded: Boolean,
onExpand: (Boolean) -> Unit, onExpand: (Boolean) -> Unit,
) { ) {
@ -86,14 +87,26 @@ fun FavoritesTagSelector(
), ),
selected = selectedTag == null, selected = selectedTag == null,
onClick = { onSelectTag(null) }, onClick = { onSelectTag(null) },
leadingIcon = { leadingIcon = if (compact) null else {
Icon( {
imageVector = Icons.Rounded.Star, Icon(
contentDescription = null, imageVector = Icons.Rounded.Star,
modifier = Modifier.size(FilterChipDefaults.IconSize), contentDescription = null,
) modifier = Modifier.size(FilterChipDefaults.IconSize),
)
}
}, },
label = { Text(stringResource(R.string.favorites)) } label = {
if (compact) {
Icon(
imageVector = Icons.Rounded.Star,
contentDescription = null,
modifier = Modifier.size(FilterChipDefaults.IconSize),
)
} else {
Text(stringResource(R.string.favorites))
}
}
) )
for (tag in tags) { for (tag in tags) {
TagChip( TagChip(
@ -112,6 +125,7 @@ fun FavoritesTagSelector(
onSelectTag(tag.tag) onSelectTag(tag.tag)
} }
}, },
compact = compact,
onLongClick = { onLongClick = {
sheetManager.showEditTagSheet(tag.tag) sheetManager.showEditTagSheet(tag.tag)
} }
@ -164,24 +178,43 @@ fun FavoritesTagSelector(
FilterChip( FilterChip(
modifier = Modifier modifier = Modifier
.padding(end = 8.dp) .padding(end = 8.dp)
.sharedBounds(rememberSharedContentState("favorites"), this@AnimatedContent), .sharedBounds(
rememberSharedContentState("favorites"),
this@AnimatedContent
),
selected = selectedTag == null, selected = selectedTag == null,
onClick = { onSelectTag(null) }, onClick = { onSelectTag(null) },
leadingIcon = { leadingIcon = if (compact) null else {
Icon( {
imageVector = Icons.Rounded.Star, Icon(
contentDescription = null, imageVector = Icons.Rounded.Star,
modifier = Modifier.size(FilterChipDefaults.IconSize), contentDescription = null,
) modifier = Modifier.size(FilterChipDefaults.IconSize),
)
}
}, },
label = { Text(stringResource(R.string.favorites)) } label = {
if (compact) {
Icon(
imageVector = Icons.Rounded.Star,
contentDescription = null,
modifier = Modifier.size(FilterChipDefaults.IconSize),
)
} else {
Text(stringResource(R.string.favorites))
}
}
) )
for (tag in tags) { for (tag in tags) {
TagChip( TagChip(
modifier = Modifier modifier = Modifier
.padding(end = 8.dp) .padding(end = 8.dp)
.sharedBounds(rememberSharedContentState("tag-${tag.tag}"), this@AnimatedContent), .sharedBounds(
rememberSharedContentState("tag-${tag.tag}"),
this@AnimatedContent
),
tag = tag, tag = tag,
compact = compact,
selected = selectedTag == tag.tag, selected = selectedTag == tag.tag,
onClick = { onClick = {
if (selectedTag == tag.tag) { if (selectedTag == tag.tag) {
@ -207,7 +240,10 @@ fun FavoritesTagSelector(
IconButton( IconButton(
modifier = Modifier modifier = Modifier
.rotate(rot) .rotate(rot)
.sharedBounds(rememberSharedContentState("expand"), this@AnimatedContent), .sharedBounds(
rememberSharedContentState("expand"),
this@AnimatedContent
),
onClick = { onExpand(false) } onClick = { onExpand(false) }
) { ) {
Icon(Icons.Rounded.ExpandLess, null) Icon(Icons.Rounded.ExpandLess, null)
@ -216,7 +252,10 @@ fun FavoritesTagSelector(
if (editButton) { if (editButton) {
SmallFloatingActionButton( SmallFloatingActionButton(
modifier = Modifier modifier = Modifier
.sharedBounds(rememberSharedContentState("edit"), this@AnimatedContent), .sharedBounds(
rememberSharedContentState("edit"),
this@AnimatedContent
),
elevation = FloatingActionButtonDefaults.bottomAppBarFabElevation(), elevation = FloatingActionButtonDefaults.bottomAppBarFabElevation(),
onClick = { sheetManager.showEditFavoritesSheet() } onClick = { sheetManager.showEditFavoritesSheet() }
) { ) {

View File

@ -27,6 +27,7 @@ abstract class FavoritesVM : ViewModel(), KoinComponent {
val showEditButton = settings.showEditButton.stateIn(viewModelScope, SharingStarted.Lazily, false) val showEditButton = settings.showEditButton.stateIn(viewModelScope, SharingStarted.Lazily, false)
abstract val tagsExpanded: Flow<Boolean> abstract val tagsExpanded: Flow<Boolean>
abstract val compactTags: Flow<Boolean>
val pinnedTags = favoritesService.getFavorites( val pinnedTags = favoritesService.getFavorites(
includeTypes = listOf("tag"), includeTypes = listOf("tag"),

View File

@ -105,6 +105,7 @@ fun SearchColumn(
val pinnedTags by favoritesVM.pinnedTags.collectAsState(emptyList()) val pinnedTags by favoritesVM.pinnedTags.collectAsState(emptyList())
val selectedTag by favoritesVM.selectedTag.collectAsState(null) val selectedTag by favoritesVM.selectedTag.collectAsState(null)
val compactTags by favoritesVM.compactTags.collectAsState(false)
val favoritesEditButton by favoritesVM.showEditButton.collectAsState(false) val favoritesEditButton by favoritesVM.showEditButton.collectAsState(false)
val favoritesTagsExpanded by favoritesVM.tagsExpanded.collectAsState(false) val favoritesTagsExpanded by favoritesVM.tagsExpanded.collectAsState(false)
@ -168,6 +169,7 @@ fun SearchColumn(
onExpandTags = { onExpandTags = {
favoritesVM.setTagsExpanded(it) favoritesVM.setTagsExpanded(it)
}, },
compactTags = compactTags,
editButton = favoritesEditButton editButton = favoritesEditButton
) )
} }

View File

@ -28,6 +28,7 @@ fun LazyListScope.SearchFavorites(
favorites: List<SavableSearchable>, favorites: List<SavableSearchable>,
pinnedTags: List<Tag>, pinnedTags: List<Tag>,
selectedTag: String?, selectedTag: String?,
compactTags: Boolean,
tagsExpanded: Boolean, tagsExpanded: Boolean,
onExpandTags: (Boolean) -> Unit, onExpandTags: (Boolean) -> Unit,
onSelectTag: (String?) -> Unit, onSelectTag: (String?) -> Unit,
@ -72,6 +73,7 @@ fun LazyListScope.SearchFavorites(
onSelectTag = onSelectTag, onSelectTag = onSelectTag,
scrollState = rememberScrollState(), scrollState = rememberScrollState(),
expanded = tagsExpanded, expanded = tagsExpanded,
compact = compactTags,
onExpand = onExpandTags, onExpand = onExpandTags,
) )
} }

View File

@ -19,4 +19,6 @@ class SearchFavoritesVM : FavoritesVM() {
uiState.setFavoritesTagsExpanded(expanded) uiState.setFavoritesTagsExpanded(expanded)
} }
override val compactTags: Flow<Boolean> = settings.compactTags
} }

View File

@ -207,6 +207,14 @@ fun ColumnScope.ConfigureFavoritesWidget(
onWidgetUpdated(widget.copy(config = widget.config.copy(editButton = it))) onWidgetUpdated(widget.copy(config = widget.config.copy(editButton = it)))
} }
) )
SwitchPreference(
title = stringResource(R.string.preference_compact_tags),
iconPadding = false,
value = widget.config.compactTags,
onValueChanged = {
onWidgetUpdated(widget.copy(config = widget.config.copy(compactTags = it)))
}
)
} }
} }
TextButton( TextButton(

View File

@ -32,6 +32,7 @@ fun FavoritesWidget(widget: FavoritesWidget) {
val favorites by remember { viewModel.favorites }.collectAsState(emptyList()) val favorites by remember { viewModel.favorites }.collectAsState(emptyList())
val pinnedTags by viewModel.pinnedTags.collectAsState(emptyList()) val pinnedTags by viewModel.pinnedTags.collectAsState(emptyList())
val selectedTag by viewModel.selectedTag.collectAsState(null) val selectedTag by viewModel.selectedTag.collectAsState(null)
val compactTags by viewModel.compactTags.collectAsState(false)
val favoritesEditButton = widget.config.editButton val favoritesEditButton = widget.config.editButton
val tagsExpanded by viewModel.tagsExpanded.collectAsState(false) val tagsExpanded by viewModel.tagsExpanded.collectAsState(false)
@ -61,6 +62,7 @@ fun FavoritesWidget(widget: FavoritesWidget) {
onSelectTag = { viewModel.selectTag(it) }, onSelectTag = { viewModel.selectTag(it) },
scrollState = rememberScrollState(), scrollState = rememberScrollState(),
expanded = tagsExpanded, expanded = tagsExpanded,
compact = compactTags,
onExpand = { viewModel.setTagsExpanded(it) } onExpand = { viewModel.setTagsExpanded(it) }
) )
} }

View File

@ -6,6 +6,7 @@ import de.mm20.launcher2.preferences.ui.UiSettings
import de.mm20.launcher2.services.widgets.WidgetsService import de.mm20.launcher2.services.widgets.WidgetsService
import de.mm20.launcher2.ui.common.FavoritesVM import de.mm20.launcher2.ui.common.FavoritesVM
import de.mm20.launcher2.widgets.FavoritesWidget import de.mm20.launcher2.widgets.FavoritesWidget
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
@ -20,6 +21,7 @@ class FavoritesWidgetVM : FavoritesVM() {
private val widget = MutableStateFlow<FavoritesWidget?>(null) private val widget = MutableStateFlow<FavoritesWidget?>(null)
override val tagsExpanded = widget.map { it?.config?.tagsMultiline == true } override val tagsExpanded = widget.map { it?.config?.tagsMultiline == true }
override val compactTags: Flow<Boolean> = widget.map { it?.config?.compactTags == true }
private val isTopWidget = widgetsService.isFavoritesWidgetFirst() private val isTopWidget = widgetsService.isFavoritesWidgetFirst()
private val clockWidgetFavSlots = private val clockWidgetFavSlots =

View File

@ -83,6 +83,7 @@ fun FavoritesSettingsScreen() {
} }
item { item {
val editButton by viewModel.editButton.collectAsState() val editButton by viewModel.editButton.collectAsState()
val compactTags by viewModel.compactTags.collectAsState()
PreferenceCategory { PreferenceCategory {
SwitchPreference( SwitchPreference(
title = stringResource(R.string.preference_edit_button), title = stringResource(R.string.preference_edit_button),
@ -93,6 +94,14 @@ fun FavoritesSettingsScreen() {
}, },
icon = Icons.Rounded.Edit icon = Icons.Rounded.Edit
) )
SwitchPreference(
title = stringResource(R.string.preference_compact_tags),
summary = stringResource(R.string.preference_compact_tags_summary),
value = compactTags == true,
onValueChanged = {
viewModel.setCompactTags(it)
},
)
} }
} }
} }

View File

@ -39,4 +39,10 @@ class FavoritesSettingsScreenVM: ViewModel(), KoinComponent {
fun setSearchResultWeightFactor(searchResultWeightFactor: WeightFactor) { fun setSearchResultWeightFactor(searchResultWeightFactor: WeightFactor) {
rankingSettings.setWeightFactor(searchResultWeightFactor) rankingSettings.setWeightFactor(searchResultWeightFactor)
} }
val compactTags = favoritesSettings.compactTags
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
fun setCompactTags(compactTags: Boolean) {
favoritesSettings.setCompactTags(compactTags)
}
} }

View File

@ -652,6 +652,8 @@
<string name="preference_favorites_frequently_used_summary">Show frequently used items in favorites</string> <string name="preference_favorites_frequently_used_summary">Show frequently used items in favorites</string>
<string name="preference_edit_button">Edit button</string> <string name="preference_edit_button">Edit button</string>
<string name="preference_favorites_edit_button_summary">Show a button to rearrange the favorites</string> <string name="preference_favorites_edit_button_summary">Show a button to rearrange the favorites</string>
<string name="preference_compact_tags">Compact tags</string>
<string name="preference_compact_tags_summary">Hide tag labels or icons to reduce the space occupied by tags</string>
<string name="preference_widgets_edit_button_summary">Show a button to add, remove and rearrange widgets</string> <string name="preference_widgets_edit_button_summary">Show a button to add, remove and rearrange widgets</string>
<string name="preference_screen_homescreen">Home screen</string> <string name="preference_screen_homescreen">Home screen</string>
<string name="preference_screen_homescreen_summary">Clock, search bar, wallpaper, system bars</string> <string name="preference_screen_homescreen_summary">Clock, search bar, wallpaper, system bars</string>

View File

@ -48,6 +48,7 @@ data class LauncherSettingsData internal constructor(
val favoritesFrequentlyUsed: Boolean = true, val favoritesFrequentlyUsed: Boolean = true,
val favoritesFrequentlyUsedRows: Int = 1, val favoritesFrequentlyUsedRows: Int = 1,
val favoritesEditButton: Boolean = true, val favoritesEditButton: Boolean = true,
val favoritesCompactTags: Boolean = false,
val fileSearchProviders: Set<String> = setOf("local"), val fileSearchProviders: Set<String> = setOf("local"),

View File

@ -41,4 +41,11 @@ class FavoritesSettings internal constructor(
fun setFrequentlyUsedRows(frequentlyUsedRows: Int) { fun setFrequentlyUsedRows(frequentlyUsedRows: Int) {
dataStore.update { it.copy(favoritesFrequentlyUsedRows = frequentlyUsedRows) } dataStore.update { it.copy(favoritesFrequentlyUsedRows = frequentlyUsedRows) }
} }
val compactTags: Flow<Boolean>
get() = dataStore.data.map { it.favoritesCompactTags }.distinctUntilChanged()
fun setCompactTags(compactTags: Boolean) {
dataStore.update { it.copy(favoritesCompactTags = compactTags) }
}
} }

View File

@ -10,6 +10,7 @@ import java.util.UUID
data class FavoritesWidgetConfig( data class FavoritesWidgetConfig(
val editButton: Boolean = true, val editButton: Boolean = true,
val tagsMultiline: Boolean = false, val tagsMultiline: Boolean = false,
val compactTags: Boolean = false,
) )
data class FavoritesWidget( data class FavoritesWidget(