Added the PatternLockView library to the project, which will let us add the pattern security option. Modified the Settings screen so that when the user tries to change its Security Lock option and the current one is PIN, show the PIN dialog first. Created the PINSecurityLockDialog which will host the logic of creating and confirming the new PIN, and verifying the current one. Finally, created BaseSecurityLockDialog which will host the shared logic between the PIN and Pattern Security Lock dialogs.

master
Severiano Jaramillo 2019-02-14 09:06:22 -06:00
parent 084a90d515
commit 123482e996
8 changed files with 166 additions and 11 deletions

View File

@ -107,6 +107,7 @@ dependencies {
implementation 'com.moldedbits.r2d2:r2d2:1.0.1'
implementation 'me.dm7.barcodescanner:zxing:1.9.8'
implementation 'com.afollestad.material-dialogs:core:2.0.0-rc9'
implementation 'com.andrognito.patternlockview:patternlockview:1.0.0'
// Android Debug Database
debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'

View File

@ -0,0 +1,28 @@
package cy.agorise.bitsybitshareswallet.fragments
import android.app.Dialog
import android.os.Bundle
import androidx.fragment.app.DialogFragment
/**
* Encapsulates the shared logic required for the PIN and Pattern Security Lock Fragments.
*/
abstract class BaseSecurityLockDialog : DialogFragment() {
companion object {
/** Used to denote that the user is in the step of creating the preferred security lock option */
const val SECURITY_LOG_STEP_CREATE = 0x01
/** Used to denote that the user is in the step of confirming the just created security lock option */
const val SECURITY_LOG_STEP_CONFIRM = 0x02
/** Used to denote that the user is in the step of verifying the current security lock option, to give
* permission to do a security constrained action like sending a transaction or trying to change the
* current security lock option */
const val SECURITY_LOG_STEP_VERIFY = 0x04
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return super.onCreateDialog(savedInstanceState)
}
}

View File

@ -83,9 +83,9 @@ class FilterOptionsDialog : DialogFragment() {
private lateinit var sAsset: Spinner
private lateinit var cbEquivalentValue: CheckBox
private lateinit var llEquivalentValue: LinearLayout
lateinit var etFromEquivalentValue: EditText
lateinit var etToEquivalentValue: EditText
lateinit var tvEquivalentValueSymbol: TextView
private lateinit var etFromEquivalentValue: EditText
private lateinit var etToEquivalentValue: EditText
private lateinit var tvEquivalentValueSymbol: TextView
private lateinit var switchAgoriseFees: Switch
private var mCallback: OnFilterOptionsSelectedListener? = null

View File

@ -0,0 +1,36 @@
package cy.agorise.bitsybitshareswallet.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import cy.agorise.bitsybitshareswallet.R
/**
* Contains all the specific logic to create and confirm a new PIN or verifying the validity of the current one.
*/
class PINSecurityLockDialog : BaseSecurityLockDialog() {
companion object {
const val TAG = "PINSecurityLockDialog"
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_pin_security_lock, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
override fun onResume() {
super.onResume()
// Force dialog fragment to use the full width of the screen
val dialogWindow = dialog.window
dialogWindow?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
}
}

View File

@ -109,8 +109,8 @@ class SettingsFragment : Fragment(), ServiceConnection {
tvSecurityLockSelected.text = resources.getStringArray(R.array.security_lock_options)[securityLockSelected]
tvSecurityLock.setOnClickListener { v -> showChooseSecurityLockDialog(v) }
tvSecurityLockSelected.setOnClickListener { v -> showChooseSecurityLockDialog(v) }
tvSecurityLock.setOnClickListener { onSecurityLockTextSelected(securityLockSelected) }
tvSecurityLockSelected.setOnClickListener { onSecurityLockTextSelected(securityLockSelected) }
// Connect to the RxBus, which receives events from the NetworkService
mDisposables.add(
@ -210,14 +210,34 @@ class SettingsFragment : Fragment(), ServiceConnection {
}
}
private fun onSecurityLockTextSelected(securityLockSelected: Int) {
when (securityLockSelected) {
0 /* PIN */ -> {
val pinFrag = PINSecurityLockDialog()
pinFrag.show(childFragmentManager, "pin_security_lock_tag")
}
1 /* Pattern */ -> {
}
else -> { /* None */
}
}
}
/**
* 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!")
private fun showChooseSecurityLockDialog() {
context?.let {
MaterialDialog(it).show {
title(R.string.title__security_dialog)
listItems(R.array.security_lock_options) {dialog, index, text ->
dialog.context.toast("$text selected!")
}
cancelable(false)
cancelOnTouchOutside(false)
negativeButton(android.R.string.cancel)
}
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/colorPrimary"
android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8L8.9,8L8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z"/>
</vector>

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
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"
tools:context=".fragments.PINSecurityLockDialog">
<ImageView
android:id="@+id/ivLock"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginTop="@dimen/spacing_same_topic"
android:src="@drawable/ic_lock"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_same_topic"
android:text="Enter your PIN"
android:textAppearance="@style/TextAppearance.Bitsy.Headline5"
app:layout_constraintTop_toBottomOf="@id/ivLock" />
<TextView
android:id="@+id/tvSubTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Enter your BiTSy PIN to continue"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
app:layout_constraintTop_toBottomOf="@id/tvTitle"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/spacing_different_section"
android:layout_marginEnd="@dimen/spacing_different_section"
app:layout_constraintTop_toBottomOf="@id/tvSubTitle"
app:layout_constraintBottom_toBottomOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tietPIN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
tools:text="123456"
android:inputType="numberPassword"
android:imeOptions="actionGo"/>
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,7 +1,7 @@
<resources>
<!-- Base application light theme. -->
<style name="Theme.Bitsy" parent="Theme.MaterialComponents.Light.DarkActionBar">
<style name="Theme.Bitsy" parent="Theme.MaterialComponents.Light.DarkActionBar.Bridge">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>