Switch SettingsActivity to use Material3 Switch (#2006)

This commit is contained in:
Harsh Shandilya 2022-07-16 03:25:42 +05:30 committed by GitHub
parent 0695f42e07
commit a15ff1b137
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 14 deletions

View file

@ -16,9 +16,9 @@ import app.passwordstore.util.auth.BiometricAuthenticator.Result
import app.passwordstore.util.extensions.sharedPrefs import app.passwordstore.util.extensions.sharedPrefs
import app.passwordstore.util.settings.PreferenceKeys import app.passwordstore.util.settings.PreferenceKeys
import de.Maxr1998.modernpreferences.PreferenceScreen import de.Maxr1998.modernpreferences.PreferenceScreen
import de.Maxr1998.modernpreferences.helpers.checkBox
import de.Maxr1998.modernpreferences.helpers.onClick import de.Maxr1998.modernpreferences.helpers.onClick
import de.Maxr1998.modernpreferences.helpers.singleChoice import de.Maxr1998.modernpreferences.helpers.singleChoice
import de.Maxr1998.modernpreferences.helpers.switch
import de.Maxr1998.modernpreferences.preferences.choice.SelectionItem import de.Maxr1998.modernpreferences.preferences.choice.SelectionItem
class GeneralSettings(private val activity: FragmentActivity) : SettingsProvider { class GeneralSettings(private val activity: FragmentActivity) : SettingsProvider {
@ -42,32 +42,32 @@ class GeneralSettings(private val activity: FragmentActivity) : SettingsProvider
titleRes = R.string.pref_sort_order_title titleRes = R.string.pref_sort_order_title
} }
checkBox(PreferenceKeys.DISABLE_SYNC_ACTION) { switch(PreferenceKeys.DISABLE_SYNC_ACTION) {
titleRes = R.string.pref_disable_sync_on_pull_title titleRes = R.string.pref_disable_sync_on_pull_title
summaryRes = R.string.pref_disable_sync_on_pull_summary summaryRes = R.string.pref_disable_sync_on_pull_summary
defaultValue = false defaultValue = false
} }
checkBox(PreferenceKeys.FILTER_RECURSIVELY) { switch(PreferenceKeys.FILTER_RECURSIVELY) {
titleRes = R.string.pref_recursive_filter_title titleRes = R.string.pref_recursive_filter_title
summaryRes = R.string.pref_recursive_filter_summary summaryRes = R.string.pref_recursive_filter_summary
defaultValue = true defaultValue = true
} }
checkBox(PreferenceKeys.SEARCH_ON_START) { switch(PreferenceKeys.SEARCH_ON_START) {
titleRes = R.string.pref_search_on_start_title titleRes = R.string.pref_search_on_start_title
summaryRes = R.string.pref_search_on_start_summary summaryRes = R.string.pref_search_on_start_summary
defaultValue = false defaultValue = false
} }
checkBox(PreferenceKeys.SHOW_HIDDEN_CONTENTS) { switch(PreferenceKeys.SHOW_HIDDEN_CONTENTS) {
titleRes = R.string.pref_show_hidden_title titleRes = R.string.pref_show_hidden_title
summaryRes = R.string.pref_show_hidden_summary summaryRes = R.string.pref_show_hidden_summary
defaultValue = false defaultValue = false
} }
val canAuthenticate = BiometricAuthenticator.canAuthenticate(activity) val canAuthenticate = BiometricAuthenticator.canAuthenticate(activity)
checkBox(PreferenceKeys.BIOMETRIC_AUTH) { switch(PreferenceKeys.BIOMETRIC_AUTH) {
titleRes = R.string.pref_biometric_auth_title titleRes = R.string.pref_biometric_auth_title
defaultValue = false defaultValue = false
enabled = canAuthenticate enabled = canAuthenticate

View file

@ -17,9 +17,9 @@ import app.passwordstore.R
import app.passwordstore.util.services.PasswordExportService import app.passwordstore.util.services.PasswordExportService
import app.passwordstore.util.settings.PreferenceKeys import app.passwordstore.util.settings.PreferenceKeys
import de.Maxr1998.modernpreferences.PreferenceScreen import de.Maxr1998.modernpreferences.PreferenceScreen
import de.Maxr1998.modernpreferences.helpers.checkBox
import de.Maxr1998.modernpreferences.helpers.onClick import de.Maxr1998.modernpreferences.helpers.onClick
import de.Maxr1998.modernpreferences.helpers.pref import de.Maxr1998.modernpreferences.helpers.pref
import de.Maxr1998.modernpreferences.helpers.switch
class MiscSettings(activity: FragmentActivity) : SettingsProvider { class MiscSettings(activity: FragmentActivity) : SettingsProvider {
@ -65,12 +65,12 @@ class MiscSettings(activity: FragmentActivity) : SettingsProvider {
true true
} }
} }
checkBox(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY) { switch(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY) {
defaultValue = false defaultValue = false
titleRes = R.string.pref_clear_clipboard_title titleRes = R.string.pref_clear_clipboard_title
summaryRes = R.string.pref_clear_clipboard_summary summaryRes = R.string.pref_clear_clipboard_summary
} }
checkBox(PreferenceKeys.ENABLE_DEBUG_LOGGING) { switch(PreferenceKeys.ENABLE_DEBUG_LOGGING) {
defaultValue = false defaultValue = false
titleRes = R.string.pref_debug_logging_title titleRes = R.string.pref_debug_logging_title
summaryRes = R.string.pref_debug_logging_summary summaryRes = R.string.pref_debug_logging_summary

View file

@ -10,10 +10,10 @@ import androidx.fragment.app.FragmentActivity
import app.passwordstore.R import app.passwordstore.R
import app.passwordstore.util.settings.PreferenceKeys import app.passwordstore.util.settings.PreferenceKeys
import de.Maxr1998.modernpreferences.PreferenceScreen import de.Maxr1998.modernpreferences.PreferenceScreen
import de.Maxr1998.modernpreferences.helpers.checkBox
import de.Maxr1998.modernpreferences.helpers.editText import de.Maxr1998.modernpreferences.helpers.editText
import de.Maxr1998.modernpreferences.helpers.onSelectionChange import de.Maxr1998.modernpreferences.helpers.onSelectionChange
import de.Maxr1998.modernpreferences.helpers.singleChoice import de.Maxr1998.modernpreferences.helpers.singleChoice
import de.Maxr1998.modernpreferences.helpers.switch
import de.Maxr1998.modernpreferences.preferences.choice.SelectionItem import de.Maxr1998.modernpreferences.preferences.choice.SelectionItem
class PasswordSettings(private val activity: FragmentActivity) : SettingsProvider { class PasswordSettings(private val activity: FragmentActivity) : SettingsProvider {
@ -38,12 +38,12 @@ class PasswordSettings(private val activity: FragmentActivity) : SettingsProvide
} }
textInputType = InputType.TYPE_CLASS_NUMBER textInputType = InputType.TYPE_CLASS_NUMBER
} }
checkBox(PreferenceKeys.SHOW_PASSWORD) { switch(PreferenceKeys.SHOW_PASSWORD) {
titleRes = R.string.show_password_pref_title titleRes = R.string.show_password_pref_title
summaryRes = R.string.show_password_pref_summary summaryRes = R.string.show_password_pref_summary
defaultValue = true defaultValue = true
} }
checkBox(PreferenceKeys.COPY_ON_DECRYPT) { switch(PreferenceKeys.COPY_ON_DECRYPT) {
titleRes = R.string.pref_copy_title titleRes = R.string.pref_copy_title
summaryRes = R.string.pref_copy_summary summaryRes = R.string.pref_copy_summary
defaultValue = false defaultValue = false

View file

@ -39,9 +39,9 @@ import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.components.SingletonComponent import dagger.hilt.components.SingletonComponent
import de.Maxr1998.modernpreferences.Preference import de.Maxr1998.modernpreferences.Preference
import de.Maxr1998.modernpreferences.PreferenceScreen import de.Maxr1998.modernpreferences.PreferenceScreen
import de.Maxr1998.modernpreferences.helpers.checkBox
import de.Maxr1998.modernpreferences.helpers.onClick import de.Maxr1998.modernpreferences.helpers.onClick
import de.Maxr1998.modernpreferences.helpers.pref import de.Maxr1998.modernpreferences.helpers.pref
import de.Maxr1998.modernpreferences.helpers.switch
class RepositorySettings(private val activity: FragmentActivity) : SettingsProvider { class RepositorySettings(private val activity: FragmentActivity) : SettingsProvider {
@ -64,7 +64,7 @@ class RepositorySettings(private val activity: FragmentActivity) : SettingsProvi
val gitSettings = hiltEntryPoint.gitSettings() val gitSettings = hiltEntryPoint.gitSettings()
builder.apply { builder.apply {
checkBox(PreferenceKeys.REBASE_ON_PULL) { switch(PreferenceKeys.REBASE_ON_PULL) {
titleRes = R.string.pref_rebase_on_pull_title titleRes = R.string.pref_rebase_on_pull_title
summaryRes = R.string.pref_rebase_on_pull_summary summaryRes = R.string.pref_rebase_on_pull_summary
summaryOnRes = R.string.pref_rebase_on_pull_summary_on summaryOnRes = R.string.pref_rebase_on_pull_summary_on

View file

@ -37,31 +37,37 @@ class SettingsActivity : AppCompatActivity() {
val screen = val screen =
screen(this) { screen(this) {
subScreen { subScreen {
collapseIcon = true
titleRes = R.string.pref_category_general_title titleRes = R.string.pref_category_general_title
iconRes = R.drawable.app_settings_alt_24px iconRes = R.drawable.app_settings_alt_24px
generalSettings.provideSettings(this) generalSettings.provideSettings(this)
} }
subScreen { subScreen {
collapseIcon = true
titleRes = R.string.pref_category_autofill_title titleRes = R.string.pref_category_autofill_title
iconRes = R.drawable.ic_wysiwyg_24px iconRes = R.drawable.ic_wysiwyg_24px
autofillSettings.provideSettings(this) autofillSettings.provideSettings(this)
} }
subScreen { subScreen {
collapseIcon = true
titleRes = R.string.pref_category_passwords_title titleRes = R.string.pref_category_passwords_title
iconRes = R.drawable.ic_password_24px iconRes = R.drawable.ic_password_24px
passwordSettings.provideSettings(this) passwordSettings.provideSettings(this)
} }
subScreen { subScreen {
collapseIcon = true
titleRes = R.string.pref_category_repository_title titleRes = R.string.pref_category_repository_title
iconRes = R.drawable.ic_call_merge_24px iconRes = R.drawable.ic_call_merge_24px
repositorySettings.provideSettings(this) repositorySettings.provideSettings(this)
} }
subScreen { subScreen {
collapseIcon = true
titleRes = R.string.pref_category_misc_title titleRes = R.string.pref_category_misc_title
iconRes = R.drawable.ic_miscellaneous_services_24px iconRes = R.drawable.ic_miscellaneous_services_24px
miscSettings.provideSettings(this) miscSettings.provideSettings(this)
} }
subScreen { subScreen {
collapseIcon = true
titleRes = R.string.pref_category_pgp_title titleRes = R.string.pref_category_pgp_title
iconRes = R.drawable.ic_lock_open_24px iconRes = R.drawable.ic_lock_open_24px
pgpSettings.provideSettings(this) pgpSettings.provideSettings(this)

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.materialswitch.MaterialSwitch xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:focusable="false" />