mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-20 19:40:46 +02:00
Changes the Theme class to only take the preferred theme directly.
This commit is contained in:
@@ -27,25 +27,19 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.vitorpamplona.amethyst.model.ThemeType
|
||||
import com.vitorpamplona.amethyst.ui.screen.SharedPreferencesViewModel
|
||||
|
||||
@Composable
|
||||
fun ThemeComparisonColumn(toPreview: @Composable () -> Unit) {
|
||||
Column {
|
||||
Box {
|
||||
val darkTheme: SharedPreferencesViewModel = viewModel()
|
||||
darkTheme.updateTheme(ThemeType.DARK)
|
||||
AmethystTheme(darkTheme) {
|
||||
AmethystTheme(ThemeType.DARK) {
|
||||
Surface(color = MaterialTheme.colorScheme.background) { toPreview() }
|
||||
}
|
||||
}
|
||||
|
||||
Box {
|
||||
val lightTheme: SharedPreferencesViewModel = viewModel()
|
||||
lightTheme.updateTheme(ThemeType.LIGHT)
|
||||
AmethystTheme(lightTheme) {
|
||||
AmethystTheme(ThemeType.LIGHT) {
|
||||
Surface(color = MaterialTheme.colorScheme.background) { toPreview() }
|
||||
}
|
||||
}
|
||||
@@ -56,17 +50,13 @@ fun ThemeComparisonColumn(toPreview: @Composable () -> Unit) {
|
||||
fun ThemeComparisonRow(toPreview: @Composable () -> Unit) {
|
||||
Row {
|
||||
Box(modifier = Modifier.weight(1f)) {
|
||||
val darkTheme: SharedPreferencesViewModel = viewModel()
|
||||
darkTheme.updateTheme(ThemeType.DARK)
|
||||
AmethystTheme(darkTheme) {
|
||||
AmethystTheme(ThemeType.DARK) {
|
||||
Surface(color = MaterialTheme.colorScheme.background) { toPreview() }
|
||||
}
|
||||
}
|
||||
|
||||
Box(modifier = Modifier.weight(1f)) {
|
||||
val lightTheme: SharedPreferencesViewModel = viewModel()
|
||||
lightTheme.updateTheme(ThemeType.LIGHT)
|
||||
AmethystTheme(lightTheme) {
|
||||
AmethystTheme(ThemeType.LIGHT) {
|
||||
Surface(color = MaterialTheme.colorScheme.background) { toPreview() }
|
||||
}
|
||||
}
|
||||
|
@@ -38,6 +38,7 @@ import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
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.CandlestickCartesianLayerColors
|
||||
import com.vitorpamplona.amethyst.model.ThemeType
|
||||
import com.vitorpamplona.amethyst.ui.screen.SharedPreferencesViewModel
|
||||
|
||||
private val DarkColorPalette =
|
||||
darkColorScheme(
|
||||
@@ -484,20 +484,20 @@ val ColorScheme.chartStyle: VicoTheme
|
||||
|
||||
@Composable
|
||||
fun AmethystTheme(
|
||||
sharedPrefsViewModel: SharedPreferencesViewModel,
|
||||
prefTheme: ThemeType,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val darkTheme =
|
||||
when (sharedPrefsViewModel.sharedPrefs.theme) {
|
||||
when (prefTheme) {
|
||||
ThemeType.DARK -> {
|
||||
val uiManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager?
|
||||
uiManager!!.nightMode = UiModeManager.MODE_NIGHT_YES
|
||||
val uiManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
|
||||
uiManager.nightMode = UiModeManager.MODE_NIGHT_YES
|
||||
true
|
||||
}
|
||||
ThemeType.LIGHT -> {
|
||||
val uiManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager?
|
||||
uiManager!!.nightMode = UiModeManager.MODE_NIGHT_NO
|
||||
val uiManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
|
||||
uiManager.nightMode = UiModeManager.MODE_NIGHT_NO
|
||||
false
|
||||
}
|
||||
else -> isSystemInDarkTheme()
|
||||
|
Reference in New Issue
Block a user