Controls UI - Fix multiple PIN dialog attempts
On cancel, the previous state should be cleared so that the wrong text is not displayed on the next attempt. Bug: 156070931 Test: PIN dialog, cancel, PIN dialog Change-Id: I625843e7768dc0b8e75045813a60774e930c5a5f
This commit is contained in:
@@ -50,7 +50,8 @@ object ChallengeDialogs {
|
||||
fun createPinDialog(
|
||||
cvh: ControlViewHolder,
|
||||
useAlphaNumeric: Boolean,
|
||||
useRetryStrings: Boolean
|
||||
useRetryStrings: Boolean,
|
||||
onCancel: () -> Unit
|
||||
): Dialog? {
|
||||
val lastAction = cvh.lastAction
|
||||
if (lastAction == null) {
|
||||
@@ -86,7 +87,10 @@ object ChallengeDialogs {
|
||||
})
|
||||
setNegativeButton(
|
||||
android.R.string.cancel,
|
||||
DialogInterface.OnClickListener { dialog, _ -> dialog.cancel() }
|
||||
DialogInterface.OnClickListener { dialog, _ ->
|
||||
onCancel.invoke()
|
||||
dialog.cancel()
|
||||
}
|
||||
)
|
||||
}
|
||||
return builder.create().apply {
|
||||
@@ -111,7 +115,7 @@ object ChallengeDialogs {
|
||||
/**
|
||||
* AlertDialogs to handle [ControlAction#RESPONSE_CHALLENGE_ACK] response type.
|
||||
*/
|
||||
fun createConfirmationDialog(cvh: ControlViewHolder): Dialog? {
|
||||
fun createConfirmationDialog(cvh: ControlViewHolder, onCancel: () -> Unit): Dialog? {
|
||||
val lastAction = cvh.lastAction
|
||||
if (lastAction == null) {
|
||||
Log.e(ControlsUiController.TAG,
|
||||
@@ -130,7 +134,10 @@ object ChallengeDialogs {
|
||||
})
|
||||
setNegativeButton(
|
||||
android.R.string.cancel,
|
||||
DialogInterface.OnClickListener { dialog, _ -> dialog.cancel() }
|
||||
DialogInterface.OnClickListener { dialog, _ ->
|
||||
onCancel.invoke()
|
||||
dialog.cancel()
|
||||
}
|
||||
)
|
||||
}
|
||||
return builder.create().apply {
|
||||
|
||||
@@ -86,6 +86,7 @@ class ControlViewHolder(
|
||||
var behavior: Behavior? = null
|
||||
var lastAction: ControlAction? = null
|
||||
private var lastChallengeDialog: Dialog? = null
|
||||
private val onDialogCancel: () -> Unit = { lastChallengeDialog = null }
|
||||
|
||||
val deviceType: Int
|
||||
get() = cws.control?.let { it.getDeviceType() } ?: cws.ci.deviceType
|
||||
@@ -154,15 +155,18 @@ class ControlViewHolder(
|
||||
setTransientStatus(context.resources.getString(R.string.controls_error_failed))
|
||||
}
|
||||
ControlAction.RESPONSE_CHALLENGE_PIN -> {
|
||||
lastChallengeDialog = ChallengeDialogs.createPinDialog(this, false, failedAttempt)
|
||||
lastChallengeDialog = ChallengeDialogs.createPinDialog(
|
||||
this, false, failedAttempt, onDialogCancel)
|
||||
lastChallengeDialog?.show()
|
||||
}
|
||||
ControlAction.RESPONSE_CHALLENGE_PASSPHRASE -> {
|
||||
lastChallengeDialog = ChallengeDialogs.createPinDialog(this, true, failedAttempt)
|
||||
lastChallengeDialog = ChallengeDialogs.createPinDialog(
|
||||
this, false, failedAttempt, onDialogCancel)
|
||||
lastChallengeDialog?.show()
|
||||
}
|
||||
ControlAction.RESPONSE_CHALLENGE_ACK -> {
|
||||
lastChallengeDialog = ChallengeDialogs.createConfirmationDialog(this)
|
||||
lastChallengeDialog = ChallengeDialogs.createConfirmationDialog(
|
||||
this, onDialogCancel)
|
||||
lastChallengeDialog?.show()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user