ProfileDeleteFragment: Require confirmation via inputting profile name
All checks were successful
/ build-debug (push) Successful in 4m4s
All checks were successful
/ build-debug (push) Successful in 4m4s
This commit is contained in:
parent
2a8fb99ed0
commit
19c63113a1
|
@ -2,7 +2,9 @@ package im.angry.openeuicc.ui
|
|||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.util.Log
|
||||
import android.widget.EditText
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
|
@ -26,11 +28,21 @@ class ProfileDeleteFragment : DialogFragment(), EuiccChannelFragmentMarker {
|
|||
}
|
||||
}
|
||||
|
||||
private val editText by lazy {
|
||||
EditText(requireContext()).apply {
|
||||
hint = Editable.Factory.getInstance().newEditable(
|
||||
getString(R.string.profile_delete_confirm_input, requireArguments().getString("name")!!)
|
||||
)
|
||||
}
|
||||
}
|
||||
private val inputMatchesName: Boolean
|
||||
get() = editText.text.toString() == requireArguments().getString("name")!!
|
||||
private var deleting = false
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return AlertDialog.Builder(requireContext(), R.style.AlertDialogTheme).apply {
|
||||
setMessage(getString(R.string.profile_delete_confirm, requireArguments().getString("name")))
|
||||
setView(editText)
|
||||
setPositiveButton(android.R.string.ok, null) // Set listener to null to prevent auto closing
|
||||
setNegativeButton(android.R.string.cancel, null)
|
||||
}.create()
|
||||
|
@ -40,7 +52,7 @@ class ProfileDeleteFragment : DialogFragment(), EuiccChannelFragmentMarker {
|
|||
super.onResume()
|
||||
val alertDialog = dialog!! as AlertDialog
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
if (!deleting) delete()
|
||||
if (!deleting && inputMatchesName) delete()
|
||||
}
|
||||
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener {
|
||||
if (!deleting) dismiss()
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
<string name="profile_rename_new_name">New nickname</string>
|
||||
|
||||
<string name="profile_delete_confirm">Are you sure you want to delete the profile %s? This operation is irreversible.</string>
|
||||
<string name="profile_delete_confirm_input">Type \'%s\' here to confirm deletion</string>
|
||||
|
||||
<string name="profile_notifications">Profile Notifications</string>
|
||||
<string name="profile_notifications_show">Manage Notifications</string>
|
||||
|
|
Loading…
Reference in a new issue