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

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewTighe committed May 2, 2022
1 parent 045d03b commit b9203d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,18 @@ package org.mozilla.fenix.settings.address.ext
import mozilla.components.concept.storage.Address

/**
* Generate an [AddressItemText] from a given [Address]. A well-formed [Address] will have
* a full name in the label and a street address as a description. If either are not present,
* the label and description will be based off lower priority properties.
* Generate a label from a given [Address]. A well-formed [Address] will have
* a full name in the label, otherwise it will find the highest priority [Address] property
* to use, as based on the desktop code found in: FormAutofillUtils::getAddressLabel
*/
fun Address.toItemText(): AddressItemText {
val label = getName().ifEmpty { iterateFields("") }
val description = iterateFields(label)
return AddressItemText(label, description)
}
fun Address.toLabel(): String = getName().ifEmpty { iterateFields("") }

/**
* Holds item display values about an [Address].
*
* @property label The label for the [Address].
* @property description The subtitled description for an [Address].
* Generate a description from a given [Address]. A well-formed address will have a street address
* as a description. An address with missing data will use the next available property after [label]
* based on the priorities found in the desktop code in: FormAutofillUtils::getAddressLabel
*/
data class AddressItemText(
val label: String,
val description: String
)
fun Address.toDescription(label: String): String = iterateFields(label)

private fun Address.getName(): String {
val middleName = if (additionalName.isEmpty()) "" else "$additionalName "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import mozilla.components.concept.storage.Address
import org.mozilla.fenix.R
import org.mozilla.fenix.compose.list.IconListItem
import org.mozilla.fenix.compose.list.TextListItem
import org.mozilla.fenix.settings.address.ext.toItemText
import org.mozilla.fenix.settings.address.ext.toDescription
import org.mozilla.fenix.settings.address.ext.toLabel
import org.mozilla.fenix.theme.FirefoxTheme
import org.mozilla.fenix.theme.Theme

Expand All @@ -38,11 +39,11 @@ fun AddressList(
) {
LazyColumn {
items(addresses) { address ->
val itemText = address.toItemText()
val label = address.toLabel()
TextListItem(
label = itemText.label,
label = address.toLabel(),
modifier = Modifier.padding(start = 56.dp),
description = itemText.description,
description = address.toDescription(label),
onClick = { onAddressClick(address) },
)
}
Expand Down

0 comments on commit b9203d6

Please sign in to comment.