From 084a90d51592288441fcf8e4e9277825cb50ce26 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Wed, 13 Feb 2019 13:37:15 -0600 Subject: [PATCH] Add a Security section to the Settings screen, with a Security Lock option where the user can see the currently selected Security Lock option. When it is tapped a dialog appears where the user can select his desired Security Lock (PIN/Pattern/None). --- .../fragments/SettingsFragment.kt | 27 +++ .../bitsybitshareswallet/utils/Constants.kt | 3 + app/src/main/res/layout/fragment_settings.xml | 189 ++++++++++-------- app/src/main/res/values-es/strings.xml | 8 + app/src/main/res/values/arrays.xml | 8 + app/src/main/res/values/strings.xml | 8 + 6 files changed, 158 insertions(+), 85 deletions(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt index fd81fc4..9685f95 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt @@ -14,12 +14,14 @@ import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.callbacks.onDismiss import com.afollestad.materialdialogs.customview.customView import com.afollestad.materialdialogs.list.customListAdapter +import com.afollestad.materialdialogs.list.listItems import cy.agorise.bitsybitshareswallet.BuildConfig import cy.agorise.bitsybitshareswallet.R import cy.agorise.bitsybitshareswallet.adapters.FullNodesAdapter import cy.agorise.bitsybitshareswallet.repositories.AuthorityRepository import cy.agorise.bitsybitshareswallet.utils.Constants import cy.agorise.bitsybitshareswallet.utils.CryptoUtils +import cy.agorise.bitsybitshareswallet.utils.toast import cy.agorise.graphenej.BrainKey import cy.agorise.graphenej.api.android.NetworkService import cy.agorise.graphenej.api.android.RxBus @@ -97,6 +99,19 @@ class SettingsFragment : Fragment(), ServiceConnection { } } + // Obtain the current Security Lock Option selected and display it in the screen + val securityLockSelected = PreferenceManager.getDefaultSharedPreferences(context) + .getInt(Constants.KEY_SECURITY_LOCK_SELECTED, 0) + // Security Lock Options + // 0 -> PIN + // 1 -> Pattern + // 2 -> None + + tvSecurityLockSelected.text = resources.getStringArray(R.array.security_lock_options)[securityLockSelected] + + tvSecurityLock.setOnClickListener { v -> showChooseSecurityLockDialog(v) } + tvSecurityLockSelected.setOnClickListener { v -> showChooseSecurityLockDialog(v) } + // Connect to the RxBus, which receives events from the NetworkService mDisposables.add( RxBus.getBusInstance() @@ -195,6 +210,18 @@ class SettingsFragment : Fragment(), ServiceConnection { } } + /** + * Shows a dialog so the user can select its desired Security Lock option. + */ + private fun showChooseSecurityLockDialog(view: View) { + MaterialDialog(view.context).show { + title(R.string.title__security_dialog) + listItems(R.array.security_lock_options) {dialog, index, text -> + dialog.context.toast("$text selected!") + } + } + } + /** * Obtains the brainKey from the authorities db table for the current user account and if it is not null it passes * the brainKey to a method to show it in a nice MaterialDialog diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt index 9de202d..47e7a8f 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt @@ -101,4 +101,7 @@ object Constants { /** Name of the external storage folder used to save files like PDF and CSV exports and Backups **/ const val EXTERNAL_STORAGE_FOLDER = "BiTSy" + + /** Key used to store the user's selected Security Lock option */ + const val KEY_SECURITY_LOCK_SELECTED = "key_security_lock_selected" } diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index e9fb4c9..4994602 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -1,112 +1,131 @@ - - + android:layout_height="wrap_content" + android:paddingTop="@dimen/activity_vertical_margin" + android:paddingBottom="@dimen/activity_vertical_margin" + android:paddingStart="@dimen/activity_horizontal_margin" + android:paddingEnd="@dimen/activity_horizontal_margin" + android:orientation="vertical"> - + + + android:text="@string/title__general" + android:textAppearance="@style/TextAppearance.Bitsy.Subtitle1" + android:textStyle="bold"/> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - \ No newline at end of file + + + \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index c6a7996..117e636 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -137,4 +137,12 @@ Telegram: https://t.me/Agorise\nKeybase: https://keybase.io/team/Agorise Bloque: %1$s + + Seguridad + Bloqueo de Seguridad + Choose Security Lock + PIN + PatrĂ³n + Ninguno + diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 64b1ff2..d8f35db 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -1,7 +1,15 @@ + @string/text__pdf @string/text__csv + + + + @string/text__pin + @string/text__pattern + @string/text__none + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8a6b476..35f6e73 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -138,4 +138,12 @@ Telegram: https://t.me/Agorise\nKeybase: https://keybase.io/team/Agorise Block: %1$s + + Security + Security Lock + Choose Security Lock + PIN + Pattern + None +