From bc463f3c64ab04ae766aa2f161cce8d5f0e4b9f3 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 29 Mar 2020 20:03:50 +0530 Subject: 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 --- .../main/java/com/zeapo/pwdstore/Application.kt | 33 +++++++++++++++++++++- app/src/main/res/layout/activity_git_clone.xml | 10 ------- app/src/main/res/layout/activity_git_config.xml | 4 --- .../res/layout/activity_oreo_autofill_filter.xml | 1 - app/src/main/res/layout/encrypt_layout.xml | 6 ---- .../res/layout/folder_creation_dialog_fragment.xml | 4 +-- app/src/main/res/layout/fragment_autofill.xml | 3 +- app/src/main/res/layout/fragment_ssh_keygen.xml | 8 ++---- app/src/main/res/values-v29/arrays.xml | 13 +++++++++ app/src/main/res/values-v29/prefs.xml | 4 +++ app/src/main/res/values/arrays.xml | 10 +++++++ app/src/main/res/values/colors.xml | 7 ++++- app/src/main/res/values/prefs.xml | 4 +++ app/src/main/res/values/strings.xml | 5 ++++ app/src/main/res/values/styles.xml | 13 +++++++-- app/src/main/res/xml/preference.xml | 7 +++++ 16 files changed, 95 insertions(+), 37 deletions(-) create mode 100644 app/src/main/res/values-v29/arrays.xml create mode 100644 app/src/main/res/values-v29/prefs.xml create mode 100644 app/src/main/res/values/prefs.xml (limited to 'app/src') 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 + }) } } diff --git a/app/src/main/res/layout/activity_git_clone.xml b/app/src/main/res/layout/activity_git_clone.xml index 2969819e..05d9a557 100644 --- a/app/src/main/res/layout/activity_git_clone.xml +++ b/app/src/main/res/layout/activity_git_clone.xml @@ -37,13 +37,11 @@ app:layout_constraintStart_toEndOf="@id/label_server_protocol" /> @@ -73,13 +69,11 @@ @@ -113,14 +105,12 @@ diff --git a/app/src/main/res/layout/activity_git_config.xml b/app/src/main/res/layout/activity_git_config.xml index bb2eac8b..a576ec46 100644 --- a/app/src/main/res/layout/activity_git_config.xml +++ b/app/src/main/res/layout/activity_git_config.xml @@ -11,12 +11,10 @@ @@ -30,13 +28,11 @@ diff --git a/app/src/main/res/layout/activity_oreo_autofill_filter.xml b/app/src/main/res/layout/activity_oreo_autofill_filter.xml index 17eb0e29..fb745afc 100644 --- a/app/src/main/res/layout/activity_oreo_autofill_filter.xml +++ b/app/src/main/res/layout/activity_oreo_autofill_filter.xml @@ -22,7 +22,6 @@ diff --git a/app/src/main/res/layout/folder_creation_dialog_fragment.xml b/app/src/main/res/layout/folder_creation_dialog_fragment.xml index dbaf97b3..375b4a30 100644 --- a/app/src/main/res/layout/folder_creation_dialog_fragment.xml +++ b/app/src/main/res/layout/folder_creation_dialog_fragment.xml @@ -11,9 +11,7 @@ style="@style/TextInputLayoutBase" android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="@string/crypto_name_hint" - app:hintTextColor="@color/color_control_normal" - app:hintEnabled="true"> + android:hint="@string/crypto_name_hint"> + android:hint="URL"> + android:hint="@string/ssh_keygen_passphrase"> + android:hint="@string/ssh_keygen_comment"> + + + @string/theme_light + @string/theme_dark + @string/theme_follow_system + + + light + dark + follow_system + + diff --git a/app/src/main/res/values-v29/prefs.xml b/app/src/main/res/values-v29/prefs.xml new file mode 100644 index 00000000..a007423f --- /dev/null +++ b/app/src/main/res/values-v29/prefs.xml @@ -0,0 +1,4 @@ + + + follow_system + diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 37b55432..559a520c 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -59,5 +59,15 @@ file directory + + @string/theme_light + @string/theme_dark + @string/theme_battery_saver + + + light + dark + battery_saver + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index f8fa1170..13bc049d 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,5 +1,5 @@ - + #607d8b #8eacbb @@ -19,4 +19,9 @@ #668eacbb #000000 @color/primary_dark_color + + + + @color/secondary_color + diff --git a/app/src/main/res/values/prefs.xml b/app/src/main/res/values/prefs.xml new file mode 100644 index 00000000..ae01866a --- /dev/null +++ b/app/src/main/res/values/prefs.xml @@ -0,0 +1,4 @@ + + + battery_saver + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ba491c87..ff9a2ea8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -334,4 +334,9 @@ Password Generator Tap here to clear clipboard Clone a git repository to sync changes + App theme + Light + Dark + Set by Battery Saver + System default diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index bed9a13e..090b56b9 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -20,6 +20,7 @@ @style/AppTheme.Dialog @style/AppTheme.Dialog @style/ThemeOverlay.MaterialComponents.ActionBar + @style/TextInputLayoutBase - + +