From 87d1ef2bced96b65f6add7c82b085affb9e39370 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Fri, 11 Nov 2022 20:51:49 +0100 Subject: [PATCH] Fixed theme reload issues. --- .../readerforselfossv2/android/LoginActivity.kt | 9 ++++++++- .../apps/readerforselfossv2/android/MyApp.kt | 17 +---------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt index 376ec0e..267043a 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt @@ -2,6 +2,7 @@ package bou.amine.apps.readerforselfossv2.android import android.animation.Animator import android.animation.AnimatorListenerAdapter +import android.annotation.SuppressLint import android.content.Intent import android.os.Bundle import android.text.TextUtils @@ -38,7 +39,8 @@ class LoginActivity : AppCompatActivity(), DIAware { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) + + handleTheme() binding = ActivityLoginBinding.inflate(layoutInflater) val view = binding.root @@ -56,6 +58,11 @@ class LoginActivity : AppCompatActivity(), DIAware { handleActions() } + @SuppressLint("WrongConstant") // Constant is fetched from the settings + private fun handleTheme() { + AppCompatDelegate.setDefaultNightMode(appSettingsService.getCurrentTheme()) + } + private fun handleActions() { binding.passwordView.setOnEditorActionListener( diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt index a8db063..9795104 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt @@ -51,7 +51,6 @@ class MyApp : MultiDexApplication(), DIAware { private val viewModel: AppViewModel by instance() private val connectivityStatus: ConnectivityStatus by instance() private val driverFactory: DriverFactory by instance() - private val appSettingsService : AppSettingsService by instance() // TODO: handle with the "previous" way private val isConnectionAvailable: MutableStateFlow = MutableStateFlow(true) @@ -126,29 +125,15 @@ class MyApp : MultiDexApplication(), DIAware { val oldHandler = Thread.getDefaultUncaughtExceptionHandler() Thread.setDefaultUncaughtExceptionHandler { thread, e -> - if (e is java.lang.NoClassDefFoundError && e.stackTrace.asList().any { + if (e is NoClassDefFoundError && e.stackTrace.asList().any { it.toString().contains("android.view.ViewDebug") }) { - Unit } else { oldHandler.uncaughtException(thread, e) } } } - 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) { -- 2.34.1