Changes the Theme class to only take the preferred theme directly.

This commit is contained in:
Vitor Pamplona
2025-09-06 10:43:54 -04:00
parent caf325f240
commit 7087fb85f0
2 changed files with 11 additions and 21 deletions

View File

@@ -27,25 +27,19 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.compose.viewModel
import com.vitorpamplona.amethyst.model.ThemeType import com.vitorpamplona.amethyst.model.ThemeType
import com.vitorpamplona.amethyst.ui.screen.SharedPreferencesViewModel
@Composable @Composable
fun ThemeComparisonColumn(toPreview: @Composable () -> Unit) { fun ThemeComparisonColumn(toPreview: @Composable () -> Unit) {
Column { Column {
Box { Box {
val darkTheme: SharedPreferencesViewModel = viewModel() AmethystTheme(ThemeType.DARK) {
darkTheme.updateTheme(ThemeType.DARK)
AmethystTheme(darkTheme) {
Surface(color = MaterialTheme.colorScheme.background) { toPreview() } Surface(color = MaterialTheme.colorScheme.background) { toPreview() }
} }
} }
Box { Box {
val lightTheme: SharedPreferencesViewModel = viewModel() AmethystTheme(ThemeType.LIGHT) {
lightTheme.updateTheme(ThemeType.LIGHT)
AmethystTheme(lightTheme) {
Surface(color = MaterialTheme.colorScheme.background) { toPreview() } Surface(color = MaterialTheme.colorScheme.background) { toPreview() }
} }
} }
@@ -56,17 +50,13 @@ fun ThemeComparisonColumn(toPreview: @Composable () -> Unit) {
fun ThemeComparisonRow(toPreview: @Composable () -> Unit) { fun ThemeComparisonRow(toPreview: @Composable () -> Unit) {
Row { Row {
Box(modifier = Modifier.weight(1f)) { Box(modifier = Modifier.weight(1f)) {
val darkTheme: SharedPreferencesViewModel = viewModel() AmethystTheme(ThemeType.DARK) {
darkTheme.updateTheme(ThemeType.DARK)
AmethystTheme(darkTheme) {
Surface(color = MaterialTheme.colorScheme.background) { toPreview() } Surface(color = MaterialTheme.colorScheme.background) { toPreview() }
} }
} }
Box(modifier = Modifier.weight(1f)) { Box(modifier = Modifier.weight(1f)) {
val lightTheme: SharedPreferencesViewModel = viewModel() AmethystTheme(ThemeType.LIGHT) {
lightTheme.updateTheme(ThemeType.LIGHT)
AmethystTheme(lightTheme) {
Surface(color = MaterialTheme.colorScheme.background) { toPreview() } Surface(color = MaterialTheme.colorScheme.background) { toPreview() }
} }
} }

View File

@@ -38,6 +38,7 @@ import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
@@ -58,7 +59,6 @@ import com.halilibo.richtext.ui.resolveDefaults
import com.patrykandpatrick.vico.compose.common.VicoTheme import com.patrykandpatrick.vico.compose.common.VicoTheme
import com.patrykandpatrick.vico.compose.common.VicoTheme.CandlestickCartesianLayerColors import com.patrykandpatrick.vico.compose.common.VicoTheme.CandlestickCartesianLayerColors
import com.vitorpamplona.amethyst.model.ThemeType import com.vitorpamplona.amethyst.model.ThemeType
import com.vitorpamplona.amethyst.ui.screen.SharedPreferencesViewModel
private val DarkColorPalette = private val DarkColorPalette =
darkColorScheme( darkColorScheme(
@@ -484,20 +484,20 @@ val ColorScheme.chartStyle: VicoTheme
@Composable @Composable
fun AmethystTheme( fun AmethystTheme(
sharedPrefsViewModel: SharedPreferencesViewModel, prefTheme: ThemeType,
content: @Composable () -> Unit, content: @Composable () -> Unit,
) { ) {
val context = LocalContext.current val context = LocalContext.current
val darkTheme = val darkTheme =
when (sharedPrefsViewModel.sharedPrefs.theme) { when (prefTheme) {
ThemeType.DARK -> { ThemeType.DARK -> {
val uiManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager? val uiManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
uiManager!!.nightMode = UiModeManager.MODE_NIGHT_YES uiManager.nightMode = UiModeManager.MODE_NIGHT_YES
true true
} }
ThemeType.LIGHT -> { ThemeType.LIGHT -> {
val uiManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager? val uiManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
uiManager!!.nightMode = UiModeManager.MODE_NIGHT_NO uiManager.nightMode = UiModeManager.MODE_NIGHT_NO
false false
} }
else -> isSystemInDarkTheme() else -> isSystemInDarkTheme()