kopia lustrzana https://github.com/ryukoposting/Signal-Android
Return optional for telephone number region name for the unknown case to be localized.
rodzic
ec8793c6fe
commit
a8dd81eace
|
@ -29,7 +29,7 @@ public final class CountryListLoader extends AsyncTaskLoader<ArrayList<Map<Strin
|
|||
|
||||
for (String region : regions) {
|
||||
Map<String, String> data = new HashMap<>(2);
|
||||
data.put("country_name", PhoneNumberFormatter.getRegionDisplayName(region));
|
||||
data.put("country_name", PhoneNumberFormatter.getRegionDisplayNameLegacy(region));
|
||||
data.put("country_code", "+" +PhoneNumberUtil.getInstance().getCountryCodeForRegion(region));
|
||||
results.add(data);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class DeleteAccountRepository {
|
|||
}
|
||||
|
||||
@NonNull String getRegionDisplayName(@NonNull String region) {
|
||||
return PhoneNumberFormatter.getRegionDisplayName(region);
|
||||
return PhoneNumberFormatter.getRegionDisplayName(region).or("");
|
||||
}
|
||||
|
||||
int getRegionCountryCode(@NonNull String region) {
|
||||
|
@ -73,7 +73,7 @@ class DeleteAccountRepository {
|
|||
}
|
||||
|
||||
private static @NonNull Country getCountryForRegion(@NonNull String region) {
|
||||
return new Country(PhoneNumberFormatter.getRegionDisplayName(region),
|
||||
return new Country(PhoneNumberFormatter.getRegionDisplayName(region).or(""),
|
||||
PhoneNumberUtil.getInstance().getCountryCodeForRegion(region),
|
||||
region);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public final class NumberViewState implements Parcelable {
|
|||
}
|
||||
|
||||
String regionCode = util.getRegionCodeForCountryCode(countryCode);
|
||||
return PhoneNumberFormatter.getRegionDisplayName(regionCode);
|
||||
return PhoneNumberFormatter.getRegionDisplayNameLegacy(regionCode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,7 @@ public final class NumberViewState implements Parcelable {
|
|||
String regionCode = util.getRegionCodeForNumber(phoneNumber);
|
||||
|
||||
if (regionCode != null) {
|
||||
return PhoneNumberFormatter.getRegionDisplayName(regionCode);
|
||||
return PhoneNumberFormatter.getRegionDisplayNameLegacy(regionCode);
|
||||
}
|
||||
|
||||
} catch (NumberParseException e) {
|
||||
|
|
|
@ -12,6 +12,8 @@ import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
|
|||
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
|
||||
|
||||
import org.whispersystems.libsignal.logging.Log;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.internal.util.Util;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -113,9 +115,22 @@ public class PhoneNumberFormatter {
|
|||
}
|
||||
}
|
||||
|
||||
public static String getRegionDisplayName(String regionCode) {
|
||||
return (regionCode == null || regionCode.equals("ZZ") || regionCode.equals(PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY))
|
||||
? "Unknown country" : new Locale("", regionCode).getDisplayCountry(Locale.getDefault());
|
||||
/**
|
||||
* @deprecated Use {@link #getRegionDisplayName} as it can be localized when the region is not found.
|
||||
*/
|
||||
@Deprecated
|
||||
public static String getRegionDisplayNameLegacy(String regionCode) {
|
||||
return getRegionDisplayName(regionCode).or("Unknown country");
|
||||
}
|
||||
|
||||
public static Optional<String> getRegionDisplayName(String regionCode) {
|
||||
if (regionCode != null && !regionCode.equals("ZZ") && !regionCode.equals(PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY)) {
|
||||
String displayCountry = new Locale("", regionCode).getDisplayCountry(Locale.getDefault());
|
||||
if (!Util.isEmpty(displayCountry)) {
|
||||
return Optional.of(displayCountry);
|
||||
}
|
||||
}
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
public static String formatE164(String countryCode, String number) {
|
||||
|
|
Ładowanie…
Reference in New Issue