mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/23936 - Show dialog on credit card delete
This commit is contained in:
parent
cb362b1685
commit
96bda01189
@ -4,11 +4,13 @@
|
||||
|
||||
package org.mozilla.fenix.settings.creditcards
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
@ -38,6 +40,8 @@ class CreditCardEditorFragment : SecureFragment(R.layout.fragment_credit_card_ed
|
||||
private lateinit var creditCardEditorView: CreditCardEditorView
|
||||
private lateinit var menu: Menu
|
||||
|
||||
private var deleteDialog: AlertDialog? = null
|
||||
|
||||
private val args by navArgs<CreditCardEditorFragmentArgs>()
|
||||
|
||||
/**
|
||||
@ -59,7 +63,8 @@ class CreditCardEditorFragment : SecureFragment(R.layout.fragment_credit_card_ed
|
||||
storage = storage,
|
||||
lifecycleScope = lifecycleScope,
|
||||
navController = findNavController(),
|
||||
requireContext().components.analytics.metrics
|
||||
requireContext().components.analytics.metrics,
|
||||
showDeleteDialog = ::showDeleteDialog
|
||||
)
|
||||
)
|
||||
|
||||
@ -97,6 +102,7 @@ class CreditCardEditorFragment : SecureFragment(R.layout.fragment_credit_card_ed
|
||||
override fun onPause() {
|
||||
view?.hideKeyboard()
|
||||
menu.close()
|
||||
deleteDialog?.dismiss()
|
||||
|
||||
redirectToReAuth(
|
||||
listOf(R.id.creditCardsManagementFragment),
|
||||
@ -127,6 +133,17 @@ class CreditCardEditorFragment : SecureFragment(R.layout.fragment_credit_card_ed
|
||||
else -> false
|
||||
}
|
||||
|
||||
private fun showDeleteDialog(onPositiveClickListener: DialogInterface.OnClickListener) {
|
||||
deleteDialog = AlertDialog.Builder(requireContext()).apply {
|
||||
setMessage(R.string.credit_cards_delete_dialog_confirmation)
|
||||
setNegativeButton(R.string.credit_cards_cancel_button) { dialog: DialogInterface, _ ->
|
||||
dialog.cancel()
|
||||
}
|
||||
setPositiveButton(R.string.credit_cards_delete_dialog_button, onPositiveClickListener)
|
||||
create()
|
||||
}.show()
|
||||
}
|
||||
|
||||
companion object {
|
||||
// Number of years to show in the expiry year dropdown.
|
||||
const val NUMBER_OF_YEARS_TO_SHOW = 10
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
package org.mozilla.fenix.settings.creditcards.controller
|
||||
|
||||
import android.content.DialogInterface
|
||||
import androidx.navigation.NavController
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@ -52,13 +53,16 @@ interface CreditCardEditorController {
|
||||
* @param lifecycleScope [CoroutineScope] scope to launch coroutines.
|
||||
* @param navController [NavController] used for navigation.
|
||||
* @param ioDispatcher [CoroutineDispatcher] used for executing async tasks. Defaults to [Dispatchers.IO].
|
||||
* @param showDeleteDialog [DialogInterface.OnClickListener] used to display a confirmation dialog
|
||||
* before removing credit card.
|
||||
*/
|
||||
class DefaultCreditCardEditorController(
|
||||
private val storage: AutofillCreditCardsAddressesStorage,
|
||||
private val lifecycleScope: CoroutineScope,
|
||||
private val navController: NavController,
|
||||
private val metrics: MetricController,
|
||||
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO,
|
||||
private val showDeleteDialog: (DialogInterface.OnClickListener) -> Unit
|
||||
) : CreditCardEditorController {
|
||||
|
||||
override fun handleCancelButtonClicked() {
|
||||
@ -66,13 +70,16 @@ class DefaultCreditCardEditorController(
|
||||
}
|
||||
|
||||
override fun handleDeleteCreditCard(guid: String) {
|
||||
lifecycleScope.launch(ioDispatcher) {
|
||||
storage.deleteCreditCard(guid)
|
||||
showDeleteDialog { dialog, _ ->
|
||||
lifecycleScope.launch(ioDispatcher) {
|
||||
storage.deleteCreditCard(guid)
|
||||
|
||||
lifecycleScope.launch(Dispatchers.Main) {
|
||||
navController.popBackStack()
|
||||
lifecycleScope.launch(Dispatchers.Main) {
|
||||
navController.popBackStack()
|
||||
}
|
||||
metrics.track(Event.CreditCardDeleted)
|
||||
}
|
||||
metrics.track(Event.CreditCardDeleted)
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1476,11 +1476,15 @@
|
||||
<string name="credit_cards_menu_delete_card">Delete card</string>
|
||||
<!-- The text for the "Delete card" button for deleting a credit card -->
|
||||
<string name="credit_cards_delete_card_button">Delete card</string>
|
||||
<!-- The text for the confirmation message of "Delete card" dialog -->
|
||||
<string name="credit_cards_delete_dialog_confirmation">Are you sure you want to delete this credit card?</string>
|
||||
<!-- The text for the positive button on "Delete card" dialog -->
|
||||
<string name="credit_cards_delete_dialog_button">Delete</string>
|
||||
<!-- The title for the "Save" menu item for saving a credit card -->
|
||||
<string name="credit_cards_menu_save">Save</string>
|
||||
<!-- The text for the "Save" button for saving a credit card -->
|
||||
<string name="credit_cards_save_button">Save</string>
|
||||
<!-- The text for the "Cancel" button for cancelling adding or updating a credit card -->
|
||||
<!-- The text for the "Cancel" button for cancelling adding, updating or deleting a credit card -->
|
||||
<string name="credit_cards_cancel_button">Cancel</string>
|
||||
<!-- Title of the "Saved cards" screen -->
|
||||
<string name="credit_cards_saved_cards">Saved cards</string>
|
||||
|
@ -4,8 +4,10 @@
|
||||
|
||||
package org.mozilla.fenix.settings.creditcards
|
||||
|
||||
import android.content.DialogInterface
|
||||
import androidx.navigation.NavController
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.spyk
|
||||
import io.mockk.verify
|
||||
@ -30,6 +32,7 @@ class DefaultCreditCardEditorControllerTest {
|
||||
private val storage: AutofillCreditCardsAddressesStorage = mockk(relaxed = true)
|
||||
private val navController: NavController = mockk(relaxed = true)
|
||||
private val metrics: MetricController = mockk(relaxed = true)
|
||||
private val showDeleteDialog = mockk<(DialogInterface.OnClickListener) -> Unit>()
|
||||
|
||||
private lateinit var controller: DefaultCreditCardEditorController
|
||||
|
||||
@ -40,13 +43,20 @@ class DefaultCreditCardEditorControllerTest {
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
every { showDeleteDialog(any()) } answers {
|
||||
firstArg<DialogInterface.OnClickListener>().onClick(
|
||||
mockk(relaxed = true),
|
||||
mockk(relaxed = true)
|
||||
)
|
||||
}
|
||||
controller = spyk(
|
||||
DefaultCreditCardEditorController(
|
||||
storage = storage,
|
||||
lifecycleScope = testCoroutineScope,
|
||||
navController = navController,
|
||||
ioDispatcher = testDispatcher,
|
||||
metrics = metrics
|
||||
metrics = metrics,
|
||||
showDeleteDialog = showDeleteDialog
|
||||
)
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user