Start UI redesign (#172)
This commit is contained in:
@@ -21,7 +21,6 @@ const val songSortOrderKey = "songSortOrder"
|
||||
const val songSortByKey = "songSortBy"
|
||||
const val playlistSortOrderKey = "playlistSortOrder"
|
||||
const val playlistSortByKey = "playlistSortBy"
|
||||
const val playlistGridExpandedKey = "playlistGridExpanded"
|
||||
const val searchFilterKey = "searchFilter"
|
||||
const val repeatModeKey = "repeatMode"
|
||||
const val skipSilenceKey = "skipSilence"
|
||||
@@ -29,6 +28,7 @@ const val volumeNormalizationKey = "volumeNormalization"
|
||||
const val persistentQueueKey = "persistentQueue"
|
||||
const val isShowingSynchronizedLyricsKey = "isShowingSynchronizedLyrics"
|
||||
const val isShowingThumbnailInLockscreenKey = "isShowingThumbnailInLockscreen"
|
||||
const val homeScreenTabIndexKey = "homeScreenTabIndex"
|
||||
|
||||
inline fun <reified T : Enum<T>> SharedPreferences.getEnum(
|
||||
key: String,
|
||||
@@ -61,6 +61,16 @@ fun rememberPreference(key: String, defaultValue: Boolean): MutableState<Boolean
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberPreference(key: String, defaultValue: Int): MutableState<Int> {
|
||||
val context = LocalContext.current
|
||||
return remember {
|
||||
mutableStatePreferenceOf(context.preferences.getInt(key, defaultValue)) {
|
||||
context.preferences.edit { putInt(key, it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberPreference(key: String, defaultValue: String): MutableState<String> {
|
||||
val context = LocalContext.current
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package it.vfsfitvnm.vimusic.utils
|
||||
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.grid.LazyGridState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.saveable.listSaver
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
|
||||
@Composable
|
||||
fun rememberLazyListStates(count: Int): List<LazyListState> {
|
||||
return rememberSaveable(
|
||||
saver = listSaver(
|
||||
save = { states: List<LazyListState> ->
|
||||
List(states.size * 2) {
|
||||
when (it % 2) {
|
||||
0 -> states[it / 2].firstVisibleItemIndex
|
||||
1 -> states[it / 2].firstVisibleItemScrollOffset
|
||||
else -> error("unreachable")
|
||||
}
|
||||
}
|
||||
},
|
||||
restore = { states ->
|
||||
List(states.size / 2) {
|
||||
LazyListState(
|
||||
firstVisibleItemIndex = states[it * 2],
|
||||
firstVisibleItemScrollOffset = states[it * 2 + 1]
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
) {
|
||||
List(count) { LazyListState(0, 0) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberLazyGridStates(count: Int): List<LazyGridState> {
|
||||
return rememberSaveable(
|
||||
saver = listSaver(
|
||||
save = { states: List<LazyGridState> ->
|
||||
List(states.size * 2) {
|
||||
when (it % 2) {
|
||||
0 -> states[it / 2].firstVisibleItemIndex
|
||||
1 -> states[it / 2].firstVisibleItemScrollOffset
|
||||
else -> error("unreachable")
|
||||
}
|
||||
}
|
||||
},
|
||||
restore = { states ->
|
||||
List(states.size / 2) {
|
||||
LazyGridState(
|
||||
firstVisibleItemIndex = states[it * 2],
|
||||
firstVisibleItemScrollOffset = states[it * 2 + 1]
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
) {
|
||||
List(count) { LazyGridState(0, 0) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user