diff --git a/androidApp/src/main/AndroidManifest.xml b/androidApp/src/main/AndroidManifest.xml index 21addf9..d2b222e 100644 --- a/androidApp/src/main/AndroidManifest.xml +++ b/androidApp/src/main/AndroidManifest.xml @@ -15,7 +15,8 @@ android:supportsRtl="true" android:networkSecurityConfig="@xml/network_security_config" android:theme="@style/NoBar" - android:dataExtractionRules="@xml/data_extraction_rules"> + android:dataExtractionRules="@xml/data_extraction_rules" + android:configChanges="uiMode"> = MutableStateFlow(true) @@ -132,6 +136,19 @@ class MyApp : MultiDexApplication(), DIAware { } } + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + if (appSettingsService.getCurrentTheme() == MODE_NIGHT_FOLLOW_SYSTEM) { + var mode = when (newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK) { + Configuration.UI_MODE_NIGHT_YES -> MODE_NIGHT_YES + else -> MODE_NIGHT_NO + } + setDefaultNightMode(mode) + } + + + } + class AppLifeCycleObserver(val connectivityStatus: ConnectivityStatus, val repository: Repository) : DefaultLifecycleObserver { override fun onResume(owner: LifecycleOwner) { diff --git a/androidApp/src/main/res/values/mode_settings.xml b/androidApp/src/main/res/values/mode_settings.xml index ca41323..f377c76 100644 --- a/androidApp/src/main/res/values/mode_settings.xml +++ b/androidApp/src/main/res/values/mode_settings.xml @@ -9,7 +9,7 @@ 1 2 - 0 + -1 diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/AppSettingsService.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/AppSettingsService.kt index 3b96e2f..199dafb 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/AppSettingsService.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/AppSettingsService.kt @@ -35,6 +35,7 @@ class AppSettingsService { private var _fontSize: Int? = null private var _staticBar: Boolean? = null private var _font: String = "" + private var _theme: Int? = null init { @@ -318,6 +319,17 @@ class AppSettingsService { return _font } + private fun refreshCurrentTheme() { + _theme = settings.getString(CURRENT_THEME, "-1").toInt() + } + + fun getCurrentTheme(): Int { + if (_theme == null) { + refreshCurrentTheme() + } + return _theme ?: -1 + } + fun refreshApiSettings() { refreshPassword() refreshUsername() @@ -346,6 +358,7 @@ class AppSettingsService { refreshFontSize() refreshFont() refreshStaticBarEnabled() + refreshCurrentTheme() } fun refreshLoginInformation( @@ -444,5 +457,7 @@ class AppSettingsService { const val INFINITE_LOADING = "infinite_loading" const val ITEMS_CACHING = "items_caching" + + const val CURRENT_THEME = "currentMode" } } \ No newline at end of file