Add setting to change the grid row count for "Your playlists"

This commit is contained in:
vfsfitvnm 2022-06-17 19:34:38 +02:00
parent 698f0c63fb
commit 945677b9d1
5 changed files with 44 additions and 12 deletions

View file

@ -225,14 +225,16 @@ inline fun DefaultDialog(
}
}
@Composable
inline fun <reified T : Enum<T>> EnumValueSelectorDialog(
inline fun <T> ValueSelectorDialog(
noinline onDismiss: () -> Unit,
title: String,
selectedValue: T,
values: List<T>,
crossinline onValueSelected: (T) -> Unit,
modifier: Modifier = Modifier,
crossinline valueText: (T) -> String = Enum<T>::name
crossinline valueText: (T) -> String = { it.toString() }
) {
val typography = LocalTypography.current
val colorPalette = LocalColorPalette.current
@ -258,7 +260,7 @@ inline fun <reified T : Enum<T>> EnumValueSelectorDialog(
modifier = Modifier
.verticalScroll(rememberScrollState())
) {
enumValues<T>().forEach { value ->
values.forEach { value ->
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(16.dp),
@ -331,4 +333,4 @@ inline fun <reified T : Enum<T>> EnumValueSelectorDialog(
)
}
}
}
}

View file

@ -221,10 +221,10 @@ fun HomeScreen() {
item {
LazyHorizontalGrid(
rows = GridCells.Fixed(2),
rows = GridCells.Fixed(preferences.yourPlaylistsGridRowCount),
contentPadding = PaddingValues(horizontal = 16.dp),
modifier = Modifier
.height(248.dp)
.height(124.dp * preferences.yourPlaylistsGridRowCount)
) {
item {
Column(

View file

@ -1,7 +1,7 @@
package it.vfsfitvnm.vimusic.ui.screens
import androidx.annotation.DrawableRes
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.*
import androidx.compose.foundation.*
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
@ -18,8 +18,8 @@ import androidx.compose.ui.unit.dp
import it.vfsfitvnm.route.*
import it.vfsfitvnm.vimusic.R
import it.vfsfitvnm.vimusic.ui.components.TopAppBar
import it.vfsfitvnm.vimusic.ui.components.themed.EnumValueSelectorDialog
import it.vfsfitvnm.vimusic.ui.components.themed.Switch
import it.vfsfitvnm.vimusic.ui.components.themed.ValueSelectorDialog
import it.vfsfitvnm.vimusic.ui.screens.settings.*
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
@ -230,24 +230,44 @@ fun SettingsScreen() {
}
@Composable
inline fun <reified T : Enum<T>> EnumValueSelectorEntry(
inline fun <reified T : Enum<T>> EnumValueSelectorSettingsEntry(
title: String,
selectedValue: T,
crossinline onValueSelected: (T) -> Unit,
modifier: Modifier = Modifier,
crossinline valueText: (T) -> String = Enum<T>::name
) {
ValueSelectorSettingsEntry(
title = title,
selectedValue = selectedValue,
values = enumValues<T>().toList(),
onValueSelected =onValueSelected,
modifier = modifier,
valueText = valueText
)
}
@Composable
inline fun <T> ValueSelectorSettingsEntry(
title: String,
selectedValue: T,
values: List<T>,
crossinline onValueSelected: (T) -> Unit,
modifier: Modifier = Modifier,
crossinline valueText: (T) -> String = { it.toString() }
) {
var isShowingDialog by remember {
mutableStateOf(false)
}
if (isShowingDialog) {
EnumValueSelectorDialog(
ValueSelectorDialog(
onDismiss = {
isShowingDialog = false
},
title = title,
selectedValue = selectedValue,
values = values,
onValueSelected = onValueSelected,
valueText = valueText
)

View file

@ -77,7 +77,7 @@ fun AppearanceSettingsScreen() {
)
}
EnumValueSelectorEntry(
EnumValueSelectorSettingsEntry(
title = "Theme mode",
selectedValue = preferences.colorPaletteMode,
onValueSelected = {
@ -85,13 +85,22 @@ fun AppearanceSettingsScreen() {
}
)
EnumValueSelectorEntry(
EnumValueSelectorSettingsEntry(
title = "Thumbnail roundness",
selectedValue = preferences.thumbnailRoundness,
onValueSelected = {
preferences.thumbnailRoundness = it
}
)
ValueSelectorSettingsEntry(
title = "\"Your playlists\" grid row count",
selectedValue = preferences.yourPlaylistsGridRowCount,
values = listOf(1, 2, 3),
onValueSelected = {
preferences.yourPlaylistsGridRowCount = it
}
)
}
}
}

View file

@ -27,6 +27,7 @@ class Preferences(holder: SharedPreferences) : SharedPreferences by holder {
var displayLikeButtonInNotification by preference("displayLikeButtonInNotification", false)
var persistentQueue by preference("persistentQueue", false)
var skipSilence by preference("skipSilence", false)
var yourPlaylistsGridRowCount by preference("yourPlaylistsGridRowCount", 2)
}
val Context.preferences: Preferences