Refactor preferences to avoid a global state when it's not necessary
This commit is contained in:
@@ -34,8 +34,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import it.vfsfitvnm.vimusic.ui.components.ChunkyButton
|
||||
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.*
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
@@ -56,8 +55,7 @@ fun TextFieldDialog(
|
||||
val focusRequester = remember {
|
||||
FocusRequester()
|
||||
}
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
var textFieldValue by rememberSaveable(initialTextInput, stateSaver = TextFieldValue.Saver) {
|
||||
mutableStateOf(
|
||||
@@ -162,8 +160,7 @@ fun ConfirmationDialog(
|
||||
confirmText: String = "Confirm",
|
||||
onCancel: () -> Unit = onDismiss
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
DefaultDialog(
|
||||
onDismiss = onDismiss,
|
||||
@@ -211,6 +208,8 @@ inline fun DefaultDialog(
|
||||
horizontalAlignment: Alignment.Horizontal = Alignment.CenterHorizontally,
|
||||
crossinline content: @Composable ColumnScope.() -> Unit
|
||||
) {
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
|
||||
Dialog(
|
||||
onDismissRequest = onDismiss,
|
||||
properties = DialogProperties(usePlatformDefaultWidth = false)
|
||||
@@ -220,7 +219,7 @@ inline fun DefaultDialog(
|
||||
modifier = modifier
|
||||
.padding(all = 48.dp)
|
||||
.background(
|
||||
color = LocalColorPalette.current.elevatedBackground,
|
||||
color = colorPalette.elevatedBackground,
|
||||
shape = RoundedCornerShape(8.dp)
|
||||
)
|
||||
.padding(horizontal = 24.dp, vertical = 16.dp),
|
||||
@@ -240,15 +239,14 @@ inline fun <T> ValueSelectorDialog(
|
||||
modifier: Modifier = Modifier,
|
||||
crossinline valueText: (T) -> String = { it.toString() }
|
||||
) {
|
||||
val typography = LocalTypography.current
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
Dialog(onDismissRequest = onDismiss) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.padding(all = 48.dp)
|
||||
.background(
|
||||
color = LocalColorPalette.current.elevatedBackground,
|
||||
color = colorPalette.elevatedBackground,
|
||||
shape = RoundedCornerShape(8.dp)
|
||||
)
|
||||
.padding(vertical = 16.dp),
|
||||
|
||||
@@ -31,8 +31,7 @@ import it.vfsfitvnm.vimusic.ui.components.Pager
|
||||
import it.vfsfitvnm.vimusic.ui.screens.rememberAlbumRoute
|
||||
import it.vfsfitvnm.vimusic.ui.screens.rememberArtistRoute
|
||||
import it.vfsfitvnm.vimusic.ui.screens.rememberCreatePlaylistRoute
|
||||
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.*
|
||||
import it.vfsfitvnm.youtubemusic.models.NavigationEndpoint
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -371,8 +370,7 @@ fun MediaItemMenu(
|
||||
|
||||
onSetSleepTimer?.let { onSetSleepTimer ->
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
val typography = LocalTypography.current
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
var isShowingSleepTimerDialog by remember {
|
||||
mutableStateOf(false)
|
||||
|
||||
@@ -16,8 +16,7 @@ import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import it.vfsfitvnm.vimusic.R
|
||||
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
|
||||
|
||||
@@ -27,7 +26,7 @@ inline fun Menu(
|
||||
modifier: Modifier = Modifier,
|
||||
content: @Composable ColumnScope.() -> Unit
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
@@ -52,8 +51,7 @@ fun MenuEntry(
|
||||
secondaryText: String? = null,
|
||||
isEnabled: Boolean = true,
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -99,7 +97,7 @@ fun MenuIconButton(
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
|
||||
@@ -16,7 +16,7 @@ import androidx.compose.ui.geometry.center
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shadow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.utils.drawCircle
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ fun Switch(
|
||||
isChecked: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
|
||||
val backgroundColor by animateColorAsState(if (isChecked) colorPalette.primaryContainer else colorPalette.lightBackground)
|
||||
val color by animateColorAsState(if (isChecked) colorPalette.onPrimaryContainer else colorPalette.textDisabled)
|
||||
|
||||
@@ -17,8 +17,7 @@ import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
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.align
|
||||
import it.vfsfitvnm.vimusic.utils.secondary
|
||||
import it.vfsfitvnm.vimusic.utils.semiBold
|
||||
@@ -32,7 +31,7 @@ fun TextCard(
|
||||
onClick: (() -> Unit)? = null,
|
||||
content: @Composable TextCardScope.() -> Unit,
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
@@ -72,17 +71,19 @@ interface TextCardScope {
|
||||
private object TextCardScopeImpl : TextCardScope {
|
||||
@Composable
|
||||
override fun Title(text: String) {
|
||||
val (_, typography) = LocalAppearance.current
|
||||
BasicText(
|
||||
text = text,
|
||||
style = LocalTypography.current.xxs.semiBold,
|
||||
style = typography.xxs.semiBold,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun Text(text: String) {
|
||||
val (_, typography) = LocalAppearance.current
|
||||
BasicText(
|
||||
text = text,
|
||||
style = LocalTypography.current.xxs.secondary.align(TextAlign.Justify),
|
||||
style = typography.xxs.secondary.align(TextAlign.Justify),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -90,9 +91,10 @@ private object TextCardScopeImpl : TextCardScope {
|
||||
private object IconTextCardScopeImpl : TextCardScope {
|
||||
@Composable
|
||||
override fun Title(text: String) {
|
||||
val (_, typography) = LocalAppearance.current
|
||||
BasicText(
|
||||
text = text,
|
||||
style = LocalTypography.current.xxs.semiBold,
|
||||
style = typography.xxs.semiBold,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp)
|
||||
)
|
||||
@@ -100,9 +102,10 @@ private object IconTextCardScopeImpl : TextCardScope {
|
||||
|
||||
@Composable
|
||||
override fun Text(text: String) {
|
||||
val (_, typography) = LocalAppearance.current
|
||||
BasicText(
|
||||
text = text,
|
||||
style = LocalTypography.current.xxs.secondary,
|
||||
style = typography.xxs.secondary,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp)
|
||||
)
|
||||
|
||||
@@ -10,20 +10,18 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import kotlin.random.Random
|
||||
|
||||
@Composable
|
||||
fun TextPlaceholder(
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
Spacer(
|
||||
modifier = modifier
|
||||
.padding(vertical = 4.dp)
|
||||
.background(
|
||||
color = LocalColorPalette.current.darkGray,
|
||||
shape = RoundedCornerShape(0.dp)
|
||||
)
|
||||
.background(color = colorPalette.darkGray, shape = RoundedCornerShape(0.dp))
|
||||
.fillMaxWidth(remember { 0.25f + Random.nextFloat() * 0.5f })
|
||||
.height(16.dp)
|
||||
)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package it.vfsfitvnm.vimusic.ui.styling
|
||||
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
|
||||
data class Appearance(
|
||||
val colorPalette: ColorPalette,
|
||||
val typography: Typography,
|
||||
val thumbnailShape: Shape
|
||||
)
|
||||
|
||||
val LocalAppearance = staticCompositionLocalOf<Appearance> { TODO() }
|
||||
@@ -82,5 +82,3 @@ val LightColorPalette = ColorPalette(
|
||||
// iconOnPrimaryContainer = Color(0xff2e30b8),
|
||||
isDark = false
|
||||
)
|
||||
|
||||
val LocalColorPalette = staticCompositionLocalOf { LightColorPalette }
|
||||
|
||||
@@ -23,53 +23,3 @@ data class Typography(
|
||||
val m: TextStyle,
|
||||
val l: TextStyle,
|
||||
)
|
||||
|
||||
val LocalTypography = staticCompositionLocalOf<Typography> { TODO() }
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@OptIn(ExperimentalTextApi::class)
|
||||
@Composable
|
||||
fun rememberTypography(color: Color): Typography {
|
||||
return remember(color) {
|
||||
TextStyle(
|
||||
fontFamily = FontFamily(
|
||||
Font(
|
||||
resId = R.font.poppins_w300,
|
||||
weight = FontWeight.Light
|
||||
),
|
||||
Font(
|
||||
resId = R.font.poppins_w400,
|
||||
weight = FontWeight.Normal
|
||||
),
|
||||
Font(
|
||||
resId = R.font.poppins_w400_italic,
|
||||
weight = FontWeight.Normal,
|
||||
style = FontStyle.Italic
|
||||
),
|
||||
Font(
|
||||
resId = R.font.poppins_w500,
|
||||
weight = FontWeight.Medium
|
||||
),
|
||||
Font(
|
||||
resId = R.font.poppins_w600,
|
||||
weight = FontWeight.SemiBold
|
||||
),
|
||||
Font(
|
||||
resId = R.font.poppins_w700,
|
||||
weight = FontWeight.Bold
|
||||
),
|
||||
),
|
||||
fontWeight = FontWeight.Normal,
|
||||
color = color,
|
||||
platformStyle = PlatformTextStyle(includeFontPadding = false)
|
||||
).run {
|
||||
Typography(
|
||||
xxs = copy(fontSize = 12.sp),
|
||||
xs = copy(fontSize = 14.sp),
|
||||
s = copy(fontSize = 16.sp),
|
||||
m = copy(fontSize = 18.sp),
|
||||
l = copy(fontSize = 20.sp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,7 @@ import it.vfsfitvnm.vimusic.ui.components.BottomSheetState
|
||||
import it.vfsfitvnm.vimusic.ui.components.MusicBars
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.QueuedMediaItemMenu
|
||||
import it.vfsfitvnm.vimusic.ui.screens.SmallSongItemShimmer
|
||||
import it.vfsfitvnm.vimusic.ui.styling.Dimensions
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LightColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalColorPalette
|
||||
import it.vfsfitvnm.vimusic.ui.styling.px
|
||||
import it.vfsfitvnm.vimusic.ui.styling.*
|
||||
import it.vfsfitvnm.vimusic.utils.PlayerState
|
||||
|
||||
|
||||
@@ -53,7 +50,7 @@ fun CurrentPlaylistView(
|
||||
) {
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
val hapticFeedback = LocalHapticFeedback.current
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
|
||||
val thumbnailSize = Dimensions.thumbnails.song.px
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import it.vfsfitvnm.vimusic.R
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.TextCard
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.TextFieldDialog
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.TextPlaceholder
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalTypography
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.utils.center
|
||||
import it.vfsfitvnm.vimusic.utils.secondary
|
||||
|
||||
@@ -32,7 +32,7 @@ fun LyricsView(
|
||||
onLyricsUpdate: (String) -> Unit,
|
||||
nestedScrollConnectionProvider: () -> NestedScrollConnection,
|
||||
) {
|
||||
val typography = LocalTypography.current
|
||||
val (_, typography) = LocalAppearance.current
|
||||
|
||||
var isEditingLyrics by remember {
|
||||
mutableStateOf(false)
|
||||
|
||||
@@ -28,8 +28,7 @@ import it.vfsfitvnm.vimusic.ui.components.BottomSheet
|
||||
import it.vfsfitvnm.vimusic.ui.components.BottomSheetState
|
||||
import it.vfsfitvnm.vimusic.ui.components.HorizontalTabPager
|
||||
import it.vfsfitvnm.vimusic.ui.components.rememberTabPagerState
|
||||
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.PlayerState
|
||||
import it.vfsfitvnm.vimusic.utils.center
|
||||
import it.vfsfitvnm.vimusic.utils.color
|
||||
@@ -50,8 +49,7 @@ fun PlayerBottomSheet(
|
||||
onGlobalRouteEmitted: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
|
||||
@@ -63,8 +63,7 @@ fun PlayerView(
|
||||
) {
|
||||
val menuState = LocalMenuState.current
|
||||
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
val context = LocalContext.current
|
||||
val configuration = LocalConfiguration.current
|
||||
@@ -318,7 +317,7 @@ private fun Thumbnail(
|
||||
song: Song?,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val typography = LocalTypography.current
|
||||
val (_, typography) = LocalAppearance.current
|
||||
val context = LocalContext.current
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
val player = binder?.player ?: return
|
||||
@@ -527,9 +526,7 @@ private fun Controls(
|
||||
song: Song?,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val typography = LocalTypography.current
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val preferences = LocalPreferences.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
val player = binder?.player ?: return
|
||||
@@ -730,9 +727,8 @@ private fun Controls(
|
||||
player.repeatMode
|
||||
.plus(2)
|
||||
.mod(3)
|
||||
.let { repeatMode ->
|
||||
player.repeatMode = repeatMode
|
||||
preferences.repeatMode = repeatMode
|
||||
.let {
|
||||
player.repeatMode = it
|
||||
}
|
||||
}
|
||||
.weight(1f)
|
||||
|
||||
@@ -23,8 +23,7 @@ import coil.compose.AsyncImage
|
||||
import it.vfsfitvnm.vimusic.Database
|
||||
import it.vfsfitvnm.vimusic.models.PlaylistPreview
|
||||
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.color
|
||||
import it.vfsfitvnm.vimusic.utils.semiBold
|
||||
import it.vfsfitvnm.vimusic.utils.thumbnail
|
||||
@@ -38,8 +37,7 @@ fun PlaylistPreviewItem(
|
||||
modifier: Modifier = Modifier,
|
||||
thumbnailSize: Dp = Dimensions.thumbnails.song,
|
||||
) {
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
val density = LocalDensity.current
|
||||
|
||||
val thumbnailSizePx = density.run {
|
||||
|
||||
@@ -26,8 +26,7 @@ import it.vfsfitvnm.vimusic.enums.ThumbnailRoundness
|
||||
import it.vfsfitvnm.vimusic.models.DetailedSong
|
||||
import it.vfsfitvnm.vimusic.ui.components.LocalMenuState
|
||||
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.secondary
|
||||
import it.vfsfitvnm.vimusic.utils.semiBold
|
||||
import it.vfsfitvnm.vimusic.utils.thumbnail
|
||||
@@ -150,8 +149,7 @@ fun SongItem(
|
||||
trailingContent: (@Composable () -> Unit)? = null
|
||||
) {
|
||||
val menuState = LocalMenuState.current
|
||||
val colorPalette = LocalColorPalette.current
|
||||
val typography = LocalTypography.current
|
||||
val (colorPalette, typography) = LocalAppearance.current
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
|
||||
Reference in New Issue
Block a user