From dca3e80bad3f8286bccd936c746fa3e9116e7075 Mon Sep 17 00:00:00 2001 From: kosyak Date: Tue, 15 Aug 2023 01:22:40 +0200 Subject: [PATCH] modify entities for proper tags navigation --- .../conversations/entities/Bookmark.java | 22 +++++++++++++++---- .../siacs/conversations/entities/Contact.java | 9 +++++--- .../conversations/entities/ListItem.java | 16 ++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Bookmark.java b/src/main/java/eu/siacs/conversations/entities/Bookmark.java index 7ded4f842..dca510750 100644 --- a/src/main/java/eu/siacs/conversations/entities/Bookmark.java +++ b/src/main/java/eu/siacs/conversations/entities/Bookmark.java @@ -195,10 +195,24 @@ public class Bookmark extends Element implements ListItem { return true; } needle = needle.toLowerCase(Locale.US); - final Jid jid = getJid(); - return (jid != null && jid.toString().contains(needle)) || - getDisplayName().toLowerCase(Locale.US).contains(needle) || - matchInTag(context, needle); + String[] parts = needle.split("[,\\s]+"); + if (parts.length > 1) { + for (String part : parts) { + if (!match(context, part)) { + return false; + } + } + return true; + } else if (parts.length > 0) { + final Jid jid = getJid(); + return (jid != null && jid.toString().contains(parts[0])) || + getDisplayName().toLowerCase(Locale.US).contains(parts[0]) || + matchInTag(context, parts[0]); + } else { + final Jid jid = getJid(); + return (jid != null && jid.toString().contains(needle)) || + getDisplayName().toLowerCase(Locale.US).contains(needle); + } } private boolean matchInTag(Context context, String needle) { diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java index 1dc78f02b..37bba38cb 100644 --- a/src/main/java/eu/siacs/conversations/entities/Contact.java +++ b/src/main/java/eu/siacs/conversations/entities/Contact.java @@ -205,7 +205,7 @@ public class Contact implements ListItem, Blockable { return true; } needle = needle.toLowerCase(Locale.US).trim(); - String[] parts = needle.split("\\s+"); + String[] parts = needle.split("[,\\s]+"); if (parts.length > 1) { for (String part : parts) { if (!match(context, part)) { @@ -213,10 +213,13 @@ public class Contact implements ListItem, Blockable { } } return true; + } else if(parts.length > 0) { + return jid.toString().contains(parts[0]) || + getDisplayName().toLowerCase(Locale.US).contains(parts[0]) || + matchInTag(context, parts[0]); } else { return jid.toString().contains(needle) || - getDisplayName().toLowerCase(Locale.US).contains(needle) || - matchInTag(context, needle); + getDisplayName().toLowerCase(Locale.US).contains(needle); } } diff --git a/src/main/java/eu/siacs/conversations/entities/ListItem.java b/src/main/java/eu/siacs/conversations/entities/ListItem.java index adc7666ce..fc8e9b6c6 100644 --- a/src/main/java/eu/siacs/conversations/entities/ListItem.java +++ b/src/main/java/eu/siacs/conversations/entities/ListItem.java @@ -3,6 +3,7 @@ package eu.siacs.conversations.entities; import android.content.Context; import java.util.List; +import java.util.Locale; import eu.siacs.conversations.services.AvatarService; import eu.siacs.conversations.xmpp.Jid; @@ -31,6 +32,21 @@ public interface ListItem extends Comparable, AvatarService.Avatarable public String getName() { return this.name; } + + + public String toString() { + return getName(); + } + + public boolean equals(Object o) { + if (!(o instanceof Tag)) return false; + Tag ot = (Tag) o; + return name.toLowerCase(Locale.US).equals(ot.getName().toLowerCase(Locale.US)) && color == ot.getColor(); + } + + public int hashCode() { + return name.toLowerCase(Locale.US).hashCode(); + } } boolean match(Context context, final String needle);