Skip to content

Commit

Permalink
Merge pull request #8713 from Ephemera42/follow-system-theme-on-pre-a…
Browse files Browse the repository at this point in the history
…pi-28-devices

Show the "Use system default" theme option on pre API 28 devices
  • Loading branch information
wmontwe authored Jan 8, 2025
2 parents d4aaac3 + cfc524e commit b864c00
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,6 @@
<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>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.fsck.k9.ui.settings.general

import android.os.Build
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.activity.result.contract.ActivityResultContracts.CreateDocument
import androidx.preference.ListPreference
import androidx.preference.Preference
import app.k9mail.feature.telemetry.api.TelemetryManager
import com.fsck.k9.ui.R
Expand All @@ -17,7 +15,6 @@ import com.google.android.material.snackbar.Snackbar
import com.takisoft.preferencex.PreferenceFragmentCompat
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
import com.fsck.k9.core.R as CoreR

class GeneralSettingsFragment : PreferenceFragmentCompat() {
private val viewModel: GeneralSettingsViewModel by viewModel()
Expand All @@ -40,7 +37,6 @@ class GeneralSettingsFragment : PreferenceFragmentCompat() {
setHasOptionsMenu(true)
setPreferencesFromResource(R.xml.general_settings, rootKey)

initializeTheme()
initializeDataCollection()

viewModel.uiState.observe(this) { uiState ->
Expand Down Expand Up @@ -76,15 +72,6 @@ class GeneralSettingsFragment : PreferenceFragmentCompat() {
return super.onOptionsItemSelected(item)
}

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

private fun initializeDataCollection() {
if (!telemetryManager.isTelemetryFeatureIncluded()) {
findPreference<Preference>(PREFERENCE_DATA_COLLECTION)?.remove()
Expand Down Expand Up @@ -128,7 +115,6 @@ class GeneralSettingsFragment : PreferenceFragmentCompat() {
}

companion object {
private const val PREFERENCE_THEME = "theme"
private const val PREFERENCE_SCREEN_DEBUGGING = "debug_preferences"
private const val PREFERENCE_DATA_COLLECTION = "data_collection"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app.k9mail.legacy.ui.theme

import android.content.Context
import android.content.res.Configuration
import android.os.Build
import androidx.annotation.StyleRes
import androidx.appcompat.app.AppCompatDelegate
import app.k9mail.core.ui.theme.api.Theme
Expand Down Expand Up @@ -34,11 +33,7 @@ class ThemeManager(
get() = when (generalSettings.appTheme) {
AppTheme.LIGHT -> Theme.LIGHT
AppTheme.DARK -> Theme.DARK
AppTheme.FOLLOW_SYSTEM -> if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
Theme.LIGHT
} else {
getSystemTheme()
}
AppTheme.FOLLOW_SYSTEM -> getSystemTheme()
}

override val messageViewTheme: Theme
Expand Down Expand Up @@ -78,13 +73,7 @@ class ThemeManager(
val defaultNightMode = when (appTheme) {
AppTheme.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
AppTheme.DARK -> AppCompatDelegate.MODE_NIGHT_YES
AppTheme.FOLLOW_SYSTEM -> {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
AppCompatDelegate.MODE_NIGHT_NO
} else {
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
}
AppTheme.FOLLOW_SYSTEM -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
AppCompatDelegate.setDefaultNightMode(defaultNightMode)
}
Expand Down

0 comments on commit b864c00

Please sign in to comment.