fix: fix theme switch

This commit is contained in:
k1ngsterr1
2026-02-03 16:06:53 +05:00
parent fa22c2dccd
commit af4df0a353
3 changed files with 42 additions and 14 deletions

View File

@@ -12,6 +12,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.*
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
@@ -129,7 +130,14 @@ class MainActivity : FragmentActivity() {
}
val scope = rememberCoroutineScope()
val isDarkTheme by preferencesManager.isDarkTheme.collectAsState(initial = true)
val themeMode by preferencesManager.themeMode.collectAsState(initial = "dark")
val systemInDarkTheme = isSystemInDarkTheme()
val isDarkTheme = when (themeMode) {
"light" -> false
"dark" -> true
"auto" -> systemInDarkTheme
else -> true
}
val isLoggedIn by accountManager.isLoggedIn.collectAsState(initial = null)
var showSplash by remember { mutableStateOf(true) }
var showOnboarding by remember { mutableStateOf(true) }
@@ -296,11 +304,17 @@ class MainActivity : FragmentActivity() {
MainScreen(
account = currentAccount,
isDarkTheme = isDarkTheme,
themeMode = themeMode,
onToggleTheme = {
scope.launch {
preferencesManager.setDarkTheme(!isDarkTheme)
}
},
onThemeModeChange = { mode ->
scope.launch {
preferencesManager.setThemeMode(mode)
}
},
onLogout = {
// Set currentAccount to null immediately to prevent UI
// lag
@@ -461,7 +475,9 @@ class MainActivity : FragmentActivity() {
fun MainScreen(
account: DecryptedAccount? = null,
isDarkTheme: Boolean = true,
themeMode: String = "dark",
onToggleTheme: () -> Unit = {},
onThemeModeChange: (String) -> Unit = {},
onLogout: () -> Unit = {},
onAccountInfoUpdated: suspend () -> Unit = {}
) {
@@ -667,13 +683,12 @@ fun MainScreen(
if (showThemeScreen) {
ThemeScreen(
isDarkTheme = isDarkTheme,
onBack = {
currentThemeMode = themeMode,
onBack = {
showThemeScreen = false
showProfileScreen = true
},
onThemeChange = { isDark ->
onToggleTheme()
}
onThemeModeChange = onThemeModeChange
)
}
}