Replace Preferences::yourPlaylistsGridRowCount with local variable

This commit is contained in:
vfsfitvnm 2022-06-22 22:19:15 +02:00
parent b44e28cc51
commit cfe12479be
5 changed files with 67 additions and 19 deletions

View file

@ -3,6 +3,7 @@ package it.vfsfitvnm.vimusic.ui.screens
import android.net.Uri
import android.os.Bundle
import androidx.compose.animation.*
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
@ -49,6 +50,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ExperimentalFoundationApi
@ExperimentalAnimationApi
@Composable
fun HomeScreen() {
@ -151,6 +153,10 @@ fun HomeScreen() {
}
}
var isGridExpanded by remember {
mutableStateOf(false)
}
var isCreatingANewPlaylist by rememberSaveable {
mutableStateOf(false)
}
@ -208,20 +214,41 @@ fun HomeScreen() {
}
item {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.zIndex(1f)
.padding(horizontal = 8.dp)
) {
BasicText(
text = "Your playlists",
style = typography.m.semiBold,
modifier = Modifier
.padding(horizontal = 16.dp)
.weight(1f)
.padding(horizontal = 8.dp)
)
Image(
painter = painterResource(if (isGridExpanded) R.drawable.grid else R.drawable.grid_single),
contentDescription = null,
colorFilter = ColorFilter.tint(colorPalette.textSecondary),
modifier = Modifier
.clickable {
isGridExpanded = !isGridExpanded
}
.padding(all = 10.dp)
.size(16.dp)
)
}
}
item {
LazyHorizontalGrid(
rows = GridCells.Fixed(preferences.yourPlaylistsGridRowCount),
rows = GridCells.Fixed(if (isGridExpanded) 3 else 1),
contentPadding = PaddingValues(horizontal = 16.dp),
modifier = Modifier
.height(124.dp * preferences.yourPlaylistsGridRowCount)
.animateContentSize()
.height(124.dp * (if (isGridExpanded) 3 else 1))
) {
item {
Column(
@ -260,6 +287,7 @@ fun HomeScreen() {
PlaylistPreviewItem(
playlistPreview = playlistPreview,
modifier = Modifier
.animateItemPlacement()
.padding(all = 8.dp)
.clickable(
indication = rememberRipple(bounded = true),
@ -274,14 +302,14 @@ fun HomeScreen() {
item {
Row(
verticalAlignment = Alignment.Bottom,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.zIndex(1f)
.padding(horizontal = 8.dp)
.padding(top = 32.dp)
) {
Row(
verticalAlignment = Alignment.CenterVertically,
verticalAlignment = Alignment.Bottom,
modifier = Modifier
.weight(1f)
.padding(horizontal = 8.dp)

View file

@ -92,15 +92,6 @@ fun AppearanceSettingsScreen() {
preferences.thumbnailRoundness = it
}
)
ValueSelectorSettingsEntry(
title = "\"Your playlists\" grid row count",
selectedValue = preferences.yourPlaylistsGridRowCount,
values = listOf(1, 2, 3),
onValueSelected = {
preferences.yourPlaylistsGridRowCount = it
}
)
}
}
}

View file

@ -26,7 +26,6 @@ class Preferences(holder: SharedPreferences) : SharedPreferences by holder {
var exoPlayerDiskCacheMaxSizeBytes by preference("exoPlayerDiskCacheMaxSizeBytes", 512L * 1024 * 1024)
var skipSilence by preference("skipSilence", false)
var volumeNormalization by preference("volumeNormalization", true)
var yourPlaylistsGridRowCount by preference("yourPlaylistsGridRowCount", 2)
}
val Context.preferences: Preferences

View file

@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:fillColor="#FF000000"
android:pathData="M204,240H68a36,36 0,0 1,-36 -36V68A36,36 0,0 1,68 32H204a36,36 0,0 1,36 36V204A36,36 0,0 1,204 240Z"/>
<path
android:fillColor="#FF000000"
android:pathData="M444,240H308a36,36 0,0 1,-36 -36V68a36,36 0,0 1,36 -36H444a36,36 0,0 1,36 36V204A36,36 0,0 1,444 240Z"/>
<path
android:fillColor="#FF000000"
android:pathData="M204,480H68a36,36 0,0 1,-36 -36V308a36,36 0,0 1,36 -36H204a36,36 0,0 1,36 36V444A36,36 0,0 1,204 480Z"/>
<path
android:fillColor="#FF000000"
android:pathData="M444,480H308a36,36 0,0 1,-36 -36V308a36,36 0,0 1,36 -36H444a36,36 0,0 1,36 36V444A36,36 0,0 1,444 480Z"/>
</vector>

View file

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:fillColor="#FF000000"
android:pathData="M204,360H68A36,36 0,0 1,32 324V188a36,36 0,0 1,36 -36h136a36,36 0,0 1,36 36v136a36,36 0,0 1,-36 36z"/>
<path
android:fillColor="#FF000000"
android:pathData="M444,360H308A36,36 0,0 1,272 324V188a36,36 0,0 1,36 -36h136a36,36 0,0 1,36 36v136a36,36 0,0 1,-36 36z"/>
</vector>