Merge "Controls UI - Fix multiple PIN dialog attempts" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-05-12 22:29:56 +00:00
committed by Android (Google) Code Review
2 changed files with 18 additions and 7 deletions

View File

@@ -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 {

View File

@@ -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()
}
}