Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 168ed4e4 authored by Ellen Poe's avatar Ellen Poe
Browse files

Merge branch 'ellenhp/no_append_locale_country' into 'main'

Don't append the locale's country when using it for formatting

Closes #29

See merge request e/os/cardinal!41
parents a0ff2c3b 66c5f505
Loading
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -27,12 +27,18 @@ import javax.inject.Singleton

@Singleton
class AddressFormatter @Inject constructor() {
    private val formatter = AndroidAddressFormatter(true, true, false)
    private val countryFormatter = AndroidAddressFormatter(true, true, false)
    private val noCountryFormatter = AndroidAddressFormatter(true, false, false)

    fun format(address: Address): String? {
        try {
            val locale = Locale.getDefault()
            val fallbackCountryCode = locale.country.uppercase()
            val formatter = if (address.countryCode != null) {
                countryFormatter
            } else {
                noCountryFormatter
            }
            return formatter.format(
                Gson().toJson(
                    mapOf(