Skip to content

Commit

Permalink
feat(Library): choose default chip in Content, closes z-huang#52
Browse files Browse the repository at this point in the history
  • Loading branch information
Malopieds committed Jun 22, 2024
1 parent 2735f43 commit 58ec85d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ val PauseListenHistoryKey = booleanPreferencesKey("pauseListenHistory")
val PauseSearchHistoryKey = booleanPreferencesKey("pauseSearchHistory")
val EnableKugouKey = booleanPreferencesKey("enableKugou")

val ChipSortTypeKey = stringPreferencesKey("chipSortType")
val SongSortTypeKey = stringPreferencesKey("songSortType")
val SongSortDescendingKey = booleanPreferencesKey("songSortDescending")
val PlaylistSongSortTypeKey = stringPreferencesKey("playlistSongSortType")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import com.zionhuang.music.ui.component.ChipsRow
import com.zionhuang.music.R
import com.zionhuang.music.constants.LibraryFilter
import com.zionhuang.music.viewmodels.LibraryViewModel
import com.zionhuang.music.constants.ChipSortTypeKey
import com.zionhuang.music.utils.rememberEnumPreference

@Composable
fun LibraryScreen(
navController: NavController,
viewModel: LibraryViewModel = hiltViewModel(),
){
val filter by remember { mutableStateOf(viewModel.filter) }
var filterType by rememberEnumPreference(ChipSortTypeKey, LibraryFilter.LIBRARY)

val filterContent = @Composable {
Row {
Expand All @@ -32,9 +30,9 @@ fun LibraryScreen(
LibraryFilter.ALBUMS to stringResource(R.string.filter_albums),
LibraryFilter.ARTISTS to stringResource(R.string.filter_artists)
),
currentValue = filter.value,
currentValue = filterType,
onValueUpdate = {
filter.value = if (filter.value == it){
filterType = if (filterType == it) {
LibraryFilter.LIBRARY
} else {
it
Expand All @@ -48,7 +46,7 @@ fun LibraryScreen(
Box(
modifier = Modifier.fillMaxSize()
) {
when (filter.value) {
when (filterType) {
LibraryFilter.LIBRARY -> LibraryMixScreen(navController, filterContent)
LibraryFilter.PLAYLISTS -> LibraryPlaylistsScreen(navController, filterContent)
LibraryFilter.SONGS -> LibrarySongsScreen(navController, filterContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import com.zionhuang.music.R
import com.zionhuang.music.constants.AccountChannelHandleKey
import com.zionhuang.music.constants.AccountEmailKey
import com.zionhuang.music.constants.AccountNameKey
import com.zionhuang.music.constants.ChipSortTypeKey
import com.zionhuang.music.constants.ContentCountryKey
import com.zionhuang.music.constants.ContentLanguageKey
import com.zionhuang.music.constants.CountryCodeToName
import com.zionhuang.music.constants.InnerTubeCookieKey
import com.zionhuang.music.constants.LanguageCodeToName
import com.zionhuang.music.constants.LibraryFilter
import com.zionhuang.music.constants.ProxyEnabledKey
import com.zionhuang.music.constants.ProxyTypeKey
import com.zionhuang.music.constants.ProxyUrlKey
Expand Down Expand Up @@ -62,6 +64,7 @@ fun ContentSettings(
val (proxyType, onProxyTypeChange) = rememberEnumPreference(key = ProxyTypeKey, defaultValue = Proxy.Type.HTTP)
val (proxyUrl, onProxyUrlChange) = rememberPreference(key = ProxyUrlKey, defaultValue = "host:port")
val (lengthTop, onLengthTopChange) = rememberPreference(key = TopSize, defaultValue = "50")
val (defaultChip, onDefaultChipChange) = rememberEnumPreference(key = ChipSortTypeKey, defaultValue = LibraryFilter.LIBRARY)


Column(
Expand Down Expand Up @@ -140,6 +143,14 @@ fun ContentSettings(
},
onValueChange = onLengthTopChange
)

ListPreference(
title = { Text("Change default chip") },
selectedValue = defaultChip,
values = listOf(LibraryFilter.LIBRARY, LibraryFilter.PLAYLISTS, LibraryFilter.SONGS, LibraryFilter.ALBUMS, LibraryFilter.ARTISTS),
valueText = { it.name },
onValueSelected = onDefaultChipChange
)
}

TopAppBar(
Expand Down

0 comments on commit 58ec85d

Please sign in to comment.