mirror of
https://github.com/status-im/keycard-connect.git
synced 2025-01-10 02:55:58 +00:00
add PIN/PUK/pairing validation/confirmation
This commit is contained in:
parent
52cdd38147
commit
fe3157caf3
@ -3,20 +3,21 @@ package im.status.keycard.connect.ui
|
||||
import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
import im.status.keycard.connect.R
|
||||
import im.status.keycard.connect.Registry
|
||||
import im.status.keycard.connect.data.PIN_ACTIVITY_ATTEMPTS
|
||||
import im.status.keycard.connect.data.PIN_ACTIVITY_CARD_UID
|
||||
import im.status.keycard.connect.data.isValidPIN
|
||||
|
||||
class PINActivity : AppCompatActivity() {
|
||||
private lateinit var cardUID: ByteArray
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
//TODO: validate PIN length == 6
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_pin)
|
||||
val attempts = intent.getIntExtra(PIN_ACTIVITY_ATTEMPTS, -1)
|
||||
@ -29,6 +30,9 @@ class PINActivity : AppCompatActivity() {
|
||||
} else {
|
||||
attemptLabel.text = getString(R.string.pin_attempts, attempts)
|
||||
}
|
||||
|
||||
val pinText = findViewById<EditText>(R.id.pinText)
|
||||
pinText.doAfterTextChanged { findViewById<Button>(R.id.okButton).isEnabled = isValidPIN(pinText.text.toString()) }
|
||||
}
|
||||
|
||||
fun ok(@Suppress("UNUSED_PARAMETER") view: View) {
|
||||
|
@ -3,19 +3,20 @@ package im.status.keycard.connect.ui
|
||||
import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
import im.status.keycard.connect.R
|
||||
import im.status.keycard.connect.Registry
|
||||
import im.status.keycard.connect.data.PUK_ACTIVITY_ATTEMPTS
|
||||
import im.status.keycard.connect.data.isValidPIN
|
||||
import im.status.keycard.connect.data.isValidPUK
|
||||
|
||||
class PUKActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
//TODO: validate PUK length == 12
|
||||
//TODO: validate PIN length == 6
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_puk)
|
||||
val attempts = intent.getIntExtra(PUK_ACTIVITY_ATTEMPTS, -1)
|
||||
@ -27,6 +28,10 @@ class PUKActivity : AppCompatActivity() {
|
||||
} else {
|
||||
attemptLabel.text = getString(R.string.pin_attempts, attempts)
|
||||
}
|
||||
|
||||
findViewById<EditText>(R.id.pukText).doAfterTextChanged { validateFields() }
|
||||
findViewById<EditText>(R.id.newPINText).doAfterTextChanged { validateFields() }
|
||||
findViewById<EditText>(R.id.pinConfirmation).doAfterTextChanged { validateFields() }
|
||||
}
|
||||
|
||||
fun ok(@Suppress("UNUSED_PARAMETER") view: View) {
|
||||
@ -42,4 +47,13 @@ class PUKActivity : AppCompatActivity() {
|
||||
setResult(Activity.RESULT_CANCELED)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun validateFields() {
|
||||
val pukText = findViewById<EditText>(R.id.pukText).text.toString()
|
||||
val pinText = findViewById<EditText>(R.id.newPINText).text.toString()
|
||||
val pinConfirmationText = findViewById<EditText>(R.id.pinConfirmation).text.toString()
|
||||
val button = findViewById<Button>(R.id.okButton)
|
||||
button.isEnabled = (pinText == pinConfirmationText) && isValidPIN(pinText) && isValidPUK(pukText)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,8 +4,10 @@ import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
import im.status.keycard.connect.R
|
||||
import im.status.keycard.connect.data.PAIRING_ACTIVITY_PASSWORD
|
||||
|
||||
@ -14,6 +16,8 @@ class PairingActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_pairing)
|
||||
val passText = findViewById<EditText>(R.id.passwordText)
|
||||
passText.doAfterTextChanged { findViewById<Button>(R.id.okButton).isEnabled = passText.text.toString().isNotEmpty() }
|
||||
}
|
||||
|
||||
fun ok(@Suppress("UNUSED_PARAMETER") view: View) {
|
||||
|
@ -34,6 +34,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="44dp"
|
||||
android:layout_marginEnd="99dp"
|
||||
android:enabled="false"
|
||||
android:onClick="ok"
|
||||
android:text="@android:string/ok"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
@ -34,6 +34,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="81dp"
|
||||
android:layout_marginEnd="57dp"
|
||||
android:enabled="false"
|
||||
android:onClick="ok"
|
||||
android:text="@android:string/ok"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
@ -50,15 +50,28 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/newPIN" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/pinConfirmation"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:ems="10"
|
||||
android:inputType="numberPassword"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.502"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/newPINText" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/attemptLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="36dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:text="@string/pin_attempts"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.498"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/newPINText" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/pinConfirmation" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/okButton"
|
||||
@ -66,6 +79,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="60dp"
|
||||
android:layout_marginEnd="68dp"
|
||||
android:enabled="false"
|
||||
android:onClick="ok"
|
||||
android:text="@android:string/ok"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
Loading…
x
Reference in New Issue
Block a user