[Fix] system theme initial, toggle theme first time
This commit is contained in:
+1
@@ -24,6 +24,7 @@ class AppStoragePlatform(context: Context) : AppStorage {
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : Any> load(key: String, type: KClass<T>): T? {
|
||||
if (!prefs.contains(key)) return null
|
||||
return when (type) {
|
||||
String::class -> prefs.getString(key, null) as T?
|
||||
Int::class -> prefs.getInt(key, -1) as T?
|
||||
|
||||
@@ -10,8 +10,9 @@ import org.koin.compose.viewmodel.koinViewModel
|
||||
|
||||
@Composable
|
||||
@Preview
|
||||
fun App() {
|
||||
val viewModel = koinViewModel<AppViewModel>()
|
||||
fun App(
|
||||
viewModel: AppViewModel = koinViewModel()
|
||||
) {
|
||||
val savedTheme = viewModel.isDarkTheme.value
|
||||
val isDarkTheme = savedTheme ?: isSystemInDarkTheme()
|
||||
val isLoggedIn = viewModel.isLoggedIn()
|
||||
|
||||
+3
-1
@@ -12,6 +12,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.navigation.NavType
|
||||
import androidx.navigation.compose.NavHost
|
||||
@@ -62,6 +63,7 @@ fun MainScreen(
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
val noNavbar = listOf(AuthDestination.route, CommunicationDestination.route)
|
||||
val startRoute = rememberSaveable { if (isLoggedIn) HomeDestination.route else AuthDestination.route }
|
||||
|
||||
val sessionExpired by viewModel.sessionExpired
|
||||
|
||||
@@ -122,7 +124,7 @@ fun MainScreen(
|
||||
) { innerPadding ->
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = if (isLoggedIn) HomeDestination.route else AuthDestination.route,
|
||||
startDestination = startRoute,
|
||||
modifier = Modifier.padding(innerPadding).fillMaxSize()
|
||||
) {
|
||||
composable(AuthDestination.route) { LoginScreen(navController) }
|
||||
|
||||
+1
@@ -25,6 +25,7 @@ class AppStoragePlatform : AppStorage {
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : Any> load(key: String, type: KClass<T>): T? {
|
||||
if (defaults.objectForKey(key) == null) return null
|
||||
return when (type) {
|
||||
String::class -> defaults.stringForKey(key) as T?
|
||||
Int::class -> defaults.integerForKey(key).toInt() as T?
|
||||
|
||||
Reference in New Issue
Block a user