From b9203d6778057810cdc08f2753e3e0236d34f7e4 Mon Sep 17 00:00:00 2001 From: MatthewTighe Date: Mon, 2 May 2022 10:11:12 -0700 Subject: [PATCH] address feedback --- .../fenix/settings/address/ext/Address.kt | 24 +++++++------------ .../settings/address/view/AddressList.kt | 9 +++---- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/settings/address/ext/Address.kt b/app/src/main/java/org/mozilla/fenix/settings/address/ext/Address.kt index ed8073bb2d67..5c86b8d021d8 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/address/ext/Address.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/address/ext/Address.kt @@ -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 " diff --git a/app/src/main/java/org/mozilla/fenix/settings/address/view/AddressList.kt b/app/src/main/java/org/mozilla/fenix/settings/address/view/AddressList.kt index 77cadbab7d3b..0fe00334ef39 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/address/view/AddressList.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/address/view/AddressList.kt @@ -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 @@ -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) }, ) }