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)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user