Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some theming-related issues #914

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class SettingsFragment : PreferenceFragmentCompat() {

// Fill in current transport network if available
networkPref = findPreference("pref_key_network")!!
manager.transportNetwork.observe(this, Observer<TransportNetwork> {
manager.transportNetwork.observe(this) {
onTransportNetworkChanged(it)
})
}

networkPref.setOnPreferenceClickListener {
if (activity == null || view == null) return@setOnPreferenceClickListener false
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/de/grobox/transportr/settings/SettingsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
app:iconSpaceReserved="false">

<ListPreference
android:defaultValue="@string/pref_theme_value_light"
android:defaultValue="@string/pref_theme_value_auto"
android:entries="@array/pref_theme_options"
android:entryValues="@array/pref_theme_values"
android:key="pref_key_theme"
Expand Down