From 26a4275f9b57f739df7bc4e6168d640308925b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Fri, 7 Jul 2023 14:35:51 +0200 Subject: [PATCH] Add more controls for EnterPasswordDialog --- .../commons/dialogs/EnterPasswordDialog.kt | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/EnterPasswordDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/EnterPasswordDialog.kt index f8b29944c..de7fcd527 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/EnterPasswordDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/EnterPasswordDialog.kt @@ -1,5 +1,6 @@ package com.simplemobiletools.commons.dialogs +import android.view.View import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.R import com.simplemobiletools.commons.activities.BaseSimpleActivity @@ -11,14 +12,17 @@ class EnterPasswordDialog( private val callback: (password: String) -> Unit, private val cancelCallback: () -> Unit ) { - init { - val view = activity.layoutInflater.inflate(R.layout.dialog_enter_password, null) + private var dialog: AlertDialog? = null + private val view: View = activity.layoutInflater.inflate(R.layout.dialog_enter_password, null) + + init { activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .apply { activity.setupDialogStuff(view, this, R.string.enter_password) { alertDialog -> + dialog = alertDialog alertDialog.showKeyboard(view.password) alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { val password = view.password.value @@ -29,8 +33,6 @@ class EnterPasswordDialog( } callback(password) - alertDialog.setOnDismissListener(null) - alertDialog.dismiss() } alertDialog.setOnDismissListener { @@ -39,4 +41,15 @@ class EnterPasswordDialog( } } } + + fun dismiss(notify: Boolean = true) { + if (!notify) { + dialog?.setOnDismissListener(null) + } + dialog?.dismiss() + } + + fun clearPassword() { + view.password.text?.clear() + } }