summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2020-03-29 20:03:50 +0530
committerGitHub <noreply@github.com>2020-03-29 20:03:50 +0530
commitbc463f3c64ab04ae766aa2f161cce8d5f0e4b9f3 (patch)
treec509e028fac85fcee6804402e32c277084f63afa /app/src/main/java
parent6e84ca1f3c19fc0f67f021ad43c40d7b99416d55 (diff)
Significantly improve app theming (#679)
* Update CHANGELOG * Use outlined box style in folder creation dialog * Add user-facing choice for app theme Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/Application.kt33
1 files changed, 32 insertions, 1 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/Application.kt b/app/src/main/java/com/zeapo/pwdstore/Application.kt
index d6c618b1..b476dd45 100644
--- a/app/src/main/java/com/zeapo/pwdstore/Application.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/Application.kt
@@ -4,11 +4,19 @@
*/
package com.zeapo.pwdstore
+import android.content.SharedPreferences
+import androidx.appcompat.app.AppCompatDelegate
+import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
+import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
+import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
+import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
+import androidx.preference.PreferenceManager
import com.haroldadmin.whatthestack.WhatTheStack
import timber.log.Timber
@Suppress("Unused")
-class Application : android.app.Application() {
+class Application : android.app.Application(), SharedPreferences.OnSharedPreferenceChangeListener {
+ private var prefs: SharedPreferences? = null
override fun onCreate() {
super.onCreate()
@@ -16,5 +24,28 @@ class Application : android.app.Application() {
if (BuildConfig.ENABLE_DEBUG_FEATURES) {
WhatTheStack(this).init()
}
+ prefs = PreferenceManager.getDefaultSharedPreferences(this)
+ prefs?.registerOnSharedPreferenceChangeListener(this)
+ setNightMode()
+ }
+
+ override fun onTerminate() {
+ prefs?.unregisterOnSharedPreferenceChangeListener(this)
+ super.onTerminate()
+ }
+
+ override fun onSharedPreferenceChanged(prefs: SharedPreferences, key: String) {
+ if (key == "app_theme") {
+ setNightMode()
+ }
+ }
+
+ private fun setNightMode() {
+ AppCompatDelegate.setDefaultNightMode(when (prefs?.getString("app_theme", getString(R.string.app_theme_def))) {
+ "light" -> MODE_NIGHT_NO
+ "dark" -> MODE_NIGHT_YES
+ "follow_system" -> MODE_NIGHT_FOLLOW_SYSTEM
+ else -> MODE_NIGHT_AUTO_BATTERY
+ })
}
}