From ce00767777fd407ec4ec0e94c8aec1525cae0a62 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 23 Mar 2018 16:52:05 +0100 Subject: [PATCH] ignore bookmark name of 'None' --- .../siacs/conversations/entities/Bookmark.java | 18 +++++++++++++----- .../siacs/conversations/entities/Contact.java | 11 ++++++----- .../conversations/entities/Conversation.java | 12 +++++++----- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Bookmark.java b/src/main/java/eu/siacs/conversations/entities/Bookmark.java index 6bf27964d..b1fa55119 100644 --- a/src/main/java/eu/siacs/conversations/entities/Bookmark.java +++ b/src/main/java/eu/siacs/conversations/entities/Bookmark.java @@ -2,6 +2,7 @@ package eu.siacs.conversations.entities; import android.content.Context; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -55,18 +56,25 @@ public class Bookmark extends Element implements ListItem { @Override public String getDisplayName() { final Conversation c = getConversation(); + final String name = getBookmarkName(); if (c != null) { return c.getName().toString(); - } else if (getBookmarkName() != null - && !getBookmarkName().trim().isEmpty()) { - return getBookmarkName().trim(); + } else if (printableValue(name, false)) { + return name.trim(); } else { Jid jid = this.getJid(); - String name = jid != null ? jid.getLocal() : getAttribute("jid"); - return name != null ? name : ""; + return jid != null && jid.getLocal() != null ? jid.getLocal() : ""; } } + public static boolean printableValue(@Nullable String value, boolean permitNone) { + return value != null && !value.trim().isEmpty() && (permitNone || !"None".equals(value)); + } + + public static boolean printableValue(@Nullable String value) { + return printableValue(value, true); + } + @Override public Jid getJid() { return this.jid; diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java index ff724efb0..29af4bc9b 100644 --- a/src/main/java/eu/siacs/conversations/entities/Contact.java +++ b/src/main/java/eu/siacs/conversations/entities/Contact.java @@ -5,6 +5,7 @@ import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract; +import android.text.TextUtils; import org.json.JSONArray; import org.json.JSONException; @@ -112,13 +113,13 @@ public class Contact implements ListItem, Blockable { } public String getDisplayName() { - if (Config.X509_VERIFICATION && this.commonName != null && !this.commonName.isEmpty()) { + if (Config.X509_VERIFICATION && !TextUtils.isEmpty(this.commonName)) { return this.commonName; - } else if (this.systemName != null && !this.systemName.isEmpty()) { + } else if (!TextUtils.isEmpty(this.systemName)) { return this.systemName; - } else if (this.serverName != null && !this.serverName.isEmpty()) { + } else if (!TextUtils.isEmpty(this.serverName)) { return this.serverName; - } else if (this.presenceName != null && !this.presenceName.isEmpty() && mutualPresenceSubscription() ) { + } else if (!TextUtils.isEmpty(this.presenceName) && mutualPresenceSubscription() ) { return this.presenceName; } else if (jid.getLocal() != null) { return JidHelper.localPartOrFallback(jid); @@ -152,7 +153,7 @@ public class Contact implements ListItem, Blockable { } public boolean match(Context context, String needle) { - if (needle == null || needle.isEmpty()) { + if (TextUtils.isEmpty(needle)) { return true; } needle = needle.toLowerCase(Locale.US).trim(); diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index f677fe8d0..20f6a9246 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -26,6 +26,8 @@ import eu.siacs.conversations.xmpp.chatstate.ChatState; import eu.siacs.conversations.xmpp.mam.MamReference; import rocks.xmpp.addr.Jid; +import static eu.siacs.conversations.entities.Bookmark.printableValue; + public class Conversation extends AbstractEntity implements Blockable, Comparable { public static final String TABLENAME = "conversations"; @@ -479,15 +481,15 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public CharSequence getName() { if (getMode() == MODE_MULTI) { final String subject = getMucOptions().getSubject(); - Bookmark bookmark = getBookmark(); + final Bookmark bookmark = getBookmark(); final String bookmarkName = bookmark != null ? bookmark.getBookmarkName() : null; - if (subject != null && !subject.trim().isEmpty()) { + if (printableValue(subject)) { return subject; - } else if (bookmarkName != null && !bookmarkName.trim().isEmpty()) { + } else if (printableValue(bookmarkName, false)) { return bookmarkName; } else { - String generatedName = getMucOptions().createNameFromParticipants(); - if (generatedName != null) { + final String generatedName = getMucOptions().createNameFromParticipants(); + if (printableValue(generatedName)) { return generatedName; } else { return getJid().getLocal();