diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PatternSecurityLockDialog.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PatternSecurityLockDialog.kt new file mode 100644 index 0000000..e9dbd62 --- /dev/null +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PatternSecurityLockDialog.kt @@ -0,0 +1,75 @@ +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 +import kotlinx.android.synthetic.main.dialog_pattern_security_lock.* +import com.andrognito.patternlockview.PatternLockView +import com.andrognito.patternlockview.listener.PatternLockViewListener +import cy.agorise.bitsybitshareswallet.utils.toast + + +/** + * Contains all the specific logic to create and confirm a new Pattern or verifying the validity of the current one. + */ +class PatternSecurityLockDialog : BaseSecurityLockDialog() { + + companion object { + const val TAG = "PatternSecurityLockDialog" + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + + return inflater.inflate(R.layout.dialog_pattern_security_lock, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + setupScreen() + + patternLockView.addPatternLockListener(mPatternLockViewListener) + } + + private val mPatternLockViewListener = object : PatternLockViewListener { + override fun onStarted() { + context?.toast("Pattern started") + } + + override fun onProgress(progressPattern: List) { + tvMessage.text = getString(R.string.msg__release_finger) + } + + override fun onComplete(pattern: List) { + if (pattern.size < 4) { + patternLockView.setViewMode(PatternLockView.PatternViewMode.WRONG) + } + } + + override fun onCleared() { + context?.toast("Pattern has been cleared") + } + } + + private fun setupScreen() { + when (currentStep) { + STEP_SECURITY_LOCK_VERIFY -> { + tvTitle.text = getString(R.string.title__re_enter_your_pattern) + tvSubTitle.text = getString(R.string.msg__enter_your_pattern) + btnClear.visibility = View.INVISIBLE + } + STEP_SECURITY_LOCK_CREATE -> { + tvTitle.text = getString(R.string.title__set_bitsy_screen_lock) + tvSubTitle.text = getString(R.string.msg__set_bitsy_pattern) + btnClear.visibility = View.INVISIBLE + } + STEP_SECURITY_LOCK_CONFIRM -> { + tvTitle.text = getString(R.string.title__re_enter_your_pin) + tvSubTitle.text = "" + tvSubTitle.visibility = View.GONE + } + } + } +} \ 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 c8354bf..b30f2af 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt @@ -233,19 +233,23 @@ class SettingsFragment : Fragment(), ServiceConnection, BaseSecurityLockDialog.O * @return true if the action was handled, false otherwise */ private fun verifySecurityLock(securityLockSelected: Int, actionIdentifier: Int): Boolean { + // Args used for both PIN and Pattern options + val args = Bundle() + args.putInt(BaseSecurityLockDialog.KEY_STEP_SECURITY_LOCK, + BaseSecurityLockDialog.STEP_SECURITY_LOCK_VERIFY) + args.putInt(BaseSecurityLockDialog.KEY_ACTION_IDENTIFIER, actionIdentifier) + return when (securityLockSelected) { 0 -> { /* PIN */ val pinFrag = PINSecurityLockDialog() - val args = Bundle() - args.putInt(BaseSecurityLockDialog.KEY_STEP_SECURITY_LOCK, - BaseSecurityLockDialog.STEP_SECURITY_LOCK_VERIFY) - args.putInt(BaseSecurityLockDialog.KEY_ACTION_IDENTIFIER, actionIdentifier) pinFrag.arguments = args pinFrag.show(childFragmentManager, "pin_security_lock_tag") true } 1 -> { /* Pattern */ - + val patternFrag = PatternSecurityLockDialog() + patternFrag.arguments = args + patternFrag.show(childFragmentManager, "pattern_security_lock_tag") true } else -> { /* None */ @@ -281,19 +285,23 @@ class SettingsFragment : Fragment(), ServiceConnection, BaseSecurityLockDialog.O context?.let { MaterialDialog(it).show { title(R.string.title__security_dialog) - listItems(R.array.security_lock_options) {dialog, index, text -> + listItems(R.array.security_lock_options) {_, index, _ -> + // Args used for both PIN and Pattern options + val args = Bundle() + args.putInt(BaseSecurityLockDialog.KEY_STEP_SECURITY_LOCK, + BaseSecurityLockDialog.STEP_SECURITY_LOCK_CREATE) + args.putInt(BaseSecurityLockDialog.KEY_ACTION_IDENTIFIER, -1) + when (index) { 0 -> { /* PIN */ val pinFrag = PINSecurityLockDialog() - val args = Bundle() - args.putInt(BaseSecurityLockDialog.KEY_STEP_SECURITY_LOCK, - BaseSecurityLockDialog.STEP_SECURITY_LOCK_CREATE) - args.putInt(BaseSecurityLockDialog.KEY_ACTION_IDENTIFIER, -1) pinFrag.arguments = args pinFrag.show(childFragmentManager, "pin_security_lock_tag") } 1 -> { /* Pattern */ - + val patternFrag = PatternSecurityLockDialog() + patternFrag.arguments = args + patternFrag.show(childFragmentManager, "pattern_security_lock_tag") } else -> { /* None */ PreferenceManager.getDefaultSharedPreferences(context).edit() diff --git a/app/src/main/res/layout/dialog_pattern_security_lock.xml b/app/src/main/res/layout/dialog_pattern_security_lock.xml new file mode 100644 index 0000000..0aa9caf --- /dev/null +++ b/app/src/main/res/layout/dialog_pattern_security_lock.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + +