From 7d199a6b07a53cd4e43a7ada0158239e68eba0ae Mon Sep 17 00:00:00 2001 From: ialokim Date: Thu, 11 Jan 2024 23:57:38 +0100 Subject: [PATCH] fix some theming-related issues fixes #913, #909 --- .../grobox/transportr/settings/SettingsFragment.kt | 4 ++-- .../de/grobox/transportr/settings/SettingsManager.kt | 12 ++++++++++-- app/src/main/res/xml/preferences.xml | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/de/grobox/transportr/settings/SettingsFragment.kt b/app/src/main/java/de/grobox/transportr/settings/SettingsFragment.kt index f72f78c73..57a0cc0ff 100644 --- a/app/src/main/java/de/grobox/transportr/settings/SettingsFragment.kt +++ b/app/src/main/java/de/grobox/transportr/settings/SettingsFragment.kt @@ -60,9 +60,9 @@ class SettingsFragment : PreferenceFragmentCompat() { // Fill in current transport network if available networkPref = findPreference("pref_key_network")!! - manager.transportNetwork.observe(this, Observer { + manager.transportNetwork.observe(this) { onTransportNetworkChanged(it) - }) + } networkPref.setOnPreferenceClickListener { if (activity == null || view == null) return@setOnPreferenceClickListener false diff --git a/app/src/main/java/de/grobox/transportr/settings/SettingsManager.kt b/app/src/main/java/de/grobox/transportr/settings/SettingsManager.kt index c1f9cc628..521a509d6 100644 --- a/app/src/main/java/de/grobox/transportr/settings/SettingsManager.kt +++ b/app/src/main/java/de/grobox/transportr/settings/SettingsManager.kt @@ -24,8 +24,10 @@ import android.content.SharedPreferences import android.content.res.Configuration import android.content.res.Resources import android.os.Build +import android.os.PowerManager import android.preference.PreferenceManager import androidx.appcompat.app.AppCompatDelegate.* +import androidx.core.content.ContextCompat import de.grobox.transportr.R import de.schildbach.pte.NetworkId import de.schildbach.pte.NetworkProvider.Optimize @@ -67,8 +69,14 @@ class SettingsManager @Inject constructor(private val context: Context) { val isDarkTheme: Boolean get() { - return (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) or - (theme == MODE_NIGHT_YES) + return when(theme) { + MODE_NIGHT_YES -> true + MODE_NIGHT_NO -> false + else -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) + context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES + else + ContextCompat.getSystemService(context, PowerManager::class.java)?.isPowerSaveMode ?: false + } } val walkSpeed: WalkSpeed diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 8dfa735f1..172952f0e 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -49,7 +49,7 @@ app:iconSpaceReserved="false">