Added the logic to create a new Security Lock pattern and save it encrypted in the preferences, with all used strings translated to Spanish.
This commit is contained in:
parent
e44f4ea6e2
commit
fb329658eb
4 changed files with 102 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
package cy.agorise.bitsybitshareswallet.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
@ -8,7 +9,8 @@ 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
|
||||
import cy.agorise.bitsybitshareswallet.utils.Constants
|
||||
import cy.agorise.bitsybitshareswallet.utils.CryptoUtils
|
||||
|
||||
|
||||
/**
|
||||
|
@ -25,34 +27,102 @@ class PatternSecurityLockDialog : BaseSecurityLockDialog() {
|
|||
return inflater.inflate(R.layout.dialog_pattern_security_lock, container, false)
|
||||
}
|
||||
|
||||
private var newPattern = ""
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
setupScreen()
|
||||
|
||||
patternLockView.addPatternLockListener(mPatternLockViewListener)
|
||||
|
||||
btnClear.setOnClickListener { setupScreen() }
|
||||
}
|
||||
|
||||
private val mPatternLockViewListener = object : PatternLockViewListener {
|
||||
override fun onStarted() {
|
||||
context?.toast("Pattern started")
|
||||
// Make sure the button is hidden when the user starts a new pattern when it was incorrect
|
||||
btnClear.visibility = View.INVISIBLE
|
||||
when (currentStep) {
|
||||
STEP_SECURITY_LOCK_VERIFY -> {
|
||||
// Do something
|
||||
}
|
||||
STEP_SECURITY_LOCK_CREATE -> {
|
||||
tvMessage.text = getString(R.string.msg__release_finger)
|
||||
}
|
||||
STEP_SECURITY_LOCK_CONFIRM -> {
|
||||
tvMessage.text = getString(R.string.msg__release_finger)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onProgress(progressPattern: List<PatternLockView.Dot>) {
|
||||
tvMessage.text = getString(R.string.msg__release_finger)
|
||||
|
||||
}
|
||||
|
||||
override fun onComplete(pattern: List<PatternLockView.Dot>) {
|
||||
if (currentStep == STEP_SECURITY_LOCK_VERIFY) {
|
||||
// Do something
|
||||
} else if (currentStep == STEP_SECURITY_LOCK_CREATE) {
|
||||
btnClear.visibility = View.VISIBLE
|
||||
if (pattern.size < 4) {
|
||||
tvMessage.text = getString(R.string.error__connect_at_least_4_dots)
|
||||
patternLockView.setViewMode(PatternLockView.PatternViewMode.WRONG)
|
||||
} else {
|
||||
tvMessage.text = getString(R.string.text__pattern_recorded)
|
||||
patternLockView.setViewMode(PatternLockView.PatternViewMode.CORRECT)
|
||||
patternLockView.isInputEnabled = false
|
||||
btnNext.isEnabled = true
|
||||
newPattern = getStringPattern(pattern)
|
||||
btnNext.setOnClickListener {
|
||||
currentStep = STEP_SECURITY_LOCK_CONFIRM
|
||||
setupScreen()
|
||||
}
|
||||
}
|
||||
} else if (currentStep == STEP_SECURITY_LOCK_CONFIRM) {
|
||||
val patternConfirm = getStringPattern(pattern)
|
||||
if (patternConfirm != newPattern) {
|
||||
tvMessage.text = getString(R.string.error__wront_pattern)
|
||||
btnNext.isEnabled = false
|
||||
patternLockView.setViewMode(PatternLockView.PatternViewMode.WRONG)
|
||||
} else {
|
||||
tvMessage.text = getString(R.string.msg__your_new_unlock_pattern)
|
||||
patternLockView.isEnabled = false
|
||||
patternLockView.setViewMode(PatternLockView.PatternViewMode.CORRECT)
|
||||
btnNext.isEnabled = true
|
||||
btnNext.setOnClickListener {
|
||||
context?.let {
|
||||
val encryptedPattern = CryptoUtils.encrypt(it, patternConfirm).trim()
|
||||
|
||||
// Stores the newly selected Pattern, encrypted
|
||||
PreferenceManager.getDefaultSharedPreferences(it).edit()
|
||||
.putString(Constants.KEY_ENCRYPTED_PIN, encryptedPattern)
|
||||
.putInt(Constants.KEY_SECURITY_LOCK_SELECTED, 1).apply() // 1 -> Pattern
|
||||
|
||||
dismiss()
|
||||
mCallback?.onPINPatternChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
context?.toast("Pattern has been cleared")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given pattern into a string representation of it.
|
||||
*/
|
||||
private fun getStringPattern(pattern: List<PatternLockView.Dot>): String {
|
||||
val sb = StringBuilder()
|
||||
for (dot in pattern)
|
||||
sb.append(dot.id)
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
private fun setupScreen() {
|
||||
when (currentStep) {
|
||||
STEP_SECURITY_LOCK_VERIFY -> {
|
||||
|
@ -63,12 +133,22 @@ class PatternSecurityLockDialog : BaseSecurityLockDialog() {
|
|||
STEP_SECURITY_LOCK_CREATE -> {
|
||||
tvTitle.text = getString(R.string.title__set_bitsy_screen_lock)
|
||||
tvSubTitle.text = getString(R.string.msg__set_bitsy_pattern)
|
||||
tvMessage.text = getString(R.string.text__draw_an_unlock_pattern)
|
||||
patternLockView.clearPattern()
|
||||
patternLockView.isInputEnabled = true
|
||||
btnClear.visibility = View.INVISIBLE
|
||||
btnNext.isEnabled = false
|
||||
}
|
||||
STEP_SECURITY_LOCK_CONFIRM -> {
|
||||
tvTitle.text = getString(R.string.title__re_enter_your_pin)
|
||||
tvTitle.text = getString(R.string.title__re_enter_your_pattern)
|
||||
tvSubTitle.text = ""
|
||||
tvMessage.text = getString(R.string.msg__draw_pattern_confirm)
|
||||
tvSubTitle.visibility = View.GONE
|
||||
patternLockView.clearPattern()
|
||||
patternLockView.isInputEnabled = true
|
||||
btnClear.visibility = View.INVISIBLE
|
||||
btnNext.isEnabled = false
|
||||
btnNext.text = getString(R.string.btn__confirm)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
android:id="@+id/tvMessage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_same_topic"
|
||||
tools:text="Draw an unlock pattern"
|
||||
android:textAlignment="center"
|
||||
app:layout_constraintBottom_toTopOf="@id/patternLockView"
|
||||
|
@ -55,7 +56,6 @@
|
|||
android:id="@+id/patternLockView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginBottom="@dimen/spacing_different_topic"
|
||||
app:normalStateColor="?android:textColorSecondary"
|
||||
app:correctStateColor="@color/colorPrimary"
|
||||
app:wrongStateColor="@color/colorSend"
|
||||
|
|
|
@ -157,5 +157,12 @@
|
|||
<string name="msg__release_finger">Suelta tu dedo al terminar</string>
|
||||
<string name="btn__clear">Limpiar</string>
|
||||
<string name="btn__next">Siguiente</string>
|
||||
<string name="text__draw_an_unlock_pattern">Dibuja un patrón de desbloqueo</string>
|
||||
<string name="msg__draw_pattern_confirm">Dibuja tu patrón de nuevo para confirmar</string>
|
||||
<string name="btn__confirm">Confirmar</string>
|
||||
<string name="msg__your_new_unlock_pattern">Tu nuevo patrón de desbloqueo</string>
|
||||
<string name="error__wront_pattern">Patrón incorrecto</string>
|
||||
<string name="text__pattern_recorded">Patrón registrado</string>
|
||||
<string name="error__connect_at_least_4_dots">Conecta al menos 4 puntos. Intenta de nuevo.</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -158,5 +158,12 @@
|
|||
<string name="msg__release_finger">Release finger when done</string>
|
||||
<string name="btn__clear">Clear</string>
|
||||
<string name="btn__next">Next</string>
|
||||
<string name="text__draw_an_unlock_pattern">Draw an unlock pattern</string>
|
||||
<string name="msg__draw_pattern_confirm">Draw pattern again to confirm</string>
|
||||
<string name="btn__confirm">Confirm</string>
|
||||
<string name="msg__your_new_unlock_pattern">Your new unlock pattern</string>
|
||||
<string name="error__wront_pattern">Wrong pattern</string>
|
||||
<string name="text__pattern_recorded">Pattern recorded</string>
|
||||
<string name="error__connect_at_least_4_dots">Connect at least 4 dots. Try again.</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue