mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-24 10:25:51 +03:00
Allow toggling theme with Android night theme
This commit is contained in:
parent
bce7845f9b
commit
32d8be34c8
6 changed files with 36 additions and 3 deletions
|
@ -65,12 +65,14 @@ class VectorConfiguration @Inject constructor(private val context: Context) {
|
|||
*
|
||||
* @param theme the new theme
|
||||
*/
|
||||
/*
|
||||
fun updateApplicationTheme(theme: String) {
|
||||
ThemeUtils.setApplicationTheme(context, theme)
|
||||
updateApplicationSettings(VectorLocale.applicationLocale,
|
||||
FontScale.getFontScalePrefValue(context),
|
||||
theme)
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Init the configuration from the saved one
|
||||
|
|
|
@ -55,7 +55,22 @@ class VectorSettingsPreferencesFragment @Inject constructor(
|
|||
findPreference<VectorListPreference>(ThemeUtils.APPLICATION_THEME_KEY)!!
|
||||
.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
if (newValue is String) {
|
||||
vectorConfiguration.updateApplicationTheme(newValue)
|
||||
//vectorConfiguration.updateApplicationTheme(newValue)
|
||||
// Restart the Activity
|
||||
activity?.let {
|
||||
// Note: recreate does not apply the color correctly
|
||||
it.startActivity(it.intent)
|
||||
it.finish()
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
findPreference<VectorListPreference>(ThemeUtils.APPLICATION_DARK_THEME_KEY)!!
|
||||
.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
if (newValue is String) {
|
||||
//vectorConfiguration.updateApplicationTheme(newValue)
|
||||
// Restart the Activity
|
||||
activity?.let {
|
||||
// Note: recreate does not apply the color correctly
|
||||
|
|
|
@ -18,6 +18,7 @@ package im.vector.riotx.features.themes
|
|||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.TypedValue
|
||||
import android.view.Menu
|
||||
|
@ -35,6 +36,7 @@ import timber.log.Timber
|
|||
object ThemeUtils {
|
||||
// preference key
|
||||
const val APPLICATION_THEME_KEY = "APPLICATION_THEME_KEY"
|
||||
const val APPLICATION_DARK_THEME_KEY = "APPLICATION_DARK_THEME_KEY"
|
||||
|
||||
// the theme possible values
|
||||
private const val THEME_DARK_VALUE = "dark"
|
||||
|
@ -57,8 +59,11 @@ object ThemeUtils {
|
|||
* @return the selected application theme
|
||||
*/
|
||||
fun getApplicationTheme(context: Context): String {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString(APPLICATION_THEME_KEY, THEME_LIGHT_VALUE)!!
|
||||
val currentNightMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||
return when (currentNightMode) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> PreferenceManager.getDefaultSharedPreferences(context).getString(APPLICATION_DARK_THEME_KEY, THEME_DARK_VALUE)!!
|
||||
else -> PreferenceManager.getDefaultSharedPreferences(context).getString(APPLICATION_THEME_KEY, THEME_LIGHT_VALUE)!!
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
<string name="redacted_stub_text">(Gelöschte Nachricht)</string>
|
||||
|
||||
<string name="settings_dark_theme">Nacht-Design</string>
|
||||
<string name="sc_theme">SC Schwarz</string>
|
||||
<string name="sc_dark_theme">SC Dunkel</string>
|
||||
<string name="sc_colored_theme">SC Schwarz, bunte Blasen</string>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
<string name="redacted_stub_text">(Deleted message)</string>
|
||||
|
||||
<string name="settings_dark_theme">Night Theme</string>
|
||||
<string name="sc_theme">SC Black</string>
|
||||
<string name="sc_dark_theme">SC Dark</string>
|
||||
<string name="sc_colored_theme">SC Black, colored bubbles</string>
|
||||
|
|
|
@ -21,6 +21,15 @@
|
|||
android:title="@string/settings_theme"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<im.vector.riotx.core.preference.VectorListPreference
|
||||
android:defaultValue="dark"
|
||||
android:entries="@array/theme_entries"
|
||||
android:entryValues="@array/theme_values"
|
||||
android:key="APPLICATION_DARK_THEME_KEY"
|
||||
android:summary="%s"
|
||||
android:title="@string/settings_dark_theme"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<im.vector.riotx.core.preference.VectorListPreference
|
||||
android:defaultValue="start"
|
||||
android:entries="@array/bubble_style_entries"
|
||||
|
|
Loading…
Reference in a new issue