Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d0c6987 authored by cketti's avatar cketti
Browse files

Switch to "use system default" theme option as default

On pre-API 28 Android versions hide the the "use system default" option
in settings. But we use the value AppTheme.FOLLOW_SYSTEM when the light
theme is selected. This way users who selected the light theme (or never
changed the setting at all) will get the "use system default" behavior
when they upgrade to Android 9+.
parent 0bf59cf6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ object K9 : KoinComponent {
    var k9Language = ""

    @JvmStatic
    var appTheme = AppTheme.LIGHT
    var appTheme = AppTheme.FOLLOW_SYSTEM

    var messageViewTheme = SubTheme.USE_GLOBAL
    var messageComposeTheme = SubTheme.USE_GLOBAL
@@ -430,7 +430,7 @@ object K9 : KoinComponent {

        k9Language = storage.getString("language", "")

        appTheme = storage.getEnum("theme", AppTheme.LIGHT)
        appTheme = storage.getEnum("theme", AppTheme.FOLLOW_SYSTEM)

        messageViewTheme = storage.getEnum("messageViewTheme", SubTheme.USE_GLOBAL)
        messageComposeTheme = storage.getEnum("messageComposeTheme", SubTheme.USE_GLOBAL)
+5 −0
Original line number Diff line number Diff line
@@ -132,6 +132,11 @@
        <item>ja</item>
    </string-array>

    <string-array name="theme_values_legacy" translatable="false">
        <item>follow_system</item>
        <item>dark</item>
    </string-array>

    <string-array name="theme_values" translatable="false">
        <item>light</item>
        <item>dark</item>
+8 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package com.fsck.k9.ui

import android.content.Context
import android.content.res.Configuration
import android.os.Build
import androidx.annotation.StyleRes
import androidx.appcompat.app.AppCompatDelegate
import com.fsck.k9.K9
@@ -51,7 +52,13 @@ class ThemeManager(private val context: Context) {
        val defaultNightMode = when (K9.appTheme) {
            AppTheme.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
            AppTheme.DARK -> AppCompatDelegate.MODE_NIGHT_YES
            AppTheme.FOLLOW_SYSTEM -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
            AppTheme.FOLLOW_SYSTEM -> {
                if (Build.VERSION.SDK_INT < 28) {
                    AppCompatDelegate.MODE_NIGHT_NO
                } else {
                    AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
                }
            }
        }
        AppCompatDelegate.setDefaultNightMode(defaultNightMode)
    }
+14 −2
Original line number Diff line number Diff line
package com.fsck.k9.ui.settings.general

import android.os.Build
import android.os.Bundle
import androidx.preference.ListPreference
import com.fsck.k9.ui.R
import com.fsck.k9.notification.NotificationController
import com.fsck.k9.ui.settings.remove
@@ -17,6 +19,7 @@ class GeneralSettingsFragment : PreferenceFragmentCompat() {

        setPreferencesFromResource(R.xml.general_settings, rootKey)

        initializeTheme()
        initializeStartInUnifiedInbox()
        initializeLockScreenNotificationVisibility()
    }
@@ -27,6 +30,15 @@ class GeneralSettingsFragment : PreferenceFragmentCompat() {
        dataStore.activity = activity
    }

    private fun initializeTheme() {
        (findPreference(PREFERENCE_THEME) as? ListPreference)?.apply {
            if (Build.VERSION.SDK_INT < 28) {
                setEntries(R.array.theme_entries_legacy)
                setEntryValues(R.array.theme_values_legacy)
            }
        }
    }

    private fun initializeStartInUnifiedInbox() {
        findPreference(PREFERENCE_START_IN_UNIFIED_INBOX)?.apply {
            if (hideSpecialAccounts()) {
@@ -46,11 +58,11 @@ class GeneralSettingsFragment : PreferenceFragmentCompat() {


    companion object {
        private const val PREFERENCE_THEME = "theme"
        private const val PREFERENCE_START_IN_UNIFIED_INBOX = "start_integrated_inbox"
        private const val PREFERENCE_HIDE_SPECIAL_ACCOUNTS = "hide_special_accounts"
        private const val PREFERENCE_LOCK_SCREEN_NOTIFICATION_VISIBILITY = "lock_screen_notification_visibility"

        fun create(rootKey: String? = null) = GeneralSettingsFragment().withArguments(
                PreferenceFragmentCompat.ARG_PREFERENCE_ROOT to rootKey)
        fun create(rootKey: String? = null) = GeneralSettingsFragment().withArguments(ARG_PREFERENCE_ROOT to rootKey)
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -84,6 +84,11 @@
        <item>日本語</item>
    </string-array>

    <string-array name="theme_entries_legacy">
        <item>@string/setting_theme_light</item>
        <item>@string/setting_theme_dark</item>
    </string-array>

    <string-array name="theme_entries">
        <item>@string/setting_theme_light</item>
        <item>@string/setting_theme_dark</item>