From bc8a48181752c2510a75a759031ca8a957432d53 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sat, 28 Oct 2023 20:31:39 -0600 Subject: [PATCH] Fix bug and don't allow pin on default account --- .../cloudstream3/utils/DataStoreHelper.kt | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/DataStoreHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/DataStoreHelper.kt index 44a64855..34d66e3c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/DataStoreHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/DataStoreHelper.kt @@ -9,6 +9,7 @@ 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 @@ -244,7 +245,7 @@ object DataStoreHelper { binding.applyBtt.setOnClickListener { if (currentEditAccount.lockPin != null) { // Ask for the current PIN - showPinInputDialog(context, currentEditAccount.lockPin, false) { pin -> + showPinInputDialog(context, currentEditAccount, false) { pin -> if (pin == null) return@showPinInputDialog // PIN is correct, proceed to update the account performAccountUpdate(currentEditAccount) @@ -258,6 +259,11 @@ object DataStoreHelper { } // Handle setting or changing the PIN + + if (currentEditAccount.keyIndex == getDefaultAccount(context).keyIndex) { + binding.lockProfileCheckbox.isVisible = false + } + var canSetPin = true binding.lockProfileCheckbox.isChecked = currentEditAccount.lockPin != null @@ -266,14 +272,18 @@ object DataStoreHelper { if (isChecked) { if (canSetPin) { showPinInputDialog(context, null, true) { pin -> - if (pin == null) return@showPinInputDialog + if (pin == null) { + binding.lockProfileCheckbox.isChecked = false + return@showPinInputDialog + } + currentEditAccount = currentEditAccount.copy(lockPin = pin) } } } else { if (currentEditAccount.lockPin != null) { // Ask for the current PIN - showPinInputDialog(context, currentEditAccount.lockPin, true) { pin -> + showPinInputDialog(context, currentEditAccount, true) { pin -> if (pin == null || pin != currentEditAccount.lockPin) { canSetPin = false binding.lockProfileCheckbox.isChecked = true @@ -334,7 +344,7 @@ object DataStoreHelper { // Check if the selected account has a lock PIN set if (account.lockPin != null) { // Prompt for the lock pin - showPinInputDialog(context, account.lockPin, false) { pin -> + showPinInputDialog(context, account, false) { pin -> if (pin == null) return@showPinInputDialog // Pin is correct, unlock the profile setAccount(account, true) @@ -382,16 +392,20 @@ object DataStoreHelper { private fun showPinInputDialog( context: Context, - currentPin: String?, + account: Account?, editAccount: Boolean, callback: (String?) -> Unit ) { + if (account?.keyIndex == getDefaultAccount(context).keyIndex) return + val binding: LockPinDialogBinding = LockPinDialogBinding.inflate(LayoutInflater.from(context)) val builder = AlertDialog.Builder(context, R.style.AlertDialogCustom) .setView(binding.root) val dialog = builder.create() + val currentPin = account?.lockPin + if (editAccount && currentPin != null) { dialog.setTitle(R.string.enter_current_pin) } else dialog.setTitle(R.string.enter_pin)