Merge pull request #234 from Hy4ri/feat/issue-232-dynamic-theme
feat(#232): dynamic theme switch on settings save
This commit is contained in:
@@ -7,6 +7,8 @@ import androidx.activity.enableEdgeToEdge
|
|||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import com.m57.hermescontrol.data.local.AuthManager
|
import com.m57.hermescontrol.data.local.AuthManager
|
||||||
import com.m57.hermescontrol.notification.NotificationReplyReceiver
|
import com.m57.hermescontrol.notification.NotificationReplyReceiver
|
||||||
@@ -21,11 +23,8 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
setContent {
|
setContent {
|
||||||
// B6 (Jun 18 2026, kanban t_86e9be9b): read the stored theme
|
val themePreference by AuthManager.themePreferenceFlow.collectAsState()
|
||||||
// preference at startup so HermesControlTheme actually applies
|
HermesControlTheme(themePreference = themePreference) {
|
||||||
// the user's SYSTEM/LIGHT/DARK choice rather than defaulting to
|
|
||||||
// SYSTEM on every cold start.
|
|
||||||
HermesControlTheme(themePreference = AuthManager.getThemePreference()) {
|
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
color = MaterialTheme.colorScheme.background,
|
color = MaterialTheme.colorScheme.background,
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ object AuthManager {
|
|||||||
private val _bottomNavItemsFlow = MutableStateFlow<List<String>>(emptyList())
|
private val _bottomNavItemsFlow = MutableStateFlow<List<String>>(emptyList())
|
||||||
val bottomNavItemsFlow: StateFlow<List<String>> = _bottomNavItemsFlow.asStateFlow()
|
val bottomNavItemsFlow: StateFlow<List<String>> = _bottomNavItemsFlow.asStateFlow()
|
||||||
|
|
||||||
|
private val _themePreferenceFlow = MutableStateFlow<ThemePreference>(ThemePreference.SYSTEM)
|
||||||
|
val themePreferenceFlow: StateFlow<ThemePreference> = _themePreferenceFlow.asStateFlow()
|
||||||
|
|
||||||
private val gson = com.google.gson.Gson()
|
private val gson = com.google.gson.Gson()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,6 +70,7 @@ object AuthManager {
|
|||||||
)
|
)
|
||||||
|
|
||||||
_bottomNavItemsFlow.value = getBottomNavItems()
|
_bottomNavItemsFlow.value = getBottomNavItems()
|
||||||
|
_themePreferenceFlow.value = getThemePreference()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +210,7 @@ object AuthManager {
|
|||||||
|
|
||||||
fun setThemePreference(theme: ThemePreference) {
|
fun setThemePreference(theme: ThemePreference) {
|
||||||
requirePrefs().edit().putString(KEY_THEME_PREFERENCE, theme.name).apply()
|
requirePrefs().edit().putString(KEY_THEME_PREFERENCE, theme.name).apply()
|
||||||
|
_themePreferenceFlow.value = theme
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convenience: build the base URL from current host + port.
|
/** Convenience: build the base URL from current host + port.
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ class SettingsViewModel : ViewModel() {
|
|||||||
|
|
||||||
fun onThemeChange(theme: ThemePreference) {
|
fun onThemeChange(theme: ThemePreference) {
|
||||||
_uiState.update { it.copy(themePreference = theme, isSaved = false) }
|
_uiState.update { it.copy(themePreference = theme, isSaved = false) }
|
||||||
|
AuthManager.setThemePreference(theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onTypingEffectEnabledChange(enabled: Boolean) {
|
fun onTypingEffectEnabledChange(enabled: Boolean) {
|
||||||
|
|||||||
Reference in New Issue
Block a user