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>
This commit is contained in:
Harsh Shandilya 2020-03-29 20:03:50 +05:30 committed by GitHub
parent 6e84ca1f3c
commit bc463f3c64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 98 additions and 37 deletions

View file

@ -6,6 +6,9 @@ All notable changes to this project will be documented in this file.
### Added ### Added
- Oreo Autofill support - Oreo Autofill support
### Fixed
- Text input box theming
## [1.6.0] - 2020-03-20 ## [1.6.0] - 2020-03-20
### Added ### Added

View file

@ -4,11 +4,19 @@
*/ */
package com.zeapo.pwdstore 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 com.haroldadmin.whatthestack.WhatTheStack
import timber.log.Timber import timber.log.Timber
@Suppress("Unused") @Suppress("Unused")
class Application : android.app.Application() { class Application : android.app.Application(), SharedPreferences.OnSharedPreferenceChangeListener {
private var prefs: SharedPreferences? = null
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
@ -16,5 +24,28 @@ class Application : android.app.Application() {
if (BuildConfig.ENABLE_DEBUG_FEATURES) { if (BuildConfig.ENABLE_DEBUG_FEATURES) {
WhatTheStack(this).init() 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
})
} }
} }

View file

@ -37,13 +37,11 @@
app:layout_constraintStart_toEndOf="@id/label_server_protocol" /> app:layout_constraintStart_toEndOf="@id/label_server_protocol" />
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutBase"
android:id="@+id/server_user_layout" android:id="@+id/server_user_layout"
android:hint="@string/server_user" android:hint="@string/server_user"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp" android:layout_margin="8dp"
app:hintEnabled="true"
app:layout_constraintTop_toBottomOf="@id/label_server_protocol"> app:layout_constraintTop_toBottomOf="@id/label_server_protocol">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/server_user" android:id="@+id/server_user"
@ -53,13 +51,11 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutBase"
android:id="@+id/label_server_url" android:id="@+id/label_server_url"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp" android:layout_margin="8dp"
android:hint="@string/server_url" android:hint="@string/server_url"
app:hintEnabled="true"
app:layout_constraintTop_toBottomOf="@id/server_user_layout" app:layout_constraintTop_toBottomOf="@id/server_user_layout"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/label_server_port"> app:layout_constraintEnd_toStartOf="@id/label_server_port">
@ -73,13 +69,11 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutBase"
android:id="@+id/label_server_port" android:id="@+id/label_server_port"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp" android:layout_margin="8dp"
android:hint="@string/server_port_hint" android:hint="@string/server_port_hint"
app:hintEnabled="true"
app:layout_constraintStart_toEndOf="@id/label_server_url" app:layout_constraintStart_toEndOf="@id/label_server_url"
app:layout_constraintTop_toBottomOf="@id/server_user_layout" app:layout_constraintTop_toBottomOf="@id/server_user_layout"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
@ -94,13 +88,11 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutBase"
android:id="@+id/label_server_path" android:id="@+id/label_server_path"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp" android:layout_margin="8dp"
android:hint="@string/server_path" android:hint="@string/server_path"
app:hintEnabled="true"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/label_server_url"> app:layout_constraintTop_toBottomOf="@id/label_server_url">
@ -113,14 +105,12 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutBase"
android:id="@+id/label_clone_uri" android:id="@+id/label_clone_uri"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/repository_uri" android:hint="@string/repository_uri"
android:editable="false" android:editable="false"
android:layout_margin="8dp" android:layout_margin="8dp"
app:hintEnabled="true"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/label_server_path"> app:layout_constraintTop_toBottomOf="@id/label_server_path">

View file

@ -11,12 +11,10 @@
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/username_input_layout" android:id="@+id/username_input_layout"
style="@style/TextInputLayoutBase"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp" android:layout_margin="8dp"
android:hint="@string/git_user_name_hint" android:hint="@string/git_user_name_hint"
app:hintEnabled="true"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="64dp"> tools:layout_editor_absoluteY="64dp">
@ -30,13 +28,11 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutBase"
android:id="@+id/email_input_layout" android:id="@+id/email_input_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp" android:layout_margin="8dp"
android:hint="@string/git_user_email" android:hint="@string/git_user_email"
app:hintEnabled="true"
app:layout_constraintTop_toBottomOf="@id/username_input_layout" app:layout_constraintTop_toBottomOf="@id/username_input_layout"
app:layout_constraintStart_toStartOf="parent"> app:layout_constraintStart_toStartOf="parent">

View file

@ -22,7 +22,6 @@
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/searchLayout" android:id="@+id/searchLayout"
style="@style/TextInputLayoutBase"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin" android:layout_marginStart="@dimen/activity_horizontal_margin"

View file

@ -22,14 +22,12 @@
tools:text="CATEGORY HERE" /> tools:text="CATEGORY HERE" />
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutBase"
android:id="@+id/name_input_layout" android:id="@+id/name_input_layout"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp" android:layout_margin="8dp"
android:hint="@string/crypto_name_hint" android:hint="@string/crypto_name_hint"
app:hintEnabled="true"
app:layout_constraintTop_toBottomOf="@id/crypto_password_category" app:layout_constraintTop_toBottomOf="@id/crypto_password_category"
app:layout_constraintStart_toStartOf="parent"> app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
@ -39,14 +37,12 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutBase"
android:id="@+id/password_input_layout" android:id="@+id/password_input_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp" android:layout_margin="8dp"
android:hint="@string/crypto_pass_label" android:hint="@string/crypto_pass_label"
app:endIconMode="password_toggle" app:endIconMode="password_toggle"
app:hintEnabled="true"
app:layout_constraintTop_toBottomOf="@id/name_input_layout" app:layout_constraintTop_toBottomOf="@id/name_input_layout"
app:layout_constraintStart_toStartOf="parent"> app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
@ -69,13 +65,11 @@
app:layout_constraintEnd_toEndOf="parent"/> app:layout_constraintEnd_toEndOf="parent"/>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutBase"
android:id="@+id/extra_input_layout" android:id="@+id/extra_input_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp" android:layout_margin="8dp"
android:hint="@string/crypto_extra_label" android:hint="@string/crypto_extra_label"
app:hintEnabled="true"
app:layout_constraintTop_toBottomOf="@id/generate_password" app:layout_constraintTop_toBottomOf="@id/generate_password"
app:layout_constraintStart_toStartOf="parent"> app:layout_constraintStart_toStartOf="parent">

View file

@ -11,9 +11,7 @@
style="@style/TextInputLayoutBase" style="@style/TextInputLayoutBase"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/crypto_name_hint" android:hint="@string/crypto_name_hint">
app:hintTextColor="@color/color_control_normal"
app:hintEnabled="true">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/folder_name_text" android:id="@+id/folder_name_text"

View file

@ -14,8 +14,7 @@
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="URL" android:hint="URL">
app:hintEnabled="true">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/webURL" android:id="@+id/webURL"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -24,12 +24,10 @@
android:spinnerMode="dropdown" /> android:spinnerMode="dropdown" />
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutBase"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:hint="@string/ssh_keygen_passphrase" android:hint="@string/ssh_keygen_passphrase">
app:hintEnabled="true">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/passphrase" android:id="@+id/passphrase"
@ -49,12 +47,10 @@
android:text="@string/ssh_keygen_show_passphrase" /> android:text="@string/ssh_keygen_show_passphrase" />
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutBase"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:hint="@string/ssh_keygen_comment" android:hint="@string/ssh_keygen_comment">
app:hintEnabled="true">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/comment" android:id="@+id/comment"

View file

@ -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>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_theme_def" translatable="false">follow_system</string>
</resources>

View file

@ -59,5 +59,15 @@
<item>file</item> <item>file</item>
<item>directory</item> <item>directory</item>
</string-array> </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> </resources>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base palette --> <!-- Base palette -->
<color name="primary_color">#607d8b</color> <color name="primary_color">#607d8b</color>
<color name="primary_light_color">#8eacbb</color> <color name="primary_light_color">#8eacbb</color>
@ -19,4 +19,9 @@
<color name="list_multiselect_background">#668eacbb</color> <color name="list_multiselect_background">#668eacbb</color>
<color name="navigation_bar_color">#000000</color> <color name="navigation_bar_color">#000000</color>
<color name="status_bar_color">@color/primary_dark_color</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> </resources>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_theme_def" translatable="false">battery_saver</string>
</resources>

View file

@ -334,4 +334,9 @@
<string name="password_generator_category_title">Password Generator</string> <string name="password_generator_category_title">Password Generator</string>
<string name="tap_clear_clipboard">Tap here to clear clipboard</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="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> </resources>

View file

@ -20,6 +20,7 @@
<item name="alertDialogTheme">@style/AppTheme.Dialog</item> <item name="alertDialogTheme">@style/AppTheme.Dialog</item>
<item name="materialAlertDialogTheme">@style/AppTheme.Dialog</item> <item name="materialAlertDialogTheme">@style/AppTheme.Dialog</item>
<item name="actionBarPopupTheme">@style/ThemeOverlay.MaterialComponents.ActionBar</item> <item name="actionBarPopupTheme">@style/ThemeOverlay.MaterialComponents.ActionBar</item>
<item name="textInputStyle">@style/TextInputLayoutBase</item>
</style> </style>
<style name="AppTheme.Dialog" parent="Theme.MaterialComponents.DayNight.Dialog.Alert"> <style name="AppTheme.Dialog" parent="Theme.MaterialComponents.DayNight.Dialog.Alert">
@ -32,9 +33,15 @@
<item name="background">@color/primary_color</item> <item name="background">@color/primary_color</item>
</style> </style>
<style name="TextInputLayoutBase" parent="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"> <style name="ThemeOverlay.AppTheme.TextInputEditText.OutlinedBox" parent="ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="boxStrokeColor">?attr/colorSecondary</item> <item name="colorControlActivated">@color/color_control_normal</item>
<item name="hintTextColor">?attr/colorOnPrimary</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>
<style name="DialogLikeTheme" parent="AppTheme"> <style name="DialogLikeTheme" parent="AppTheme">

View file

@ -102,6 +102,13 @@
</androidx.preference.PreferenceCategory> </androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory app:title="@string/pref_general_title"> <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 <androidx.preference.EditTextPreference
app:defaultValue="45" app:defaultValue="45"
app:dialogTitle="@string/pref_show_time_summary" app:dialogTitle="@string/pref_show_time_summary"