diff options
author | Harsh Shandilya <msfjarvis@gmail.com> | 2020-03-29 20:03:50 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-29 20:03:50 +0530 |
commit | bc463f3c64ab04ae766aa2f161cce8d5f0e4b9f3 (patch) | |
tree | c509e028fac85fcee6804402e32c277084f63afa /app/src/main | |
parent | 6e84ca1f3c19fc0f67f021ad43c40d7b99416d55 (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')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/Application.kt | 33 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_git_clone.xml | 10 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_git_config.xml | 4 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_oreo_autofill_filter.xml | 1 | ||||
-rw-r--r-- | app/src/main/res/layout/encrypt_layout.xml | 6 | ||||
-rw-r--r-- | app/src/main/res/layout/folder_creation_dialog_fragment.xml | 4 | ||||
-rw-r--r-- | app/src/main/res/layout/fragment_autofill.xml | 3 | ||||
-rw-r--r-- | app/src/main/res/layout/fragment_ssh_keygen.xml | 8 | ||||
-rw-r--r-- | app/src/main/res/values-v29/arrays.xml | 13 | ||||
-rw-r--r-- | app/src/main/res/values-v29/prefs.xml | 4 | ||||
-rw-r--r-- | app/src/main/res/values/arrays.xml | 10 | ||||
-rw-r--r-- | app/src/main/res/values/colors.xml | 7 | ||||
-rw-r--r-- | app/src/main/res/values/prefs.xml | 4 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 5 | ||||
-rw-r--r-- | app/src/main/res/values/styles.xml | 13 | ||||
-rw-r--r-- | app/src/main/res/xml/preference.xml | 7 |
16 files changed, 95 insertions, 37 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 + }) } } 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" /> <com.google.android.material.textfield.TextInputLayout - style="@style/TextInputLayoutBase" android:id="@+id/server_user_layout" android:hint="@string/server_user" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp" - app:hintEnabled="true" app:layout_constraintTop_toBottomOf="@id/label_server_protocol"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/server_user" @@ -53,13 +51,11 @@ </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout - style="@style/TextInputLayoutBase" android:id="@+id/label_server_url" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="8dp" android:hint="@string/server_url" - app:hintEnabled="true" app:layout_constraintTop_toBottomOf="@id/server_user_layout" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toStartOf="@id/label_server_port"> @@ -73,13 +69,11 @@ </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout - style="@style/TextInputLayoutBase" android:id="@+id/label_server_port" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="8dp" android:hint="@string/server_port_hint" - app:hintEnabled="true" app:layout_constraintStart_toEndOf="@id/label_server_url" app:layout_constraintTop_toBottomOf="@id/server_user_layout" app:layout_constraintEnd_toEndOf="parent" @@ -94,13 +88,11 @@ </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout - style="@style/TextInputLayoutBase" android:id="@+id/label_server_path" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp" android:hint="@string/server_path" - app:hintEnabled="true" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/label_server_url"> @@ -113,14 +105,12 @@ </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout - style="@style/TextInputLayoutBase" android:id="@+id/label_clone_uri" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/repository_uri" android:editable="false" android:layout_margin="8dp" - app:hintEnabled="true" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/label_server_path"> 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 @@ <com.google.android.material.textfield.TextInputLayout android:id="@+id/username_input_layout" - style="@style/TextInputLayoutBase" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp" android:hint="@string/git_user_name_hint" - app:hintEnabled="true" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" tools:layout_editor_absoluteY="64dp"> @@ -30,13 +28,11 @@ </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout - style="@style/TextInputLayoutBase" android:id="@+id/email_input_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp" android:hint="@string/git_user_email" - app:hintEnabled="true" app:layout_constraintTop_toBottomOf="@id/username_input_layout" app:layout_constraintStart_toStartOf="parent"> 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 @@ <com.google.android.material.textfield.TextInputLayout android:id="@+id/searchLayout" - style="@style/TextInputLayoutBase" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="@dimen/activity_horizontal_margin" diff --git a/app/src/main/res/layout/encrypt_layout.xml b/app/src/main/res/layout/encrypt_layout.xml index e4d9464a..54b1c7c9 100644 --- a/app/src/main/res/layout/encrypt_layout.xml +++ b/app/src/main/res/layout/encrypt_layout.xml @@ -22,14 +22,12 @@ tools:text="CATEGORY HERE" /> <com.google.android.material.textfield.TextInputLayout - style="@style/TextInputLayoutBase" android:id="@+id/name_input_layout" android:layout_gravity="center_vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp" android:hint="@string/crypto_name_hint" - app:hintEnabled="true" app:layout_constraintTop_toBottomOf="@id/crypto_password_category" app:layout_constraintStart_toStartOf="parent"> <com.google.android.material.textfield.TextInputEditText @@ -39,14 +37,12 @@ </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout - style="@style/TextInputLayoutBase" android:id="@+id/password_input_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp" android:hint="@string/crypto_pass_label" app:endIconMode="password_toggle" - app:hintEnabled="true" app:layout_constraintTop_toBottomOf="@id/name_input_layout" app:layout_constraintStart_toStartOf="parent"> <com.google.android.material.textfield.TextInputEditText @@ -69,13 +65,11 @@ app:layout_constraintEnd_toEndOf="parent"/> <com.google.android.material.textfield.TextInputLayout - style="@style/TextInputLayoutBase" android:id="@+id/extra_input_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp" android:hint="@string/crypto_extra_label" - app:hintEnabled="true" app:layout_constraintTop_toBottomOf="@id/generate_password" app:layout_constraintStart_toStartOf="parent"> 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"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/folder_name_text" diff --git a/app/src/main/res/layout/fragment_autofill.xml b/app/src/main/res/layout/fragment_autofill.xml index e1a18696..29d0f517 100644 --- a/app/src/main/res/layout/fragment_autofill.xml +++ b/app/src/main/res/layout/fragment_autofill.xml @@ -14,8 +14,7 @@ <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="URL" - app:hintEnabled="true"> + android:hint="URL"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/webURL" android:layout_width="match_parent" diff --git a/app/src/main/res/layout/fragment_ssh_keygen.xml b/app/src/main/res/layout/fragment_ssh_keygen.xml index cee878fd..16c3f512 100644 --- a/app/src/main/res/layout/fragment_ssh_keygen.xml +++ b/app/src/main/res/layout/fragment_ssh_keygen.xml @@ -24,12 +24,10 @@ android:spinnerMode="dropdown" /> <com.google.android.material.textfield.TextInputLayout - style="@style/TextInputLayoutBase" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" - android:hint="@string/ssh_keygen_passphrase" - app:hintEnabled="true"> + android:hint="@string/ssh_keygen_passphrase"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/passphrase" @@ -49,12 +47,10 @@ android:text="@string/ssh_keygen_show_passphrase" /> <com.google.android.material.textfield.TextInputLayout - style="@style/TextInputLayoutBase" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" - android:hint="@string/ssh_keygen_comment" - app:hintEnabled="true"> + android:hint="@string/ssh_keygen_comment"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/comment" diff --git a/app/src/main/res/values-v29/arrays.xml b/app/src/main/res/values-v29/arrays.xml new file mode 100644 index 00000000..a90e645d --- /dev/null +++ b/app/src/main/res/values-v29/arrays.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string-array name="app_theme_options"> + <item>@string/theme_light</item> + <item>@string/theme_dark</item> + <item>@string/theme_follow_system</item> + </string-array> + <string-array name="app_theme_values"> + <item>light</item> + <item>dark</item> + <item>follow_system</item> + </string-array> +</resources> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="app_theme_def" translatable="false">follow_system</string> +</resources> 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 @@ <item>file</item> <item>directory</item> </string-array> + <string-array name="app_theme_options"> + <item>@string/theme_light</item> + <item>@string/theme_dark</item> + <item>@string/theme_battery_saver</item> + </string-array> + <string-array name="app_theme_values"> + <item>light</item> + <item>dark</item> + <item>battery_saver</item> + </string-array> </resources> 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 @@ <?xml version="1.0" encoding="utf-8"?> -<resources> +<resources xmlns:tools="http://schemas.android.com/tools"> <!-- Base palette --> <color name="primary_color">#607d8b</color> <color name="primary_light_color">#8eacbb</color> @@ -19,4 +19,9 @@ <color name="list_multiselect_background">#668eacbb</color> <color name="navigation_bar_color">#000000</color> <color name="status_bar_color">@color/primary_dark_color</color> + + <!-- Override TextInputEditText stroke color like a boss --> + <color name="mtrl_textinput_default_box_stroke_color" tools:override="true"> + @color/secondary_color + </color> </resources> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="app_theme_def" translatable="false">battery_saver</string> +</resources> 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 @@ <string name="password_generator_category_title">Password Generator</string> <string name="tap_clear_clipboard">Tap here to clear clipboard</string> <string name="clone_git_repo">Clone a git repository to sync changes</string> + <string name="theme_title">App theme</string> + <string name="theme_light">Light</string> + <string name="theme_dark">Dark</string> + <string name="theme_battery_saver">Set by Battery Saver</string> + <string name="theme_follow_system">System default</string> </resources> 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 @@ <item name="alertDialogTheme">@style/AppTheme.Dialog</item> <item name="materialAlertDialogTheme">@style/AppTheme.Dialog</item> <item name="actionBarPopupTheme">@style/ThemeOverlay.MaterialComponents.ActionBar</item> + <item name="textInputStyle">@style/TextInputLayoutBase</item> </style> <style name="AppTheme.Dialog" parent="Theme.MaterialComponents.DayNight.Dialog.Alert"> @@ -32,9 +33,15 @@ <item name="background">@color/primary_color</item> </style> - <style name="TextInputLayoutBase" parent="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"> - <item name="boxStrokeColor">?attr/colorSecondary</item> - <item name="hintTextColor">?attr/colorOnPrimary</item> + <style name="ThemeOverlay.AppTheme.TextInputEditText.OutlinedBox" parent="ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox"> + <item name="colorControlActivated">@color/color_control_normal</item> + </style> + + <style name="TextInputLayoutBase" parent="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"> + <item name="boxStrokeColor">@color/secondary_color</item> + <item name="hintTextColor">@color/color_control_normal</item> + <item name="hintEnabled">true</item> + <item name="materialThemeOverlay">@style/ThemeOverlay.AppTheme.TextInputEditText.OutlinedBox</item> </style> <style name="DialogLikeTheme" parent="AppTheme"> diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index b1c5e4d0..31c6de5a 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -102,6 +102,13 @@ </androidx.preference.PreferenceCategory> <androidx.preference.PreferenceCategory app:title="@string/pref_general_title"> + <ListPreference + android:defaultValue="@string/app_theme_def" + android:key="app_theme" + android:entries="@array/app_theme_options" + android:entryValues="@array/app_theme_values" + android:summary="%s" + android:title="@string/theme_title" /> <androidx.preference.EditTextPreference app:defaultValue="45" app:dialogTitle="@string/pref_show_time_summary" |