For #24854: Add ability to delete an existing address.
This commit is contained in:
parent
4369c0b920
commit
2192d55da3
|
@ -29,6 +29,11 @@ interface AddressEditorController {
|
|||
*/
|
||||
fun handleSaveAddress(addressFields: UpdatableAddressFields)
|
||||
|
||||
/**
|
||||
* @see [AddressEditorInteractor.onDeleteAddress]
|
||||
*/
|
||||
fun handleDeleteAddress(guid: String)
|
||||
|
||||
/**
|
||||
* @see [AddressEditorInteractor.onUpdateAddress]
|
||||
*/
|
||||
|
@ -63,6 +68,16 @@ class DefaultAddressEditorController(
|
|||
}
|
||||
}
|
||||
|
||||
override fun handleDeleteAddress(guid: String) {
|
||||
lifecycleScope.launch {
|
||||
storage.deleteAddress(guid)
|
||||
|
||||
lifecycleScope.launch(Dispatchers.Main) {
|
||||
navController.popBackStack()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleUpdateAddress(guid: String, addressFields: UpdatableAddressFields) {
|
||||
lifecycleScope.launch {
|
||||
storage.updateAddress(guid, addressFields)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package org.mozilla.fenix.settings.address.interactor
|
||||
|
||||
import mozilla.components.concept.storage.Address
|
||||
import mozilla.components.concept.storage.UpdatableAddressFields
|
||||
import org.mozilla.fenix.settings.address.controller.AddressEditorController
|
||||
|
||||
|
@ -26,6 +27,14 @@ interface AddressEditorInteractor {
|
|||
*/
|
||||
fun onSaveAddress(addressFields: UpdatableAddressFields)
|
||||
|
||||
/**
|
||||
* Deletes the provided address from the autofill storage. Called when a user
|
||||
* taps on the save menu item or "Save" button.
|
||||
*
|
||||
* @param guid The unique identifier for the [Address] record to delete.
|
||||
*/
|
||||
fun onDeleteAddress(guid: String)
|
||||
|
||||
/**
|
||||
* Updates the provided address in the autofill storage. Called when a user
|
||||
* taps on the update menu item or "Update" button.
|
||||
|
@ -53,6 +62,10 @@ class DefaultAddressEditorInteractor(
|
|||
controller.handleSaveAddress(addressFields)
|
||||
}
|
||||
|
||||
override fun onDeleteAddress(guid: String) {
|
||||
controller.handleDeleteAddress(guid)
|
||||
}
|
||||
|
||||
override fun onUpdateAddress(guid: String, addressFields: UpdatableAddressFields) {
|
||||
controller.handleUpdateAddress(guid, addressFields)
|
||||
}
|
||||
|
|
|
@ -56,6 +56,13 @@ class AddressEditorView(
|
|||
binding.cityInput.setText(address.addressLevel2)
|
||||
binding.stateInput.setText(address.addressLevel1)
|
||||
binding.zipInput.setText(address.postalCode)
|
||||
|
||||
binding.deleteButton.apply {
|
||||
isVisible = true
|
||||
setOnClickListener { view ->
|
||||
showConfirmDeleteAddressDialog(view.context, address.guid)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,4 +90,17 @@ class AddressEditorView(
|
|||
interactor.onSaveAddress(addressFields)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun showConfirmDeleteAddressDialog(context: Context, guid: String) {
|
||||
AlertDialog.Builder(context).apply {
|
||||
setMessage(R.string.addressess_confirm_dialog_message)
|
||||
setNegativeButton(R.string.addressess_confirm_dialog_cancel_button) { dialog: DialogInterface, _ ->
|
||||
dialog.cancel()
|
||||
}
|
||||
setPositiveButton(R.string.addressess_confirm_dialog_ok_button) { _, _ ->
|
||||
interactor.onDeleteAddress(guid)
|
||||
}
|
||||
create()
|
||||
}.show()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1576,6 +1576,12 @@
|
|||
<string name="addresses_cancel_button">Cancel</string>
|
||||
<!-- The text for the "Delete address" button for deleting an address -->
|
||||
<string name="addressess_delete_address_button">Delete address</string>
|
||||
<!-- The title for the "Delete address" confirmation dialog -->
|
||||
<string name="addressess_confirm_dialog_message">Are you sure you want to delete this address?</string>
|
||||
<!-- The text for the positive button on "Delete address" dialog -->
|
||||
<string name="addressess_confirm_dialog_ok_button">Delete</string>
|
||||
<!-- The text for the negative button on "Delete address" dialog -->
|
||||
<string name="addressess_confirm_dialog_cancel_button">Cancel</string>
|
||||
|
||||
<!-- Title of the Add search engine screen -->
|
||||
<string name="search_engine_add_custom_search_engine_title">Add search engine</string>
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.mockk.every
|
|||
import io.mockk.mockk
|
||||
import io.mockk.spyk
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import mozilla.components.concept.storage.Address
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.Assert.assertEquals
|
||||
|
@ -86,4 +87,22 @@ class AddressEditorViewTest {
|
|||
assertEquals("email@mozilla.com", binding.emailInput.text.toString())
|
||||
assertEquals("Telephone", binding.phoneInput.text.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN an existing address WHEN editor is opened THEN the delete address button is visible`() = runBlocking {
|
||||
val addressEditorView = spyk(AddressEditorView(binding, interactor, address))
|
||||
addressEditorView.bind()
|
||||
|
||||
assertEquals(View.VISIBLE, binding.deleteButton.visibility)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN an existing address WHEN the delete address button is clicked THEN confirm delete dialog is shown`() = runBlocking {
|
||||
val addressEditorView = spyk(AddressEditorView(binding, interactor, address))
|
||||
addressEditorView.bind()
|
||||
|
||||
binding.deleteButton.performClick()
|
||||
|
||||
verify { addressEditorView.showConfirmDeleteAddressDialog(view.context, "123") }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user