2
0
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:
Alexandru2909 2022-02-24 17:03:29 +02:00 committed by mergify[bot]
parent cb362b1685
commit 96bda01189
4 changed files with 47 additions and 9 deletions

View File

@ -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

View File

@ -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,6 +70,7 @@ class DefaultCreditCardEditorController(
}
override fun handleDeleteCreditCard(guid: String) {
showDeleteDialog { dialog, _ ->
lifecycleScope.launch(ioDispatcher) {
storage.deleteCreditCard(guid)
@ -74,6 +79,8 @@ class DefaultCreditCardEditorController(
}
metrics.track(Event.CreditCardDeleted)
}
dialog.dismiss()
}
}
override fun handleSaveCreditCard(creditCardFields: NewCreditCardFields) {

View File

@ -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>

View File

@ -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
)
)
}