mirror of
https://github.com/oxen-io/session-android.git
synced 2025-07-12 04:58:36 +00:00
Only use the NATIONAL format for the US and UK.
This commit is contained in:
parent
872f935fd5
commit
cfdef7bca7
@ -19,6 +19,7 @@ import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.libsignal.util.Pair;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@ -36,6 +37,11 @@ public class PhoneNumberFormatter {
|
||||
add("AC");
|
||||
}};
|
||||
|
||||
private static final Set<Integer> NATIONAL_FORMAT_COUNTRY_CODES = new HashSet<>(Arrays.asList(
|
||||
1, // US
|
||||
44 // UK
|
||||
));
|
||||
|
||||
private static final Pattern US_NO_AREACODE = Pattern.compile("^(\\d{7})$");
|
||||
private static final Pattern BR_NO_AREACODE = Pattern.compile("^(9?\\d{8})$");
|
||||
|
||||
@ -89,7 +95,10 @@ public class PhoneNumberFormatter {
|
||||
try {
|
||||
Phonenumber.PhoneNumber parsedNumber = phoneNumberUtil.parse(e164, localCountryCode);
|
||||
|
||||
if (localNumber.isPresent() && localNumber.get().countryCode == parsedNumber.getCountryCode()) {
|
||||
if (localNumber.isPresent() &&
|
||||
localNumber.get().countryCode == parsedNumber.getCountryCode() &&
|
||||
NATIONAL_FORMAT_COUNTRY_CODES.contains(localNumber.get().getCountryCode()))
|
||||
{
|
||||
return phoneNumberUtil.format(parsedNumber, PhoneNumberUtil.PhoneNumberFormat.NATIONAL);
|
||||
} else {
|
||||
return phoneNumberUtil.format(parsedNumber, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
|
||||
|
Loading…
x
Reference in New Issue
Block a user