Add preference to hide grid labels

Close #159
This commit is contained in:
MM20 2022-09-03 15:08:53 +02:00
parent ef5474b470
commit b96c6c603d
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
5 changed files with 44 additions and 6 deletions

View File

@ -507,6 +507,8 @@
<string name="preference_category_grid">Grid</string> <string name="preference_category_grid">Grid</string>
<string name="preference_grid_icon_size">Icon size</string> <string name="preference_grid_icon_size">Icon size</string>
<string name="preference_grid_column_count">Number of columns</string> <string name="preference_grid_column_count">Number of columns</string>
<string name="preference_grid_labels">Show labels</string>
<string name="preference_grid_labels_summary">Show the app name below the icon</string>
<string name="preference_screen_debug">Debug</string> <string name="preference_screen_debug">Debug</string>
<string name="preference_screen_debug_summary">Troubleshooting tools</string> <string name="preference_screen_debug_summary">Troubleshooting tools</string>
<string name="preference_screen_widgets">Widgets</string> <string name="preference_screen_widgets">Widgets</string>

View File

@ -5,14 +5,11 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import de.mm20.launcher2.search.data.Searchable import de.mm20.launcher2.search.data.Searchable
@ -42,6 +39,8 @@ fun SearchColumn(
val viewModel: SearchVM = viewModel() val viewModel: SearchVM = viewModel()
val showLabels by viewModel.showLabels.observeAsState(true)
val hideFavs by viewModel.hideFavorites.observeAsState(true) val hideFavs by viewModel.hideFavorites.observeAsState(true)
val favorites by viewModel.favorites.observeAsState(emptyList()) val favorites by viewModel.favorites.observeAsState(emptyList())
val apps by viewModel.appResults.observeAsState(emptyList()) val apps by viewModel.appResults.observeAsState(emptyList())
@ -62,9 +61,19 @@ fun SearchColumn(
reverseLayout = reverse, reverseLayout = reverse,
) { ) {
if (!hideFavs) { if (!hideFavs) {
GridResults(favorites.toImmutableList(), columns, reverse) GridResults(
items = favorites.toImmutableList(),
columns = columns,
showLabels = showLabels,
reverse = reverse,
)
} }
GridResults(apps.toImmutableList(), columns, reverse) GridResults(
items = apps.toImmutableList(),
columns = columns,
showLabels = showLabels,
reverse = reverse,
)
ListResults(appShortcuts.toImmutableList(), reverse) ListResults(appShortcuts.toImmutableList(), reverse)
val uc = unitConverter val uc = unitConverter
if (uc != null) { if (uc != null) {
@ -103,6 +112,7 @@ fun LazyListScope.GridResults(
items: ImmutableList<Searchable>, items: ImmutableList<Searchable>,
columns: Int, columns: Int,
reverse: Boolean, reverse: Boolean,
showLabels: Boolean,
) { ) {
if (items.isEmpty()) return if (items.isEmpty()) return
val rows = ceil(items.size / columns.toFloat()).toInt() val rows = ceil(items.size / columns.toFloat()).toInt()
@ -110,6 +120,7 @@ fun LazyListScope.GridResults(
GridRow( GridRow(
items = items.subList(it * columns, (it * columns + columns).coerceAtMost(items.size)), items = items.subList(it * columns, (it * columns + columns).coerceAtMost(items.size)),
columns = columns, columns = columns,
showLabels = showLabels,
isFirst = if (reverse) it == rows - 1 else it == 0, isFirst = if (reverse) it == rows - 1 else it == 0,
isLast = if (reverse) it == 0 else it == rows - 1 isLast = if (reverse) it == 0 else it == rows - 1
) )
@ -121,6 +132,7 @@ fun GridRow(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
items: ImmutableList<Searchable>, items: ImmutableList<Searchable>,
columns: Int, columns: Int,
showLabels: Boolean,
isFirst: Boolean, isFirst: Boolean,
isLast: Boolean, isLast: Boolean,
) { ) {
@ -145,7 +157,7 @@ fun GridRow(
.weight(1f) .weight(1f)
.padding(4.dp, 8.dp), .padding(4.dp, 8.dp),
item = item, item = item,
showLabels = true showLabels = showLabels
) )
} }
for (i in 0 until columns - items.size) { for (i in 0 until columns - items.size) {

View File

@ -3,6 +3,7 @@ package de.mm20.launcher2.ui.launcher.search
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import de.mm20.launcher2.applications.AppRepository import de.mm20.launcher2.applications.AppRepository
import de.mm20.launcher2.appshortcuts.AppShortcutRepository import de.mm20.launcher2.appshortcuts.AppShortcutRepository
@ -47,6 +48,8 @@ class SearchVM : ViewModel(), KoinComponent {
val searchQuery = MutableLiveData("") val searchQuery = MutableLiveData("")
val isSearchEmpty = MutableLiveData(true) val isSearchEmpty = MutableLiveData(true)
val showLabels = dataStore.data.map { it.grid.showLabels }.asLiveData()
val favorites = MutableLiveData<List<Searchable>>(emptyList()) val favorites = MutableLiveData<List<Searchable>>(emptyList())
val appResults = MutableLiveData<List<Application>>(emptyList()) val appResults = MutableLiveData<List<Application>>(emptyList())

View File

@ -125,6 +125,15 @@ fun AppearanceSettingsScreen() {
viewModel.setIconSize(it) viewModel.setIconSize(it)
} }
) )
val showLabels by viewModel.showLabels.observeAsState()
SwitchPreference(
title = stringResource(R.string.preference_grid_labels),
summary = stringResource(R.string.preference_grid_labels_summary),
value = showLabels == true,
onValueChanged = {
viewModel.setShowLabels(it)
}
)
val columnCount by viewModel.columnCount.observeAsState(5) val columnCount by viewModel.columnCount.observeAsState(5)
SliderPreference( SliderPreference(
title = stringResource(R.string.preference_grid_column_count), title = stringResource(R.string.preference_grid_column_count),

View File

@ -78,6 +78,18 @@ class AppearanceSettingsScreenVM : ViewModel(), KoinComponent {
} }
} }
val showLabels = dataStore.data.map { it.grid.showLabels }.asLiveData()
fun setShowLabels(showLabels: Boolean) {
viewModelScope.launch {
dataStore.updateData {
it.toBuilder()
.setGrid(it.grid.toBuilder().setShowLabels(showLabels))
.build()
}
}
}
val dimWallpaper = dataStore.data.map { it.appearance.dimWallpaper }.asLiveData() val dimWallpaper = dataStore.data.map { it.appearance.dimWallpaper }.asLiveData()
fun setDimWallpaper(dimWallpaper: Boolean) { fun setDimWallpaper(dimWallpaper: Boolean) {
viewModelScope.launch { viewModelScope.launch {