mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Add done button for when creating new PINs
This commit is contained in:
parent
8b73c35e43
commit
87e71b215d
1 changed files with 33 additions and 8 deletions
|
@ -4,12 +4,12 @@ import android.content.Context
|
|||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.isVisible
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.databinding.LockPinDialogBinding
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||
|
@ -21,14 +21,18 @@ object AccountDialog {
|
|||
context: Context,
|
||||
currentPin: String?,
|
||||
editAccount: Boolean,
|
||||
errorText: String? = null,
|
||||
callback: (String?) -> Unit
|
||||
) {
|
||||
fun TextView.visibleWithText(@StringRes textRes: Int) {
|
||||
visibility = View.VISIBLE
|
||||
isVisible = true
|
||||
setText(textRes)
|
||||
}
|
||||
|
||||
fun View.isVisible() = visibility == View.VISIBLE
|
||||
fun TextView.visibleWithText(text: String?) {
|
||||
isVisible = true
|
||||
setText(text)
|
||||
}
|
||||
|
||||
val binding = LockPinDialogBinding.inflate(LayoutInflater.from(context))
|
||||
|
||||
|
@ -38,7 +42,7 @@ object AccountDialog {
|
|||
|
||||
val titleRes = if (isEditPin) R.string.enter_current_pin else R.string.enter_pin
|
||||
|
||||
val dialog = AlertDialog.Builder(context, R.style.AlertDialogCustom)
|
||||
val builder = AlertDialog.Builder(context, R.style.AlertDialogCustom)
|
||||
.setView(binding.root)
|
||||
.setTitle(titleRes)
|
||||
.setNegativeButton(R.string.cancel) { _, _ ->
|
||||
|
@ -48,11 +52,32 @@ object AccountDialog {
|
|||
callback.invoke(null)
|
||||
}
|
||||
.setOnDismissListener {
|
||||
if (binding.pinEditTextError.isVisible()) {
|
||||
if (binding.pinEditTextError.isVisible) {
|
||||
callback.invoke(null)
|
||||
}
|
||||
}
|
||||
.create()
|
||||
|
||||
if (isNewPin) {
|
||||
if (errorText != null) binding.pinEditTextError.visibleWithText(errorText)
|
||||
builder.setPositiveButton(R.string.setup_done) { _, _ ->
|
||||
if (binding.pinEditTextError.isVisible) {
|
||||
// If the done button is pressed and there is an error,
|
||||
// ask again, and mention the error that caused this.
|
||||
showPinInputDialog(
|
||||
context = binding.root.context,
|
||||
currentPin = null,
|
||||
editAccount = true,
|
||||
errorText = binding.pinEditTextError.text.toString(),
|
||||
callback = callback
|
||||
)
|
||||
} else {
|
||||
val enteredPin = binding.pinEditText.text.toString()
|
||||
callback.invoke(enteredPin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val dialog = builder.create()
|
||||
|
||||
var isPinValid = false
|
||||
|
||||
|
@ -70,14 +95,14 @@ object AccountDialog {
|
|||
binding.pinEditText.text = null
|
||||
isPinValid = false
|
||||
} else {
|
||||
binding.pinEditTextError.visibility = View.GONE
|
||||
binding.pinEditTextError.isVisible = false
|
||||
isPinValid = true
|
||||
|
||||
callback.invoke(enteredPin)
|
||||
dialog.dismissSafe()
|
||||
}
|
||||
} else {
|
||||
binding.pinEditTextError.visibility = View.GONE
|
||||
binding.pinEditTextError.isVisible = false
|
||||
isPinValid = true
|
||||
}
|
||||
} else if (isNewPin) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue