Refactor preferences to avoid a global state when it's not necessary
This commit is contained in:
@@ -28,16 +28,17 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import coil.compose.AsyncImage
|
||||
import it.vfsfitvnm.route.RouteHandler
|
||||
import it.vfsfitvnm.vimusic.*
|
||||
import it.vfsfitvnm.vimusic.Database
|
||||
import it.vfsfitvnm.vimusic.LocalPlayerServiceBinder
|
||||
import it.vfsfitvnm.vimusic.R
|
||||
import it.vfsfitvnm.vimusic.enums.ThumbnailRoundness
|
||||
import it.vfsfitvnm.vimusic.models.*
|
||||
import it.vfsfitvnm.vimusic.query
|
||||
import it.vfsfitvnm.vimusic.ui.components.LocalMenuState
|
||||
import it.vfsfitvnm.vimusic.ui.components.TopAppBar
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.*
|
||||
import it.vfsfitvnm.vimusic.ui.styling.Dimensions
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.ui.styling.px
|
||||
import it.vfsfitvnm.vimusic.ui.views.SongItem
|
||||
import it.vfsfitvnm.vimusic.utils.*
|
||||
@@ -90,8 +91,7 @@ fun AlbumScreen(
|
||||
val context = LocalContext.current
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
val menuState = LocalMenuState.current
|
||||
|
||||
|
||||
@@ -356,6 +356,8 @@ private fun LoadingOrError(
|
||||
errorMessage: String? = null,
|
||||
onRetry: (() -> Unit)? = null
|
||||
) {
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
|
||||
LoadingOrError(
|
||||
errorMessage = errorMessage,
|
||||
onRetry = onRetry
|
||||
@@ -369,7 +371,7 @@ private fun LoadingOrError(
|
||||
) {
|
||||
Spacer(
|
||||
modifier = Modifier
|
||||
.background(color = LocalColorPalette.current.darkGray, shape = ThumbnailRoundness.shape)
|
||||
.background(color = colorPalette.darkGray, shape = ThumbnailRoundness.shape)
|
||||
.size(Dimensions.thumbnails.album)
|
||||
)
|
||||
|
||||
|
||||
@@ -36,10 +36,7 @@ import it.vfsfitvnm.vimusic.ui.components.themed.InHistoryMediaItemMenu
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.LoadingOrError
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.TextCard
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.TextPlaceholder
|
||||
import it.vfsfitvnm.vimusic.ui.styling.Dimensions
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.ui.styling.px
|
||||
import it.vfsfitvnm.vimusic.ui.styling.*
|
||||
import it.vfsfitvnm.vimusic.ui.views.SongItem
|
||||
import it.vfsfitvnm.vimusic.utils.*
|
||||
import it.vfsfitvnm.youtubemusic.YouTube
|
||||
@@ -77,8 +74,7 @@ fun ArtistScreen(
|
||||
host {
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
val artistResult by remember(browseId) {
|
||||
Database.artist(browseId).map { artist ->
|
||||
@@ -294,7 +290,7 @@ private fun LoadingOrError(
|
||||
errorMessage: String? = null,
|
||||
onRetry: (() -> Unit)? = null
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
|
||||
LoadingOrError(
|
||||
errorMessage = errorMessage,
|
||||
|
||||
@@ -29,10 +29,7 @@ import it.vfsfitvnm.vimusic.models.DetailedSong
|
||||
import it.vfsfitvnm.vimusic.ui.components.LocalMenuState
|
||||
import it.vfsfitvnm.vimusic.ui.components.TopAppBar
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.*
|
||||
import it.vfsfitvnm.vimusic.ui.styling.Dimensions
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.ui.styling.px
|
||||
import it.vfsfitvnm.vimusic.ui.styling.*
|
||||
import it.vfsfitvnm.vimusic.ui.views.SongItem
|
||||
import it.vfsfitvnm.vimusic.utils.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -66,8 +63,7 @@ fun BuiltInPlaylistScreen(
|
||||
val menuState = LocalMenuState.current
|
||||
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
val thumbnailSize = Dimensions.thumbnails.song.px
|
||||
|
||||
|
||||
@@ -50,10 +50,7 @@ import it.vfsfitvnm.vimusic.ui.components.TopAppBar
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.DropdownMenu
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.InHistoryMediaItemMenu
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.TextFieldDialog
|
||||
import it.vfsfitvnm.vimusic.ui.styling.Dimensions
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.ui.styling.px
|
||||
import it.vfsfitvnm.vimusic.ui.styling.*
|
||||
import it.vfsfitvnm.vimusic.ui.views.PlaylistPreviewItem
|
||||
import it.vfsfitvnm.vimusic.ui.views.SongItem
|
||||
import it.vfsfitvnm.vimusic.utils.*
|
||||
@@ -64,8 +61,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
@ExperimentalAnimationApi
|
||||
@Composable
|
||||
fun HomeScreen() {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
val lazyListState = rememberLazyListState()
|
||||
|
||||
@@ -82,10 +78,11 @@ fun HomeScreen() {
|
||||
Database.playlistPreviews()
|
||||
}.collectAsState(initial = emptyList(), context = Dispatchers.IO)
|
||||
|
||||
val preferences = LocalPreferences.current
|
||||
var songSortBy by rememberPreference(songSortByKey, SongSortBy.DateAdded)
|
||||
var songSortOrder by rememberPreference(songSortOrderKey, SortOrder.Descending)
|
||||
|
||||
val songCollection by remember(preferences.songSortBy, preferences.songSortOrder) {
|
||||
Database.songs(preferences.songSortBy, preferences.songSortOrder)
|
||||
val songCollection by remember(songSortBy, songSortOrder) {
|
||||
Database.songs(songSortBy, songSortOrder)
|
||||
}.collectAsState(initial = emptyList(), context = Dispatchers.IO)
|
||||
|
||||
RouteHandler(listenToGlobalEmitter = true) {
|
||||
@@ -153,6 +150,9 @@ fun HomeScreen() {
|
||||
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
|
||||
val isFirstLaunch by rememberPreference(isFirstLaunchKey, true)
|
||||
val isCachedPlaylistShown by rememberPreference(isCachedPlaylistShownKey, false)
|
||||
|
||||
val thumbnailSize = Dimensions.thumbnails.song.px
|
||||
|
||||
var isGridExpanded by remember {
|
||||
@@ -199,7 +199,7 @@ fun HomeScreen() {
|
||||
}
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
.run {
|
||||
if (preferences.isFirstLaunch) {
|
||||
if (isFirstLaunch) {
|
||||
drawBehind {
|
||||
drawCircle(
|
||||
color = colorPalette.red,
|
||||
@@ -321,7 +321,7 @@ fun HomeScreen() {
|
||||
}
|
||||
}
|
||||
|
||||
if (preferences.isCachedPlaylistShown) {
|
||||
if (isCachedPlaylistShown) {
|
||||
item {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
@@ -492,16 +492,16 @@ fun HomeScreen() {
|
||||
) {
|
||||
Item(
|
||||
text = "PLAY TIME",
|
||||
isSelected = preferences.songSortBy == SongSortBy.PlayTime,
|
||||
isSelected = songSortBy == SongSortBy.PlayTime,
|
||||
onClick = {
|
||||
preferences.songSortBy = SongSortBy.PlayTime
|
||||
songSortBy = SongSortBy.PlayTime
|
||||
}
|
||||
)
|
||||
Item(
|
||||
text = "DATE ADDED",
|
||||
isSelected = preferences.songSortBy == SongSortBy.DateAdded,
|
||||
isSelected = songSortBy == SongSortBy.DateAdded,
|
||||
onClick = {
|
||||
preferences.songSortBy = SongSortBy.DateAdded
|
||||
songSortBy = SongSortBy.DateAdded
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -518,14 +518,14 @@ fun HomeScreen() {
|
||||
.width(IntrinsicSize.Max),
|
||||
) {
|
||||
Item(
|
||||
text = when (preferences.songSortOrder) {
|
||||
text = when (songSortOrder) {
|
||||
SortOrder.Ascending -> "ASCENDING"
|
||||
SortOrder.Descending -> "DESCENDING"
|
||||
},
|
||||
textColor = colorPalette.text,
|
||||
backgroundColor = colorPalette.elevatedBackground,
|
||||
onClick = {
|
||||
preferences.songSortOrder = !preferences.songSortOrder
|
||||
songSortOrder = !songSortOrder
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -556,7 +556,7 @@ fun HomeScreen() {
|
||||
},
|
||||
onThumbnailContent = {
|
||||
AnimatedVisibility(
|
||||
visible = preferences.songSortBy == SongSortBy.PlayTime,
|
||||
visible = songSortBy == SongSortBy.PlayTime,
|
||||
enter = fadeIn(),
|
||||
exit = fadeOut(),
|
||||
modifier = Modifier
|
||||
|
||||
@@ -27,7 +27,7 @@ import it.vfsfitvnm.vimusic.ui.components.LocalMenuState
|
||||
import it.vfsfitvnm.vimusic.ui.components.TopAppBar
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.*
|
||||
import it.vfsfitvnm.vimusic.ui.styling.Dimensions
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.ui.styling.px
|
||||
import it.vfsfitvnm.vimusic.utils.asMediaItem
|
||||
import it.vfsfitvnm.vimusic.utils.enqueue
|
||||
@@ -61,7 +61,7 @@ fun IntentUriScreen(uri: Uri) {
|
||||
|
||||
host {
|
||||
val menuState = LocalMenuState.current
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
|
||||
val thumbnailSizePx = Dimensions.thumbnails.song.px
|
||||
|
||||
@@ -32,8 +32,7 @@ import it.vfsfitvnm.vimusic.ui.components.LocalMenuState
|
||||
import it.vfsfitvnm.vimusic.ui.components.TopAppBar
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.*
|
||||
import it.vfsfitvnm.vimusic.ui.styling.Dimensions
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.ui.styling.px
|
||||
import it.vfsfitvnm.vimusic.ui.views.SongItem
|
||||
import it.vfsfitvnm.vimusic.utils.*
|
||||
@@ -73,8 +72,7 @@ fun LocalPlaylistScreen(
|
||||
val menuState = LocalMenuState.current
|
||||
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
val thumbnailSize = Dimensions.thumbnails.song.px
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@ import it.vfsfitvnm.vimusic.ui.components.LocalMenuState
|
||||
import it.vfsfitvnm.vimusic.ui.components.TopAppBar
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.*
|
||||
import it.vfsfitvnm.vimusic.ui.styling.Dimensions
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.ui.styling.px
|
||||
import it.vfsfitvnm.vimusic.ui.views.SongItem
|
||||
import it.vfsfitvnm.vimusic.utils.*
|
||||
@@ -73,8 +72,7 @@ fun PlaylistScreen(
|
||||
val context = LocalContext.current
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
val menuState = LocalMenuState.current
|
||||
|
||||
val thumbnailSizePx = Dimensions.thumbnails.playlist.px
|
||||
@@ -387,7 +385,7 @@ private fun LoadingOrError(
|
||||
errorMessage: String? = null,
|
||||
onRetry: (() -> Unit)? = null
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
|
||||
LoadingOrError(
|
||||
errorMessage = errorMessage,
|
||||
|
||||
@@ -37,8 +37,7 @@ import it.vfsfitvnm.vimusic.ui.components.themed.NonQueuedMediaItemMenu
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.TextCard
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.TextPlaceholder
|
||||
import it.vfsfitvnm.vimusic.ui.styling.Dimensions
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.ui.styling.px
|
||||
import it.vfsfitvnm.vimusic.ui.views.SongItem
|
||||
import it.vfsfitvnm.vimusic.utils.*
|
||||
@@ -53,29 +52,29 @@ fun SearchResultScreen(
|
||||
query: String,
|
||||
onSearchAgain: () -> Unit,
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val preferences = LocalPreferences.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
|
||||
var searchFilter by rememberPreference(searchFilterKey, YouTube.Item.Song.Filter.value)
|
||||
|
||||
val lazyListState = rememberLazyListState()
|
||||
|
||||
val items = remember(preferences.searchFilter) {
|
||||
val items = remember(searchFilter) {
|
||||
mutableStateListOf<YouTube.Item>()
|
||||
}
|
||||
|
||||
var continuationResult by remember(preferences.searchFilter) {
|
||||
var continuationResult by remember(searchFilter) {
|
||||
mutableStateOf<Result<String?>?>(null)
|
||||
}
|
||||
|
||||
val onLoad = relaunchableEffect(preferences.searchFilter) {
|
||||
val onLoad = relaunchableEffect(searchFilter) {
|
||||
withContext(Dispatchers.Main) {
|
||||
val token = continuationResult?.getOrNull()
|
||||
|
||||
continuationResult = null
|
||||
|
||||
continuationResult = withContext(Dispatchers.IO) {
|
||||
YouTube.search(query, preferences.searchFilter, token)
|
||||
YouTube.search(query, searchFilter, token)
|
||||
}?.map { searchResult ->
|
||||
items.addAll(searchResult.items)
|
||||
searchResult.continuation
|
||||
@@ -186,14 +185,14 @@ fun SearchResultScreen(
|
||||
value = YouTube.Item.FeaturedPlaylist.Filter.value
|
||||
),
|
||||
),
|
||||
value = preferences.searchFilter,
|
||||
value = searchFilter,
|
||||
selectedBackgroundColor = colorPalette.primaryContainer,
|
||||
unselectedBackgroundColor = colorPalette.lightBackground,
|
||||
selectedTextStyle = typography.xs.medium.color(colorPalette.onPrimaryContainer),
|
||||
unselectedTextStyle = typography.xs.medium,
|
||||
shape = RoundedCornerShape(36.dp),
|
||||
onValueChanged = {
|
||||
preferences.searchFilter = it
|
||||
searchFilter = it
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(vertical = 8.dp)
|
||||
@@ -255,7 +254,7 @@ fun SearchResultScreen(
|
||||
} ?: item(key = "loading") {
|
||||
LoadingOrError(
|
||||
itemCount = if (items.isEmpty()) 8 else 3,
|
||||
isLoadingArtists = preferences.searchFilter == YouTube.Item.Artist.Filter.value
|
||||
isLoadingArtists = searchFilter == YouTube.Item.Artist.Filter.value
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -268,7 +267,7 @@ fun SmallSongItemShimmer(
|
||||
thumbnailSizeDp: Dp,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -293,7 +292,7 @@ fun SmallArtistItemShimmer(
|
||||
thumbnailSizeDp: Dp,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -422,7 +421,7 @@ fun SmallPlaylistItem(
|
||||
thumbnailSizePx: Int,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val typography = LocalTypography.current
|
||||
val (_, typography) = LocalAppearance.current
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -474,7 +473,7 @@ fun SmallAlbumItem(
|
||||
thumbnailSizePx: Int,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val typography = LocalTypography.current
|
||||
val (_, typography) = LocalAppearance.current
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -526,7 +525,7 @@ fun SmallArtistItem(
|
||||
thumbnailSizePx: Int,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val typography = LocalTypography.current
|
||||
val (_, typography) = LocalAppearance.current
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
|
||||
@@ -37,8 +37,7 @@ import it.vfsfitvnm.vimusic.query
|
||||
import it.vfsfitvnm.vimusic.ui.components.TopAppBar
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.LoadingOrError
|
||||
import it.vfsfitvnm.vimusic.ui.styling.Dimensions
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.utils.medium
|
||||
import it.vfsfitvnm.vimusic.utils.secondary
|
||||
import it.vfsfitvnm.youtubemusic.YouTube
|
||||
@@ -104,8 +103,7 @@ fun SearchScreen(
|
||||
}
|
||||
|
||||
host {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
val isOpenableUrl = remember(textFieldValue.text) {
|
||||
listOf(
|
||||
|
||||
@@ -23,8 +23,7 @@ import it.vfsfitvnm.vimusic.ui.components.TopAppBar
|
||||
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
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.utils.*
|
||||
|
||||
|
||||
@@ -92,9 +91,9 @@ fun SettingsScreen() {
|
||||
}
|
||||
|
||||
host {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val preferences = LocalPreferences.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
var isFirstLaunch by rememberPreference(isFirstLaunchKey, true)
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@@ -242,9 +241,9 @@ fun SettingsScreen() {
|
||||
title = "Other",
|
||||
description = "Advanced settings",
|
||||
route = otherSettingsRoute,
|
||||
withAlert = LocalPreferences.current.isFirstLaunch,
|
||||
withAlert = isFirstLaunch,
|
||||
onClick = {
|
||||
preferences.isFirstLaunch = false
|
||||
isFirstLaunch = false
|
||||
}
|
||||
)
|
||||
|
||||
@@ -324,8 +323,7 @@ fun SwitchSettingEntry(
|
||||
modifier: Modifier = Modifier,
|
||||
isEnabled: Boolean = true
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||
@@ -370,8 +368,8 @@ fun SettingsEntry(
|
||||
onClick: () -> Unit,
|
||||
isEnabled: Boolean = true
|
||||
) {
|
||||
val typography = LocalTypography.current
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val (_, typography) = LocalAppearance.current
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
@@ -422,7 +420,7 @@ fun BaseSettingsEntry(
|
||||
titleTextStyle: @Composable TextStyle.() -> TextStyle = { this },
|
||||
textStyle: @Composable TextStyle.() -> TextStyle = { this },
|
||||
) {
|
||||
val typography = LocalTypography.current
|
||||
val (_, typography) = LocalAppearance.current
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
@@ -447,11 +445,11 @@ fun SettingsEntryGroupText(
|
||||
title: String,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
BasicText(
|
||||
text = title.uppercase(),
|
||||
style = typography.xxs.semiBold.copy(LocalColorPalette.current.blue),
|
||||
style = typography.xxs.semiBold.copy(colorPalette.blue),
|
||||
modifier = modifier
|
||||
.padding(start = 24.dp, top = 24.dp)
|
||||
.padding(horizontal = 32.dp)
|
||||
|
||||
@@ -16,12 +16,11 @@ import it.vfsfitvnm.route.RouteHandler
|
||||
import it.vfsfitvnm.vimusic.BuildConfig
|
||||
import it.vfsfitvnm.vimusic.R
|
||||
import it.vfsfitvnm.vimusic.ui.components.TopAppBar
|
||||
import it.vfsfitvnm.vimusic.ui.screens.ArtistScreen
|
||||
import it.vfsfitvnm.vimusic.ui.screens.AlbumScreen
|
||||
import it.vfsfitvnm.vimusic.ui.screens.rememberArtistRoute
|
||||
import it.vfsfitvnm.vimusic.ui.screens.ArtistScreen
|
||||
import it.vfsfitvnm.vimusic.ui.screens.rememberAlbumRoute
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.ui.screens.rememberArtistRoute
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.utils.bold
|
||||
import it.vfsfitvnm.vimusic.utils.secondary
|
||||
import it.vfsfitvnm.vimusic.utils.semiBold
|
||||
@@ -48,8 +47,7 @@ fun AboutScreen() {
|
||||
}
|
||||
|
||||
host {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
val uriHandler = LocalUriHandler.current
|
||||
|
||||
Column(
|
||||
|
||||
@@ -5,18 +5,20 @@ import androidx.compose.foundation.*
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.text.BasicText
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import it.vfsfitvnm.route.RouteHandler
|
||||
import it.vfsfitvnm.vimusic.R
|
||||
import it.vfsfitvnm.vimusic.enums.ColorPaletteMode
|
||||
import it.vfsfitvnm.vimusic.enums.ThumbnailRoundness
|
||||
import it.vfsfitvnm.vimusic.ui.components.TopAppBar
|
||||
import it.vfsfitvnm.vimusic.ui.screens.*
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.utils.LocalPreferences
|
||||
import it.vfsfitvnm.vimusic.utils.semiBold
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.utils.*
|
||||
|
||||
@ExperimentalAnimationApi
|
||||
@Composable
|
||||
@@ -40,9 +42,11 @@ fun AppearanceSettingsScreen() {
|
||||
}
|
||||
|
||||
host {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val preferences = LocalPreferences.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
var colorPaletteMode by rememberPreference(colorPaletteModeKey, ColorPaletteMode.System)
|
||||
var thumbnailRoundness by rememberPreference(thumbnailRoundnessKey, ThumbnailRoundness.Light)
|
||||
var isCachedPlaylistShown by rememberPreference(isCachedPlaylistShownKey, false)
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@@ -81,9 +85,9 @@ fun AppearanceSettingsScreen() {
|
||||
|
||||
EnumValueSelectorSettingsEntry(
|
||||
title = "Theme mode",
|
||||
selectedValue = preferences.colorPaletteMode,
|
||||
selectedValue = colorPaletteMode,
|
||||
onValueSelected = {
|
||||
preferences.colorPaletteMode = it
|
||||
colorPaletteMode = it
|
||||
}
|
||||
)
|
||||
|
||||
@@ -91,9 +95,9 @@ fun AppearanceSettingsScreen() {
|
||||
|
||||
EnumValueSelectorSettingsEntry(
|
||||
title = "Thumbnail roundness",
|
||||
selectedValue = preferences.thumbnailRoundness,
|
||||
selectedValue = thumbnailRoundness,
|
||||
onValueSelected = {
|
||||
preferences.thumbnailRoundness = it
|
||||
thumbnailRoundness = it
|
||||
}
|
||||
)
|
||||
|
||||
@@ -102,9 +106,9 @@ fun AppearanceSettingsScreen() {
|
||||
SwitchSettingEntry(
|
||||
title = "Cached playlist",
|
||||
text = "Display a playlist whose songs can be played offline",
|
||||
isChecked = preferences.isCachedPlaylistShown,
|
||||
isChecked = isCachedPlaylistShown,
|
||||
onCheckedChange = {
|
||||
preferences.isCachedPlaylistShown = it
|
||||
isCachedPlaylistShown = it
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -31,8 +31,7 @@ import it.vfsfitvnm.vimusic.ui.screens.AlbumScreen
|
||||
import it.vfsfitvnm.vimusic.ui.screens.ArtistScreen
|
||||
import it.vfsfitvnm.vimusic.ui.screens.rememberAlbumRoute
|
||||
import it.vfsfitvnm.vimusic.ui.screens.rememberArtistRoute
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.utils.intent
|
||||
import it.vfsfitvnm.vimusic.utils.semiBold
|
||||
import java.io.FileInputStream
|
||||
@@ -64,8 +63,7 @@ fun BackupAndRestoreScreen() {
|
||||
}
|
||||
|
||||
host {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
val context = LocalContext.current
|
||||
|
||||
val backupLauncher =
|
||||
|
||||
@@ -16,13 +16,15 @@ import coil.annotation.ExperimentalCoilApi
|
||||
import it.vfsfitvnm.route.RouteHandler
|
||||
import it.vfsfitvnm.vimusic.LocalPlayerServiceBinder
|
||||
import it.vfsfitvnm.vimusic.R
|
||||
import it.vfsfitvnm.vimusic.enums.CoilDiskCacheMaxSize
|
||||
import it.vfsfitvnm.vimusic.enums.ExoPlayerDiskCacheMaxSize
|
||||
import it.vfsfitvnm.vimusic.ui.components.TopAppBar
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.TextCard
|
||||
import it.vfsfitvnm.vimusic.ui.screens.*
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.utils.LocalPreferences
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.utils.coilDiskCacheMaxSizeKey
|
||||
import it.vfsfitvnm.vimusic.utils.exoPlayerDiskCacheMaxSizeKey
|
||||
import it.vfsfitvnm.vimusic.utils.rememberPreference
|
||||
import it.vfsfitvnm.vimusic.utils.semiBold
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -51,11 +53,12 @@ fun CacheSettingsScreen() {
|
||||
|
||||
host {
|
||||
val context = LocalContext.current
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val preferences = LocalPreferences.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
|
||||
var coilDiskCacheMaxSize by rememberPreference(coilDiskCacheMaxSizeKey, CoilDiskCacheMaxSize.`128MB`)
|
||||
var exoPlayerDiskCacheMaxSize by rememberPreference(exoPlayerDiskCacheMaxSizeKey, ExoPlayerDiskCacheMaxSize.`2GB`)
|
||||
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
Column(
|
||||
@@ -100,9 +103,9 @@ fun CacheSettingsScreen() {
|
||||
|
||||
EnumValueSelectorSettingsEntry(
|
||||
title = "Max size",
|
||||
selectedValue = preferences.coilDiskCacheMaxSize,
|
||||
selectedValue = coilDiskCacheMaxSize,
|
||||
onValueSelected = {
|
||||
preferences.coilDiskCacheMaxSize = it
|
||||
coilDiskCacheMaxSize = it
|
||||
}
|
||||
)
|
||||
|
||||
@@ -114,9 +117,7 @@ fun CacheSettingsScreen() {
|
||||
diskCacheSize
|
||||
)
|
||||
} (${
|
||||
diskCacheSize * 100 / preferences.coilDiskCacheMaxSize.bytes.coerceAtLeast(
|
||||
1
|
||||
)
|
||||
diskCacheSize * 100 / coilDiskCacheMaxSize.bytes.coerceAtLeast(1)
|
||||
}%)",
|
||||
)
|
||||
|
||||
@@ -143,9 +144,9 @@ fun CacheSettingsScreen() {
|
||||
|
||||
EnumValueSelectorSettingsEntry(
|
||||
title = "Max size",
|
||||
selectedValue = preferences.exoPlayerDiskCacheMaxSize,
|
||||
selectedValue = exoPlayerDiskCacheMaxSize,
|
||||
onValueSelected = {
|
||||
preferences.exoPlayerDiskCacheMaxSize = it
|
||||
exoPlayerDiskCacheMaxSize = it
|
||||
}
|
||||
)
|
||||
|
||||
@@ -154,7 +155,7 @@ fun CacheSettingsScreen() {
|
||||
text = buildString {
|
||||
append(Formatter.formatShortFileSize(context, diskCacheSize))
|
||||
|
||||
when (val size = preferences.exoPlayerDiskCacheMaxSize) {
|
||||
when (val size = exoPlayerDiskCacheMaxSize) {
|
||||
ExoPlayerDiskCacheMaxSize.Unlimited -> {}
|
||||
else -> append("(${diskCacheSize * 100 / size.bytes}%)")
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ import it.vfsfitvnm.vimusic.R
|
||||
import it.vfsfitvnm.vimusic.ui.components.TopAppBar
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.TextCard
|
||||
import it.vfsfitvnm.vimusic.ui.screens.*
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.utils.LocalPreferences
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.utils.isIgnoringBatteryOptimizations
|
||||
import it.vfsfitvnm.vimusic.utils.isInvincibilityEnabledKey
|
||||
import it.vfsfitvnm.vimusic.utils.rememberPreference
|
||||
import it.vfsfitvnm.vimusic.utils.semiBold
|
||||
|
||||
|
||||
@@ -53,9 +53,9 @@ fun OtherSettingsScreen() {
|
||||
|
||||
host {
|
||||
val context = LocalContext.current
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val preferences = LocalPreferences.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
var isInvincibilityEnabled by rememberPreference(isInvincibilityEnabledKey, false)
|
||||
|
||||
var isIgnoringBatteryOptimizations by remember {
|
||||
mutableStateOf(context.isIgnoringBatteryOptimizations)
|
||||
@@ -140,9 +140,9 @@ fun OtherSettingsScreen() {
|
||||
SwitchSettingEntry(
|
||||
title = "Invincible service",
|
||||
text = "When turning off battery optimizations is not enough",
|
||||
isChecked = preferences.isInvincibilityEnabled,
|
||||
isChecked = isInvincibilityEnabled,
|
||||
onCheckedChange = {
|
||||
preferences.isInvincibilityEnabled = it
|
||||
isInvincibilityEnabled = it
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ import androidx.compose.foundation.*
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.text.BasicText
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@@ -20,10 +22,8 @@ import it.vfsfitvnm.vimusic.LocalPlayerServiceBinder
|
||||
import it.vfsfitvnm.vimusic.R
|
||||
import it.vfsfitvnm.vimusic.ui.components.TopAppBar
|
||||
import it.vfsfitvnm.vimusic.ui.screens.*
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.utils.LocalPreferences
|
||||
import it.vfsfitvnm.vimusic.utils.semiBold
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.utils.*
|
||||
|
||||
|
||||
@ExperimentalAnimationApi
|
||||
@@ -49,11 +49,13 @@ fun PlayerSettingsScreen() {
|
||||
|
||||
host {
|
||||
val context = LocalContext.current
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val preferences = LocalPreferences.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
|
||||
var persistentQueue by rememberPreference(persistentQueueKey, false)
|
||||
var skipSilence by rememberPreference(skipSilenceKey, false)
|
||||
var volumeNormalization by rememberPreference(volumeNormalizationKey, false)
|
||||
|
||||
val activityResultLauncher =
|
||||
rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
}
|
||||
@@ -96,9 +98,9 @@ fun PlayerSettingsScreen() {
|
||||
SwitchSettingEntry(
|
||||
title = "Persistent queue",
|
||||
text = "Save and restore playing songs",
|
||||
isChecked = preferences.persistentQueue,
|
||||
isChecked = persistentQueue,
|
||||
onCheckedChange = {
|
||||
preferences.persistentQueue = it
|
||||
persistentQueue = it
|
||||
}
|
||||
)
|
||||
|
||||
@@ -107,19 +109,18 @@ fun PlayerSettingsScreen() {
|
||||
SwitchSettingEntry(
|
||||
title = "Skip silence",
|
||||
text = "Skip silent parts during playback",
|
||||
isChecked = preferences.skipSilence,
|
||||
isChecked = skipSilence,
|
||||
onCheckedChange = {
|
||||
binder?.player?.skipSilenceEnabled = it
|
||||
preferences.skipSilence = it
|
||||
skipSilence = it
|
||||
}
|
||||
)
|
||||
|
||||
SwitchSettingEntry(
|
||||
title = "Loudness normalization",
|
||||
text = "Lower the volume to a standard level",
|
||||
isChecked = preferences.volumeNormalization,
|
||||
isChecked = volumeNormalization,
|
||||
onCheckedChange = {
|
||||
preferences.volumeNormalization = it
|
||||
volumeNormalization = it
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user