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).

This commit is contained in:
Severiano Jaramillo 2019-02-13 13:37:15 -06:00
parent 19c50a0b6e
commit 084a90d515
6 changed files with 158 additions and 85 deletions

View file

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

View file

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

View file

@ -1,18 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
tools:context=".fragments.SettingsFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -61,6 +56,32 @@
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:drawableEnd="@drawable/ic_disconnected"/>
<!-- Security -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_different_section"
android:text="@string/title__security"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textStyle="bold"/>
<TextView
android:id="@+id/tvSecurityLock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_different_topic"
android:text="@string/text__security_lock"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"/>
<TextView
android:id="@+id/tvSecurityLockSelected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
tools:text="PIN"
android:textSize="16sp"/>
<!-- Backup -->
<TextView
@ -107,6 +128,4 @@
</LinearLayout>
</ScrollView>
</LinearLayout>
</ScrollView>

View file

@ -137,4 +137,12 @@
<string name="msg__bugs_or_ideas">Telegram: https://t.me/Agorise\nKeybase: https://keybase.io/team/Agorise</string>
<string name="title__bitshares_nodes_dialog">Bloque: %1$s</string>
<!-- Security Settings -->
<string name="title__security">Seguridad</string>
<string name="text__security_lock">Bloqueo de Seguridad</string>
<string name="title__security_dialog">Choose Security Lock</string>
<string name="text__pin">PIN</string>
<string name="text__pattern">Patrón</string>
<string name="text__none">Ninguno</string>
</resources>

View file

@ -1,7 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Options used to populate the Export Options Dialog in the Transactions Screen -->
<string-array name="export_options">
<item>@string/text__pdf</item>
<item>@string/text__csv</item>
</string-array>
<!-- Options used to populate the Security Lock Options Dialog in the Settings Screen -->
<string-array name="security_lock_options">
<item>@string/text__pin</item>
<item>@string/text__pattern</item>
<item>@string/text__none</item>
</string-array>
</resources>

View file

@ -138,4 +138,12 @@
<string name="msg__bugs_or_ideas">Telegram: https://t.me/Agorise\nKeybase: https://keybase.io/team/Agorise</string>
<string name="title__bitshares_nodes_dialog">Block: %1$s</string>
<!-- Security Settings -->
<string name="title__security">Security</string>
<string name="text__security_lock">Security Lock</string>
<string name="title__security_dialog">Choose Security Lock</string>
<string name="text__pin">PIN</string>
<string name="text__pattern">Pattern</string>
<string name="text__none">None</string>
</resources>