Add more controls for EnterPasswordDialog
This commit is contained in:
parent
db25f91be3
commit
26a4275f9b
1 changed files with 17 additions and 4 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue