Don't format numbers unnecessarily.
Util.getFirstNonEmpty() requires calculating all input strings first, but that's unnecessary and could result in lots of warning logs in the case of calling PhoneNumberFormatter#prettyPrint with nulls or other stuff. Fixes #10246
This commit is contained in:
parent
3f25609561
commit
323a405004
1 changed files with 55 additions and 16 deletions
|
@ -416,32 +416,71 @@ public class Recipient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull String getDisplayName(@NonNull Context context) {
|
public @NonNull String getDisplayName(@NonNull Context context) {
|
||||||
String name = Util.getFirstNonEmpty(getName(context),
|
String name = getName(context);
|
||||||
getProfileName().toString(),
|
|
||||||
PhoneNumberFormatter.prettyPrint(e164),
|
if (Util.isEmpty(name)) {
|
||||||
email,
|
name = getProfileName().toString();
|
||||||
context.getString(R.string.Recipient_unknown));
|
}
|
||||||
|
|
||||||
|
if (Util.isEmpty(name) && !Util.isEmpty(e164)) {
|
||||||
|
name = PhoneNumberFormatter.prettyPrint(e164);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Util.isEmpty(name)) {
|
||||||
|
name = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Util.isEmpty(name)) {
|
||||||
|
name = context.getString(R.string.Recipient_unknown);
|
||||||
|
}
|
||||||
|
|
||||||
return StringUtil.isolateBidi(name);
|
return StringUtil.isolateBidi(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull String getDisplayNameOrUsername(@NonNull Context context) {
|
public @NonNull String getDisplayNameOrUsername(@NonNull Context context) {
|
||||||
String name = Util.getFirstNonEmpty(getName(context),
|
String name = getName(context);
|
||||||
getProfileName().toString(),
|
|
||||||
PhoneNumberFormatter.prettyPrint(e164),
|
if (Util.isEmpty(name)) {
|
||||||
email,
|
name = getProfileName().toString();
|
||||||
username,
|
}
|
||||||
context.getString(R.string.Recipient_unknown));
|
|
||||||
|
if (Util.isEmpty(name) && !Util.isEmpty(e164)) {
|
||||||
|
name = PhoneNumberFormatter.prettyPrint(e164);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Util.isEmpty(name)) {
|
||||||
|
name = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Util.isEmpty(name)) {
|
||||||
|
name = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Util.isEmpty(name)) {
|
||||||
|
name = context.getString(R.string.Recipient_unknown);
|
||||||
|
}
|
||||||
|
|
||||||
return StringUtil.isolateBidi(name);
|
return StringUtil.isolateBidi(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull String getMentionDisplayName(@NonNull Context context) {
|
public @NonNull String getMentionDisplayName(@NonNull Context context) {
|
||||||
String name = Util.getFirstNonEmpty(isSelf ? getProfileName().toString() : getName(context),
|
String name = isSelf ? getProfileName().toString() : getName(context);
|
||||||
isSelf ? getName(context) : getProfileName().toString(),
|
|
||||||
PhoneNumberFormatter.prettyPrint(e164),
|
if (Util.isEmpty(name)) {
|
||||||
email,
|
name = isSelf ? getName(context) : getProfileName().toString();
|
||||||
context.getString(R.string.Recipient_unknown));
|
}
|
||||||
|
|
||||||
|
if (Util.isEmpty(name) && !Util.isEmpty(e164)) {
|
||||||
|
name = PhoneNumberFormatter.prettyPrint(e164);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Util.isEmpty(name)) {
|
||||||
|
name = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Util.isEmpty(name)) {
|
||||||
|
name = context.getString(R.string.Recipient_unknown);
|
||||||
|
}
|
||||||
|
|
||||||
return StringUtil.isolateBidi(name);
|
return StringUtil.isolateBidi(name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue