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;
}
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) {

View file

@ -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);
}
}

View file

@ -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<ListItem>, 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);