mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
UX improvements
This commit is contained in:
parent
99a459d001
commit
fdabaed367
4 changed files with 85 additions and 44 deletions
|
@ -3,10 +3,12 @@ package com.lagradost.cloudstream3.utils
|
|||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
|
@ -272,18 +274,18 @@ object DataStoreHelper {
|
|||
binding.lockProfileCheckbox.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
if (canSetPin) {
|
||||
showPinInputDialog(context) { pin ->
|
||||
showPinInputDialog(context, null, true) { pin ->
|
||||
if (pin == null) return@showPinInputDialog
|
||||
currentEditAccount = currentEditAccount.copy(lockPin = pin)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (currentEditAccount.lockPin != null) {
|
||||
// Ask for the current PIN
|
||||
showPinInputDialog(context) { currentPin ->
|
||||
if (currentPin != currentEditAccount.lockPin) {
|
||||
showPinInputDialog(context, currentEditAccount.lockPin, true) { pin ->
|
||||
if (pin == null || pin != currentEditAccount.lockPin) {
|
||||
canSetPin = false
|
||||
binding.lockProfileCheckbox.isChecked = true
|
||||
binding.lockProfileIncorrect.isVisible = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -324,15 +326,11 @@ object DataStoreHelper {
|
|||
// Check if the selected account has a lock PIN set
|
||||
if (account.lockPin != null) {
|
||||
// Prompt for the lock pin
|
||||
showPinInputDialog(context) { enteredPin ->
|
||||
if (enteredPin == account.lockPin) {
|
||||
showPinInputDialog(context, account.lockPin, false) { pin ->
|
||||
if (pin == null) return@showPinInputDialog
|
||||
// Pin is correct, unlock the profile
|
||||
setAccount(account, true)
|
||||
builder.dismissSafe()
|
||||
} else {
|
||||
// PIN is incorrect, display an error message
|
||||
showToast(R.string.incorrect_pin)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No lock PIN set, directly set the account
|
||||
|
@ -374,23 +372,75 @@ object DataStoreHelper {
|
|||
builder.show()
|
||||
}
|
||||
|
||||
private fun showPinInputDialog(context: Context, callback: (String) -> Unit) {
|
||||
private fun showPinInputDialog(
|
||||
context: Context,
|
||||
currentPin: String?,
|
||||
editAccount: Boolean,
|
||||
callback: (String?) -> Unit
|
||||
) {
|
||||
val binding: LockPinDialogBinding = LockPinDialogBinding.inflate(LayoutInflater.from(context))
|
||||
val builder =
|
||||
AlertDialog.Builder(context, R.style.AlertDialogCustom)
|
||||
val builder = AlertDialog.Builder(context, R.style.AlertDialogCustom)
|
||||
.setView(binding.root)
|
||||
|
||||
builder.setTitle(R.string.enter_pin)
|
||||
.setPositiveButton(R.string.ok) { dialog, _ ->
|
||||
val enteredPin = binding.pinEditText.text.toString()
|
||||
callback(enteredPin)
|
||||
val dialog = builder.create()
|
||||
|
||||
if (editAccount && currentPin != null) {
|
||||
dialog.setTitle(R.string.enter_current_pin)
|
||||
} else dialog.setTitle(R.string.enter_pin)
|
||||
|
||||
binding.pinEditTextError.visibility = View.GONE
|
||||
|
||||
// A flag to track if the PIN is valid
|
||||
var isPinValid = false
|
||||
|
||||
binding.pinEditText.addTextChangedListener(object : TextWatcher {
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
val enteredPin = s.toString()
|
||||
if (enteredPin.length == 4) {
|
||||
if (currentPin != null) {
|
||||
if (enteredPin != currentPin) {
|
||||
binding.pinEditTextError.visibility = View.VISIBLE
|
||||
binding.pinEditTextError.text = context.getString(R.string.pin_error_incorrect)
|
||||
isPinValid = false
|
||||
} else {
|
||||
binding.pinEditTextError.visibility = View.GONE
|
||||
isPinValid = true
|
||||
|
||||
callback.invoke(enteredPin)
|
||||
dialog.dismiss()
|
||||
}
|
||||
.setNegativeButton(R.string.cancel) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
} else {
|
||||
binding.pinEditTextError.visibility = View.GONE
|
||||
isPinValid = true
|
||||
}
|
||||
} else if (editAccount && currentPin == null) {
|
||||
binding.pinEditTextError.visibility = View.VISIBLE
|
||||
binding.pinEditTextError.text = context.getString(R.string.pin_error_length)
|
||||
isPinValid = false
|
||||
}
|
||||
}
|
||||
|
||||
builder.show()
|
||||
override fun afterTextChanged(s: Editable?) {}
|
||||
})
|
||||
|
||||
// Detect IME_ACTION_DONE
|
||||
binding.pinEditText.setOnEditorActionListener { _, actionId, _ ->
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE && isPinValid) {
|
||||
val enteredPin = binding.pinEditText.text.toString()
|
||||
callback.invoke(enteredPin)
|
||||
dialog.dismiss()
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, context.getString(R.string.cancel)) { _, _ ->
|
||||
callback.invoke(null)
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
data class PosDur(
|
||||
|
|
|
@ -6,13 +6,6 @@
|
|||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/enter_lock_pin"
|
||||
android:textSize="18sp"
|
||||
android:gravity="center"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/pinEditText"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -22,4 +15,11 @@
|
|||
android:inputType="numberPassword"
|
||||
android:maxLength="4" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pinEditTextError"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -63,14 +63,6 @@
|
|||
android:layout_marginBottom="60dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lockProfileIncorrect"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="@string/lock_profile_incorrect_current"
|
||||
android:visibility="gone" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/account_name"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -717,10 +717,9 @@
|
|||
|
||||
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="enter_current_pin">Enter Current PIN</string>
|
||||
<string name="lock_profile">Lock Profile</string>
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_lock_pin">Enter Lock PIN</string>
|
||||
<string name="incorrect_pin">Incorrect PIN</string>
|
||||
<string name="lock_profile_incorrect_current">Current PIN entered incorrectly</string>
|
||||
<string name="pin_error_incorrect">Incorrect PIN. Please try again.</string>
|
||||
<string name="pin_error_length">PIN must be 4 characters</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue