Refactor preferences to avoid a global state when it's not necessary

This commit is contained in:
vfsfitvnm
2022-07-16 13:51:38 +02:00
parent aa8e065412
commit 1e719b33ed
38 changed files with 415 additions and 452 deletions

View File

@@ -1,9 +1,20 @@
package it.vfsfitvnm.vimusic.enums
import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.PlatformTextStyle
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import it.vfsfitvnm.vimusic.R
import it.vfsfitvnm.vimusic.ui.styling.BlackColorPalette
import it.vfsfitvnm.vimusic.ui.styling.ColorPalette
import it.vfsfitvnm.vimusic.ui.styling.DarkColorPalette
import it.vfsfitvnm.vimusic.ui.styling.LightColorPalette
import it.vfsfitvnm.vimusic.ui.styling.Typography
enum class ColorPaletteMode {
Light,
@@ -22,4 +33,50 @@ enum class ColorPaletteMode {
}
}
}
@OptIn(ExperimentalTextApi::class)
fun typography(isSystemInDarkMode: Boolean): Typography {
val color = palette(isSystemInDarkMode).text
val textStyle = 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 = @Suppress("DEPRECATION") PlatformTextStyle(includeFontPadding = false)
)
return Typography(
xxs = textStyle.copy(fontSize = 12.sp),
xs = textStyle.copy(fontSize = 14.sp),
s = textStyle.copy(fontSize = 16.sp),
m = textStyle.copy(fontSize = 18.sp),
l = textStyle.copy(fontSize = 20.sp),
)
}
}

View File

@@ -6,7 +6,7 @@ import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.dp
import it.vfsfitvnm.vimusic.utils.LocalPreferences
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
enum class ThumbnailRoundness {
None,
@@ -14,15 +14,19 @@ enum class ThumbnailRoundness {
Medium,
Heavy;
fun shape(): Shape {
return when (this) {
None -> RectangleShape
Light -> RoundedCornerShape(2.dp)
Medium -> RoundedCornerShape(4.dp)
Heavy -> RoundedCornerShape(8.dp)
}
}
companion object {
val shape: Shape
@Composable
@ReadOnlyComposable
get() = when (LocalPreferences.current.thumbnailRoundness) {
None -> RectangleShape
Light -> RoundedCornerShape(2.dp)
Medium -> RoundedCornerShape(4.dp)
Heavy -> RoundedCornerShape(8.dp)
}
get() = LocalAppearance.current.thumbnailShape
}
}