Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #24854: Add ability to delete an existing address.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarare committed May 2, 2022
1 parent 4a8789e commit dcb91dd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.navigation.NavController
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import mozilla.components.concept.storage.Address
import mozilla.components.concept.storage.UpdatableAddressFields
import mozilla.components.service.sync.autofill.AutofillCreditCardsAddressesStorage
import org.mozilla.fenix.settings.address.AddressEditorFragment
Expand All @@ -29,6 +30,11 @@ interface AddressEditorController {
*/
fun handleSaveAddress(addressFields: UpdatableAddressFields)

/**
* @see [AddressEditorInteractor.onDeleteAddress]
*/
fun handleDeleteAddress(address: Address)

/**
* @see [AddressEditorInteractor.onUpdateAddress]
*/
Expand Down Expand Up @@ -63,6 +69,15 @@ class DefaultAddressEditorController(
}
}

override fun handleDeleteAddress(address: Address) {
lifecycleScope.launch {
storage.deleteAddress(address.guid)
lifecycleScope.launch(Dispatchers.Main) {
navController.popBackStack()
}
}
}

override fun handleUpdateAddress(guid: String, addressFields: UpdatableAddressFields) {
lifecycleScope.launch {
storage.updateAddress(guid, addressFields)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 address An [Address] record to delete.
*/
fun onDeleteAddress(address: Address)

/**
* Updates the provided address in the autofill storage. Called when a user
* taps on the update menu item or "Update" button.
Expand Down Expand Up @@ -53,6 +62,10 @@ class DefaultAddressEditorInteractor(
controller.handleSaveAddress(addressFields)
}

override fun onDeleteAddress(address: Address) {
controller.handleDeleteAddress(address)
}

override fun onUpdateAddress(guid: String, addressFields: UpdatableAddressFields) {
controller.handleUpdateAddress(guid, addressFields)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class AddressEditorView(
binding.emailInput.setText(address.email)
binding.phoneInput.setText(address.tel)
binding.fullNameInput.setText(address.givenName)

binding.deleteButton.apply {
isVisible = true
setOnClickListener { view ->
showConfirmDeleteAddressDialog(view.context, address)
}
}
}
}

Expand Down Expand Up @@ -78,4 +85,17 @@ class AddressEditorView(
interactor.onSaveAddress(addressFields)
}
}

private fun showConfirmDeleteAddressDialog(context: Context, address: Address) {
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(address)
}
create()
}.show()
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,12 @@
<string name="addressess_delete_address_button">Delete address</string>
<!-- The text for the "Update address" button for updating an address -->
<string name="addressess_update_address_button">Update</string>
<!-- The title for the "Delete address" confirmation dialog message-->
<string name="addressess_confirm_dialog_message">Are you sure you want to delete this address?</string>
<!-- The text for the "Delete address" button in confirmation dialog when deleting an address -->
<string name="addressess_confirm_dialog_ok_button">Delete</string>
<!-- The text for the "Cancel delete" button in confirmation dialog when deleting an address -->
<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>
Expand Down

0 comments on commit dcb91dd

Please sign in to comment.