diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-04-13 21:52:26 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-04-13 21:52:26 +0200 |
commit | 649b52222a4cecbb184eb7bea3cf685fac2801df (patch) | |
tree | 99ff28b5cb936ab9f17ae247b280bde4054e4c8d /src/main/java/de/pixart/messenger | |
parent | db5a5bac17440231821f2e9d480046d7ac210047 (diff) |
ignore bookmark name of 'None'
Diffstat (limited to 'src/main/java/de/pixart/messenger')
3 files changed, 26 insertions, 16 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Bookmark.java b/src/main/java/de/pixart/messenger/entities/Bookmark.java index 46b5ace06..309c08e0f 100644 --- a/src/main/java/de/pixart/messenger/entities/Bookmark.java +++ b/src/main/java/de/pixart/messenger/entities/Bookmark.java @@ -2,6 +2,7 @@ package de.pixart.messenger.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 int getOffline() { return 0; diff --git a/src/main/java/de/pixart/messenger/entities/Contact.java b/src/main/java/de/pixart/messenger/entities/Contact.java index 2af40e1fb..b69f421ff 100644 --- a/src/main/java/de/pixart/messenger/entities/Contact.java +++ b/src/main/java/de/pixart/messenger/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); @@ -155,7 +156,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/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index 91257c6ff..d10868bf7 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -32,6 +32,8 @@ import de.pixart.messenger.xmpp.chatstate.ChatState; import de.pixart.messenger.xmpp.mam.MamReference; import rocks.xmpp.addr.Jid; +import static de.pixart.messenger.entities.Bookmark.printableValue; + public class Conversation extends AbstractEntity implements Blockable, Comparable<Conversation> { public static final String TABLENAME = "conversations"; @@ -511,16 +513,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(); |