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

master
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,112 +1,131 @@
<?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
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
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">
<LinearLayout
<!-- General -->
<TextView
android:layout_width="match_parent"
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"/>
<!-- General -->
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchAutoClose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_different_topic"
app:switchPadding="12dp"
android:text="@string/msg__close_timer"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:textColor="?android:textColorPrimary"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title__general"
android:textAppearance="@style/TextAppearance.Bitsy.Subtitle1"
android:textStyle="bold"/>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchNightMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_same_topic"
android:text="@string/msg__night_mode"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:textColor="?android:textColorPrimary"/>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchAutoClose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_different_topic"
app:switchPadding="12dp"
android:text="@string/msg__close_timer"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:textColor="?android:textColorPrimary"/>
<TextView
android:id="@+id/tvNetworkStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_same_topic"
android:layout_marginEnd="2dp"
android:text="@string/text__view_network_status"
android:gravity="center_vertical"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:drawableEnd="@drawable/ic_disconnected"/>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchNightMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_same_topic"
android:text="@string/msg__night_mode"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:textColor="?android:textColorPrimary"/>
<!-- Security -->
<TextView
android:id="@+id/tvNetworkStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_same_topic"
android:layout_marginEnd="2dp"
android:text="@string/text__view_network_status"
android:gravity="center_vertical"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:drawableEnd="@drawable/ic_disconnected"/>
<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"/>
<!-- Backup -->
<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:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_different_section"
android:text="@string/title__backup"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textStyle="bold"/>
<TextView
android:id="@+id/tvSecurityLockSelected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
tools:text="PIN"
android:textSize="16sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_different_topic"
android:text="@string/msg__brainkey_description"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"/>
<!-- Backup -->
<com.google.android.material.button.MaterialButton
android:id="@+id/btnViewBrainKey"
style="@style/Widget.Bitsy.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_same_topic"
android:text="@string/button__view_and_copy"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_different_section"
android:text="@string/title__backup"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textStyle="bold"/>
<!-- Bugs or Ideas -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_different_topic"
android:text="@string/msg__brainkey_description"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_different_section"
android:text="@string/title__bugs_or_ideas"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textStyle="bold"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/btnViewBrainKey"
style="@style/Widget.Bitsy.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_same_topic"
android:text="@string/button__view_and_copy"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_same_topic"
android:autoLink="all"
android:lineSpacingExtra="8dp"
android:text="@string/msg__bugs_or_ideas"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"/>
<!-- Bugs or Ideas -->
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_different_section"
android:text="@string/title__bugs_or_ideas"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textStyle="bold"/>
</ScrollView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_same_topic"
android:autoLink="all"
android:lineSpacingExtra="8dp"
android:text="@string/msg__bugs_or_ideas"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"/>
</LinearLayout>
</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>