Add labs setting for following system dark mode < Android 10
Fixes https://github.com/SpiritCroc/SchildiChat-android/issues/19. Change-Id: I4fec536d3b491ef31c4ed51325a8300a5134e96c
This commit is contained in:
parent
96aa885819
commit
5e721d55f9
|
@ -16,8 +16,11 @@
|
|||
|
||||
package im.vector.app.features.settings
|
||||
|
||||
import androidx.preference.Preference
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.extensions.restart
|
||||
import im.vector.app.core.preference.VectorSwitchPreference
|
||||
import im.vector.app.features.themes.ThemeUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
class VectorSettingsLabsFragment @Inject constructor(
|
||||
|
@ -35,5 +38,25 @@ class VectorSettingsLabsFragment @Inject constructor(
|
|||
it.parent?.removePreference(it)
|
||||
}
|
||||
}
|
||||
|
||||
val systemDarkThemePreTenPref = findPreference<VectorSwitchPreference>(ThemeUtils.SYSTEM_DARK_THEME_PRE_TEN)
|
||||
systemDarkThemePreTenPref?.let {
|
||||
if (ThemeUtils.darkThemeDefinitivelyPossible()) {
|
||||
it.parent?.removePreference(it)
|
||||
}
|
||||
}
|
||||
/*
|
||||
systemDarkThemePreTenPref?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
if (newValue is Boolean) {
|
||||
if (ThemeUtils.shouldUseDarkTheme(requireContext())) {
|
||||
// Restart the Activity | TODO: we need to do this AFTER the value is persisted...
|
||||
activity?.restart()
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ class VectorSettingsPreferencesFragment @Inject constructor(
|
|||
false
|
||||
}
|
||||
}
|
||||
if (ThemeUtils.darkThemePossible()) {
|
||||
if (ThemeUtils.darkThemePossible(requireContext())) {
|
||||
lightThemePref.title = getString(R.string.settings_light_theme)
|
||||
darkThemePref.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
if (newValue is String) {
|
||||
|
|
|
@ -39,6 +39,7 @@ object ThemeUtils {
|
|||
// preference key
|
||||
const val APPLICATION_THEME_KEY = "APPLICATION_THEME_KEY"
|
||||
const val APPLICATION_DARK_THEME_KEY = "APPLICATION_DARK_THEME_KEY"
|
||||
const val SYSTEM_DARK_THEME_PRE_TEN = "SYSTEM_DARK_THEME_PRE_TEN"
|
||||
|
||||
// the theme possible values
|
||||
private const val THEME_DARK_VALUE = "dark"
|
||||
|
@ -63,13 +64,18 @@ object ThemeUtils {
|
|||
/**
|
||||
* @return Whether a system-wide dark mode is available on this device
|
||||
*/
|
||||
fun darkThemePossible(): Boolean {
|
||||
fun darkThemePossible(context: Context): Boolean {
|
||||
// On Lineage, available since 15.1: https://review.lineageos.org/c/LineageOS/android_frameworks_base/+/209022
|
||||
return darkThemeDefinitivelyPossible() || DefaultSharedPreferences.getInstance(context).getBoolean(SYSTEM_DARK_THEME_PRE_TEN, false)
|
||||
}
|
||||
|
||||
fun darkThemeDefinitivelyPossible(): Boolean {
|
||||
// Available since Android 10: https://developer.android.com/guide/topics/ui/look-and-feel/darktheme
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
||||
}
|
||||
|
||||
fun shouldUseDarkTheme(context: Context): Boolean {
|
||||
if (!darkThemePossible()) {
|
||||
if (!darkThemePossible(context)) {
|
||||
return false
|
||||
}
|
||||
val currentNightMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
<string name="settings_light_theme">Helles Design</string>
|
||||
<string name="settings_dark_theme">Dunkles Design</string>
|
||||
<string name="settings_system_dark_theme_pre_ten">Folge dem Systemdesign</string>
|
||||
<string name="settings_system_dark_theme_pre_ten_summary">Erlaube die separate Konfiguration eines hellen und dunklen Anwendungsdesigns. Deine aktuelle Android-Version unterstützt den Wechsel womöglich nicht!</string>
|
||||
<string name="sc_light_theme">SC Hell</string>
|
||||
<string name="sc_theme">SC Schwarz</string>
|
||||
<string name="sc_dark_theme">SC Dunkel</string>
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
<string name="settings_light_theme">Light theme</string>
|
||||
<string name="settings_dark_theme">Dark theme</string>
|
||||
<string name="settings_system_dark_theme_pre_ten">Follow system dark theme</string>
|
||||
<string name="settings_system_dark_theme_pre_ten_summary">Provide separate theme settings for light and dark themes. Your current Android version might not support switching light and dark themes!</string>
|
||||
<string name="sc_light_theme">SC Light</string>
|
||||
<string name="sc_theme">SC Black</string>
|
||||
<string name="sc_dark_theme">SC Dark</string>
|
||||
|
|
|
@ -34,6 +34,12 @@
|
|||
<!--android:summary="@string/settings_labs_enable_send_voice_summary"-->
|
||||
<!--android:title="@string/settings_labs_enable_send_voice" />-->
|
||||
|
||||
<im.vector.app.core.preference.VectorSwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="SYSTEM_DARK_THEME_PRE_TEN"
|
||||
android:title="@string/settings_system_dark_theme_pre_ten"
|
||||
android:summary="@string/settings_system_dark_theme_pre_ten_summary" />
|
||||
|
||||
<im.vector.app.core.preference.VectorSwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY"
|
||||
|
|
Loading…
Reference in New Issue