From 123482e99679457bbb0cf33156d54c59d5b67660 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Thu, 14 Feb 2019 09:06:22 -0600 Subject: [PATCH] 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. --- app/build.gradle | 1 + .../fragments/BaseSecurityLockDialog.kt | 28 +++++++++ .../fragments/FilterOptionsDialog.kt | 6 +- .../fragments/PINSecurityLockDialog.kt | 36 +++++++++++ .../fragments/SettingsFragment.kt | 34 ++++++++--- app/src/main/res/drawable/ic_lock.xml | 9 +++ .../res/layout/dialog_pin_security_lock.xml | 61 +++++++++++++++++++ app/src/main/res/values/styles.xml | 2 +- 8 files changed, 166 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseSecurityLockDialog.kt create mode 100644 app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PINSecurityLockDialog.kt create mode 100644 app/src/main/res/drawable/ic_lock.xml create mode 100644 app/src/main/res/layout/dialog_pin_security_lock.xml diff --git a/app/build.gradle b/app/build.gradle index f696570..195d34b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseSecurityLockDialog.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseSecurityLockDialog.kt new file mode 100644 index 0000000..501549f --- /dev/null +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseSecurityLockDialog.kt @@ -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) + } +} \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/FilterOptionsDialog.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/FilterOptionsDialog.kt index fe0241f..ca7ed55 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/FilterOptionsDialog.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/FilterOptionsDialog.kt @@ -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 diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PINSecurityLockDialog.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PINSecurityLockDialog.kt new file mode 100644 index 0000000..acd6da9 --- /dev/null +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PINSecurityLockDialog.kt @@ -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) + } +} \ No newline at end of file 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 9685f95..d2c6d7a 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt @@ -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) } } } diff --git a/app/src/main/res/drawable/ic_lock.xml b/app/src/main/res/drawable/ic_lock.xml new file mode 100644 index 0000000..fec5e4d --- /dev/null +++ b/app/src/main/res/drawable/ic_lock.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/dialog_pin_security_lock.xml b/app/src/main/res/layout/dialog_pin_security_lock.xml new file mode 100644 index 0000000..e6756a2 --- /dev/null +++ b/app/src/main/res/layout/dialog_pin_security_lock.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index f77e935..2fec67d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,7 +1,7 @@ -