discord-jadx/app/src/main/java/com/discord/utilities/phone/PhoneUtils.java

49 lines
1.8 KiB
Java

package com.discord.utilities.phone;
import android.content.Context;
import c.d.b.a.a;
import com.discord.models.phone.PhoneCountryCode;
import d0.z.d.m;
import java.util.Locale;
import java.util.Objects;
import kotlin.text.Regex;
/* compiled from: PhoneUtils.kt */
public final class PhoneUtils {
public static final PhoneUtils INSTANCE = new PhoneUtils();
private static final Regex PARTIAL_PHONE_RE = new Regex("^[-() \\d]+$");
private PhoneUtils() {
}
public final String getTranslatedStringForCountry(PhoneCountryCode phoneCountryCode, Context context) {
m.checkNotNullParameter(phoneCountryCode, "data");
m.checkNotNullParameter(context, "context");
String code = phoneCountryCode.getCode();
Locale locale = Locale.getDefault();
m.checkNotNullExpressionValue(locale, "Locale.getDefault()");
Objects.requireNonNull(code, "null cannot be cast to non-null type java.lang.String");
String lowerCase = code.toLowerCase(locale);
m.checkNotNullExpressionValue(lowerCase, "(this as java.lang.String).toLowerCase(locale)");
int identifier = context.getResources().getIdentifier(a.s("country_name_", lowerCase), "string", context.getPackageName());
if (identifier == 0) {
return phoneCountryCode.getName();
}
String string = context.getString(identifier);
m.checkNotNullExpressionValue(string, "context.getString(identifier)");
return string;
}
public final boolean isLikelyToContainPhoneNumber(String str) {
m.checkNotNullParameter(str, "input");
if (str.length() < 3) {
return false;
}
return isValidPhoneFragment(str);
}
public final boolean isValidPhoneFragment(String str) {
m.checkNotNullParameter(str, "input");
return PARTIAL_PHONE_RE.matches(str);
}
}