Enable delete account for OAuth users

This commit is contained in:
Hafiz 2022-05-15 15:55:21 -04:00
parent 327d36e58d
commit ed7d7af9c2
3 changed files with 22 additions and 14 deletions

View file

@ -592,8 +592,8 @@
<string name="reset_account_description">You will lose all your levels, Gold, and Experience. All your tasks and their historical data will be deleted (Challenge tasks will stay). You will lose all equipment, including limited edition or subscriber equipment, but you will be able to buy it back (you will need to be the correct class to re-buy class-specific gear). You will keep your current class and your Pets and Mounts. To confirm reset, type RESET below.</string>
<string name="delete_caps">DELETE</string>
<string name="delete_account">Delete Account</string>
<string name="delete_account_description">This will delete your account forever and it can never be restored! Banked or spent Gems will not be refunded. If youre absolutely certain, type DELETE into the text box below.</string>
<string name="delete_oauth_account_description">Deleted accounts are permanent and cannot be restored. Gems cannot be refunded. If you still want to delete, type DELETE below.</string>
<string name="delete_account_description">This will delete your account forever and it can never be restored! Banked or spent Gems will not be refunded. If youre absolutely certain, type your password into the text box below.</string>
<string name="delete_oauth_account_description">This will delete your account forever and it can never be restored! Banked or spent Gems will not be refunded. If youre absolutely certain, type DELETE into the text box below.</string>
<string name="reset_account_confirmation">Reset my Account</string>
<string name="delete_account_confirmation">Delete my Account</string>
<string name="danger_zone">Danger Zone</string>

View file

@ -183,8 +183,8 @@ class AccountPreferenceFragment :
disconnect("facebook", "Facebook")
}
}
"reset_account" -> showAccountResetConfirmation()
"delete_account" -> showAccountDeleteConfirmation()
"reset_account" -> showAccountResetConfirmation(user)
"delete_account" -> showAccountDeleteConfirmation(user)
"fixCharacterValues" -> {
val intent = Intent(activity, FixCharacterValuesActivity::class.java)
activity?.startActivity(intent)
@ -410,8 +410,8 @@ class AccountPreferenceFragment :
}
}
private fun showAccountDeleteConfirmation() {
val habiticaAccountDialog = context?.let { HabiticaAccountDialog(it, "delete_account", this) }
private fun showAccountDeleteConfirmation(user: User?) {
val habiticaAccountDialog = context?.let { HabiticaAccountDialog(it, "delete_account", this, user) }
habiticaAccountDialog?.show(parentFragmentManager, "account")
if (habiticaAccountDialog != null) {
@ -434,8 +434,8 @@ class AccountPreferenceFragment :
)
}
private fun showAccountResetConfirmation() {
val habiticaAccountDialog = context?.let { HabiticaAccountDialog(it, "reset_account", this) }
private fun showAccountResetConfirmation(user: User?) {
val habiticaAccountDialog = context?.let { HabiticaAccountDialog(it, "reset_account", this, user) }
habiticaAccountDialog?.show(parentFragmentManager, "account")
if (habiticaAccountDialog != null) {

View file

@ -14,9 +14,10 @@ import androidx.fragment.app.DialogFragment
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.models.user.User
class HabiticaAccountDialog(private var thisContext: Context, private val accountAction: String, val accountUpdateConfirmed: AccountUpdateConfirmed) : DialogFragment() {
class HabiticaAccountDialog(private var thisContext: Context, private val accountAction: String, val accountUpdateConfirmed: AccountUpdateConfirmed, val user: User?) : DialogFragment() {
private lateinit var mainView: View
private var backBtn: ImageButton? = null
@ -77,9 +78,13 @@ class HabiticaAccountDialog(private var thisContext: Context, private val accoun
private fun setDeleteAccountViews() {
title?.setText(R.string.are_you_sure_you_want_to_delete)
warningDescription?.setText(R.string.delete_account_description)
confirmationTextInputLayout?.setHint(R.string.password)
confirmationAction?.setText(R.string.delete_account)
warningDescription?.text = context?.getString(R.string.delete_account_description)
if (user?.authentication?.hasPassword != true) {
warningDescription?.text = context?.getString(R.string.delete_oauth_account_description)
confirmationTextInputLayout?.setHint(R.string.confirm_deletion)
}
confirmationText?.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
@ -88,9 +93,12 @@ class HabiticaAccountDialog(private var thisContext: Context, private val accoun
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
if (confirmationText?.text.toString() == context?.getString(R.string.delete_caps)) {
confirmationAction?.setTextColor(ContextCompat.getColor(thisContext, R.color.red_100))
confirmationAction?.alpha = 1.0f
if (confirmationText?.text.toString().length >= 5) {
if ((user?.authentication?.hasPassword != true && confirmationText?.text.toString() == context?.getString(R.string.delete_caps)) ||
user?.authentication?.hasPassword == true) {
confirmationAction?.setTextColor(ContextCompat.getColor(thisContext, R.color.red_100))
confirmationAction?.alpha = 1.0f
}
} else {
confirmationAction?.setTextColor(ContextCompat.getColor(thisContext, R.color.gray_10))
confirmationAction?.alpha = .4f
@ -102,7 +110,7 @@ class HabiticaAccountDialog(private var thisContext: Context, private val accoun
})
confirmationAction?.setOnClickListener {
if (confirmationText?.text.toString() == context?.getString(R.string.delete_caps)) {
accountUpdateConfirmed.resetConfirmedClicked()
accountUpdateConfirmed.deletionConfirmClicked(confirmationText?.text.toString())
}
}
}