feat(settings): add option for different themes

This commit is contained in:
Anthony Berg 2024-08-10 15:31:06 +02:00
parent 64159b798b
commit 1a77654d29
3 changed files with 49 additions and 2 deletions

View File

@ -4,8 +4,10 @@ import App
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import data.SettingsVar
import io.anthonyberg.veganenumbers.ui.theme.AppTheme
class MainActivity : ComponentActivity() {
@ -13,7 +15,13 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
setContent {
AppTheme {
AppTheme(
darkTheme = when(SettingsVar.theme.value) {
1 -> false
2 -> true
else -> isSystemInDarkTheme()
}
) {
App()
}
}

View File

@ -0,0 +1,7 @@
package data
import androidx.compose.runtime.mutableIntStateOf
object SettingsVar {
val theme = mutableIntStateOf(0)
}

View File

@ -1,16 +1,22 @@
package tab.setting
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import data.SettingsVar
object Settings : Screen {
@ -42,7 +48,33 @@ object Settings : Screen {
@Composable
private fun SettingsContent() {
Text("Theme")
Theme()
Text("List Style")
}
/**
* ALl the different themes that can be picked
* - 0 - Auto
* - 1 - Light
* - 2 - Dark
*/
@Composable
private fun Theme() {
var mode by rememberSaveable { SettingsVar.theme }
val themes = listOf("Auto", "Light", "Dark")
Text("Theme")
for ((index, value) in themes.withIndex()) {
Row(
verticalAlignment = Alignment.CenterVertically,
) {
RadioButton(
selected = mode == index,
onClick = { mode = index }
)
Text(value)
}
}
}
}