modify entities for proper tags navigation

This commit is contained in:
kosyak 2023-08-15 01:22:40 +02:00
parent b26adc84b0
commit dca3e80bad
3 changed files with 40 additions and 7 deletions

View file

@ -195,10 +195,24 @@ public class Bookmark extends Element implements ListItem {
return true; return true;
} }
needle = needle.toLowerCase(Locale.US); needle = needle.toLowerCase(Locale.US);
final Jid jid = getJid(); String[] parts = needle.split("[,\\s]+");
return (jid != null && jid.toString().contains(needle)) || if (parts.length > 1) {
getDisplayName().toLowerCase(Locale.US).contains(needle) || for (String part : parts) {
matchInTag(context, needle); 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) { private boolean matchInTag(Context context, String needle) {

View file

@ -205,7 +205,7 @@ public class Contact implements ListItem, Blockable {
return true; return true;
} }
needle = needle.toLowerCase(Locale.US).trim(); needle = needle.toLowerCase(Locale.US).trim();
String[] parts = needle.split("\\s+"); String[] parts = needle.split("[,\\s]+");
if (parts.length > 1) { if (parts.length > 1) {
for (String part : parts) { for (String part : parts) {
if (!match(context, part)) { if (!match(context, part)) {
@ -213,10 +213,13 @@ public class Contact implements ListItem, Blockable {
} }
} }
return true; 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 { } else {
return jid.toString().contains(needle) || return jid.toString().contains(needle) ||
getDisplayName().toLowerCase(Locale.US).contains(needle) || getDisplayName().toLowerCase(Locale.US).contains(needle);
matchInTag(context, needle);
} }
} }

View file

@ -3,6 +3,7 @@ package eu.siacs.conversations.entities;
import android.content.Context; import android.content.Context;
import java.util.List; import java.util.List;
import java.util.Locale;
import eu.siacs.conversations.services.AvatarService; import eu.siacs.conversations.services.AvatarService;
import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.Jid;
@ -31,6 +32,21 @@ public interface ListItem extends Comparable<ListItem>, AvatarService.Avatarable
public String getName() { public String getName() {
return this.name; 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); boolean match(Context context, final String needle);