made tags searchable
This commit is contained in:
parent
8c4236b01b
commit
2036c58cd7
|
@ -2,8 +2,8 @@ package eu.siacs.conversations.entities;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import eu.siacs.conversations.utils.UIHelper;
|
||||
import eu.siacs.conversations.xml.Element;
|
||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||
|
@ -39,25 +39,6 @@ public class Bookmark extends Element implements ListItem {
|
|||
}
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setNick(String nick) {
|
||||
Element element = this.findChild("nick");
|
||||
if (element == null) {
|
||||
element = this.addChild("nick");
|
||||
}
|
||||
element.setContent(nick);
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
Element element = this.findChild("password");
|
||||
if (element != null) {
|
||||
element.setContent(password);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final ListItem another) {
|
||||
return this.getDisplayName().compareToIgnoreCase(
|
||||
|
@ -92,7 +73,14 @@ public class Bookmark extends Element implements ListItem {
|
|||
|
||||
@Override
|
||||
public List<Tag> getTags() {
|
||||
return new ArrayList<Tag>();
|
||||
ArrayList<Tag> tags = new ArrayList<Tag>();
|
||||
for (Element element : getChildren()) {
|
||||
if (element.getName().equals("group") && element.getContent() != null) {
|
||||
String group = element.getContent();
|
||||
tags.add(new Tag(group, UIHelper.getColorForName(group)));
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
public String getNick() {
|
||||
|
@ -104,6 +92,14 @@ public class Bookmark extends Element implements ListItem {
|
|||
}
|
||||
}
|
||||
|
||||
public void setNick(String nick) {
|
||||
Element element = this.findChild("nick");
|
||||
if (element == null) {
|
||||
element = this.addChild("nick");
|
||||
}
|
||||
element.setContent(nick);
|
||||
}
|
||||
|
||||
public boolean autojoin() {
|
||||
String autojoin = this.getAttribute("autojoin");
|
||||
return (autojoin != null && (autojoin.equalsIgnoreCase("true") || autojoin
|
||||
|
@ -119,29 +115,50 @@ public class Bookmark extends Element implements ListItem {
|
|||
}
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
Element element = this.findChild("password");
|
||||
if (element != null) {
|
||||
element.setContent(password);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean match(String needle) {
|
||||
return needle == null
|
||||
|| getJid().toString().toLowerCase(Locale.US).contains(needle.toLowerCase(Locale.US))
|
||||
|| getDisplayName().toLowerCase(Locale.US).contains(
|
||||
needle.toLowerCase(Locale.US));
|
||||
if (needle == null) {
|
||||
return true;
|
||||
}
|
||||
needle = needle.toLowerCase();
|
||||
return getJid().toString().contains(needle) || getDisplayName().toLowerCase().contains(needle) || matchInTag(needle);
|
||||
}
|
||||
|
||||
private boolean matchInTag(String needle) {
|
||||
for (Tag tag : getTags()) {
|
||||
if (tag.getName().toLowerCase().contains(needle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return this.account;
|
||||
}
|
||||
|
||||
public void setConversation(Conversation conversation) {
|
||||
this.mJoinedConversation = conversation;
|
||||
}
|
||||
|
||||
public Conversation getConversation() {
|
||||
return this.mJoinedConversation;
|
||||
}
|
||||
|
||||
public void setConversation(Conversation conversation) {
|
||||
this.mJoinedConversation = conversation;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.getAttribute("name");
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void unregisterConversation() {
|
||||
if (this.mJoinedConversation != null) {
|
||||
this.mJoinedConversation.deregisterWithBookmark();
|
||||
|
|
|
@ -8,9 +8,7 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import eu.siacs.conversations.utils.UIHelper;
|
||||
import eu.siacs.conversations.xml.Element;
|
||||
|
@ -32,7 +30,7 @@ public class Contact implements ListItem {
|
|||
public static final String LAST_PRESENCE = "last_presence";
|
||||
public static final String LAST_TIME = "last_time";
|
||||
public static final String GROUPS = "groups";
|
||||
|
||||
public Lastseen lastseen = new Lastseen();
|
||||
protected String accountUuid;
|
||||
protected String systemName;
|
||||
protected String serverName;
|
||||
|
@ -45,11 +43,8 @@ public class Contact implements ListItem {
|
|||
protected JSONObject keys = new JSONObject();
|
||||
protected JSONArray groups = new JSONArray();
|
||||
protected Presences presences = new Presences();
|
||||
|
||||
protected Account account;
|
||||
|
||||
public Lastseen lastseen = new Lastseen();
|
||||
|
||||
public Contact(final String account, final String systemName, final String serverName,
|
||||
final Jid jid, final int subscription, final String photoUri,
|
||||
final String systemAccount, final String keys, final String avatar, final Lastseen lastseen, final String groups) {
|
||||
|
@ -78,6 +73,30 @@ public class Contact implements ListItem {
|
|||
this.jid = jid;
|
||||
}
|
||||
|
||||
public static Contact fromCursor(final Cursor cursor) {
|
||||
final Lastseen lastseen = new Lastseen(
|
||||
cursor.getString(cursor.getColumnIndex(LAST_PRESENCE)),
|
||||
cursor.getLong(cursor.getColumnIndex(LAST_TIME)));
|
||||
final Jid jid;
|
||||
try {
|
||||
jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(JID)));
|
||||
} catch (final InvalidJidException e) {
|
||||
// TODO: Borked DB... handle this somehow?
|
||||
return null;
|
||||
}
|
||||
return new Contact(cursor.getString(cursor.getColumnIndex(ACCOUNT)),
|
||||
cursor.getString(cursor.getColumnIndex(SYSTEMNAME)),
|
||||
cursor.getString(cursor.getColumnIndex(SERVERNAME)),
|
||||
jid,
|
||||
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
|
||||
cursor.getString(cursor.getColumnIndex(PHOTOURI)),
|
||||
cursor.getString(cursor.getColumnIndex(SYSTEMACCOUNT)),
|
||||
cursor.getString(cursor.getColumnIndex(KEYS)),
|
||||
cursor.getString(cursor.getColumnIndex(AVATAR)),
|
||||
lastseen,
|
||||
cursor.getString(cursor.getColumnIndex(GROUPS)));
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
if (this.systemName != null) {
|
||||
return this.systemName;
|
||||
|
@ -103,33 +122,43 @@ public class Contact implements ListItem {
|
|||
@Override
|
||||
public List<Tag> getTags() {
|
||||
ArrayList<Tag> tags = new ArrayList<Tag>();
|
||||
for(String group : getGroups()) {
|
||||
for (String group : getGroups()) {
|
||||
tags.add(new Tag(group, UIHelper.getColorForName(group)));
|
||||
}
|
||||
int status = getMostAvailableStatus();
|
||||
switch (getMostAvailableStatus()) {
|
||||
case Presences.CHAT:
|
||||
case Presences.ONLINE:
|
||||
tags.add(new Tag("online",0xff259b24));
|
||||
tags.add(new Tag("online", 0xff259b24));
|
||||
break;
|
||||
case Presences.AWAY:
|
||||
tags.add(new Tag("away",0xffff9800));
|
||||
tags.add(new Tag("away", 0xffff9800));
|
||||
break;
|
||||
case Presences.XA:
|
||||
tags.add(new Tag("not available",0xffe51c23));
|
||||
tags.add(new Tag("not available", 0xffe51c23));
|
||||
break;
|
||||
case Presences.DND:
|
||||
tags.add(new Tag("dnd",0xffe51c23));
|
||||
tags.add(new Tag("dnd", 0xffe51c23));
|
||||
break;
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
public boolean match(String needle) {
|
||||
return needle == null
|
||||
|| jid.toString().contains(needle.toLowerCase())
|
||||
|| getDisplayName().toLowerCase()
|
||||
.contains(needle.toLowerCase());
|
||||
if (needle == null) {
|
||||
return true;
|
||||
}
|
||||
needle = needle.toLowerCase();
|
||||
return jid.toString().contains(needle) || getDisplayName().toLowerCase().contains(needle) || matchInTag(needle);
|
||||
}
|
||||
|
||||
private boolean matchInTag(String needle) {
|
||||
for (Tag tag : getTags()) {
|
||||
if (tag.getName().toLowerCase().contains(needle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ContentValues getContentValues() {
|
||||
|
@ -145,40 +174,16 @@ public class Contact implements ListItem {
|
|||
values.put(AVATAR, avatar);
|
||||
values.put(LAST_PRESENCE, lastseen.presence);
|
||||
values.put(LAST_TIME, lastseen.time);
|
||||
values.put(GROUPS,groups.toString());
|
||||
values.put(GROUPS, groups.toString());
|
||||
return values;
|
||||
}
|
||||
|
||||
public static Contact fromCursor(final Cursor cursor) {
|
||||
final Lastseen lastseen = new Lastseen(
|
||||
cursor.getString(cursor.getColumnIndex(LAST_PRESENCE)),
|
||||
cursor.getLong(cursor.getColumnIndex(LAST_TIME)));
|
||||
final Jid jid;
|
||||
try {
|
||||
jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(JID)));
|
||||
} catch (final InvalidJidException e) {
|
||||
// TODO: Borked DB... handle this somehow?
|
||||
return null;
|
||||
}
|
||||
return new Contact(cursor.getString(cursor.getColumnIndex(ACCOUNT)),
|
||||
cursor.getString(cursor.getColumnIndex(SYSTEMNAME)),
|
||||
cursor.getString(cursor.getColumnIndex(SERVERNAME)),
|
||||
jid,
|
||||
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
|
||||
cursor.getString(cursor.getColumnIndex(PHOTOURI)),
|
||||
cursor.getString(cursor.getColumnIndex(SYSTEMACCOUNT)),
|
||||
cursor.getString(cursor.getColumnIndex(KEYS)),
|
||||
cursor.getString(cursor.getColumnIndex(AVATAR)),
|
||||
lastseen,
|
||||
cursor.getString(cursor.getColumnIndex(GROUPS)));
|
||||
}
|
||||
|
||||
public int getSubscription() {
|
||||
return this.subscription;
|
||||
}
|
||||
|
||||
public void setSystemAccount(String account) {
|
||||
this.systemAccount = account;
|
||||
public Account getAccount() {
|
||||
return this.account;
|
||||
}
|
||||
|
||||
public void setAccount(Account account) {
|
||||
|
@ -186,14 +191,14 @@ public class Contact implements ListItem {
|
|||
this.accountUuid = account.getUuid();
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return this.account;
|
||||
}
|
||||
|
||||
public Presences getPresences() {
|
||||
return this.presences;
|
||||
}
|
||||
|
||||
public void setPresences(Presences pres) {
|
||||
this.presences = pres;
|
||||
}
|
||||
|
||||
public void updatePresence(String resource, int status) {
|
||||
this.presences.updatePresence(resource, status);
|
||||
}
|
||||
|
@ -211,10 +216,6 @@ public class Contact implements ListItem {
|
|||
return this.presences.getMostAvailableStatus();
|
||||
}
|
||||
|
||||
public void setPresences(Presences pres) {
|
||||
this.presences = pres;
|
||||
}
|
||||
|
||||
public void setPhotoUri(String uri) {
|
||||
this.photoUri = uri;
|
||||
}
|
||||
|
@ -235,9 +236,13 @@ public class Contact implements ListItem {
|
|||
return systemAccount;
|
||||
}
|
||||
|
||||
public void setSystemAccount(String account) {
|
||||
this.systemAccount = account;
|
||||
}
|
||||
|
||||
public List<String> getGroups() {
|
||||
ArrayList<String> groups = new ArrayList<String>();
|
||||
for(int i = 0; i < this.groups.length(); ++i) {
|
||||
for (int i = 0; i < this.groups.length(); ++i) {
|
||||
try {
|
||||
groups.add(this.groups.getString(i));
|
||||
} catch (final JSONException ignored) {
|
||||
|
@ -282,14 +287,6 @@ public class Contact implements ListItem {
|
|||
}
|
||||
}
|
||||
|
||||
public void setPgpKeyId(long keyId) {
|
||||
try {
|
||||
this.keys.put("pgp_keyid", keyId);
|
||||
} catch (final JSONException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public long getPgpKeyId() {
|
||||
if (this.keys.has("pgp_keyid")) {
|
||||
try {
|
||||
|
@ -302,6 +299,14 @@ public class Contact implements ListItem {
|
|||
}
|
||||
}
|
||||
|
||||
public void setPgpKeyId(long keyId) {
|
||||
try {
|
||||
this.keys.put("pgp_keyid", keyId);
|
||||
} catch (final JSONException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void setOption(int option) {
|
||||
this.subscription |= 1 << option;
|
||||
}
|
||||
|
@ -359,7 +364,7 @@ public class Contact implements ListItem {
|
|||
|
||||
public void parseGroupsFromElement(Element item) {
|
||||
this.groups = new JSONArray();
|
||||
for(Element element : item.getChildren()) {
|
||||
for (Element element : item.getChildren()) {
|
||||
if (element.getName().equals("group") && element.getContent() != null) {
|
||||
this.groups.put(element.getContent());
|
||||
}
|
||||
|
@ -372,37 +377,12 @@ public class Contact implements ListItem {
|
|||
if (this.serverName != null) {
|
||||
item.setAttribute("name", this.serverName);
|
||||
}
|
||||
for(String group : getGroups()) {
|
||||
for (String group : getGroups()) {
|
||||
item.addChild("group").setContent(group);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public class Options {
|
||||
public static final int TO = 0;
|
||||
public static final int FROM = 1;
|
||||
public static final int ASKING = 2;
|
||||
public static final int PREEMPTIVE_GRANT = 3;
|
||||
public static final int IN_ROSTER = 4;
|
||||
public static final int PENDING_SUBSCRIPTION_REQUEST = 5;
|
||||
public static final int DIRTY_PUSH = 6;
|
||||
public static final int DIRTY_DELETE = 7;
|
||||
}
|
||||
|
||||
public static class Lastseen {
|
||||
public long time;
|
||||
public String presence;
|
||||
|
||||
public Lastseen() {
|
||||
time = 0;
|
||||
presence = null;
|
||||
}
|
||||
public Lastseen(final String presence, final long time) {
|
||||
this.time = time;
|
||||
this.presence = presence;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final ListItem another) {
|
||||
return this.getDisplayName().compareToIgnoreCase(
|
||||
|
@ -455,9 +435,35 @@ public class Contact implements ListItem {
|
|||
public String getShareableUri() {
|
||||
if (getOtrFingerprints().size() >= 1) {
|
||||
String otr = getOtrFingerprints().get(0);
|
||||
return "xmpp:"+getJid().toBareJid().toString()+"?otr-fingerprint="+otr.replace(" ","");
|
||||
return "xmpp:" + getJid().toBareJid().toString() + "?otr-fingerprint=" + otr.replace(" ", "");
|
||||
} else {
|
||||
return "xmpp:"+getJid().toBareJid().toString();
|
||||
return "xmpp:" + getJid().toBareJid().toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Lastseen {
|
||||
public long time;
|
||||
public String presence;
|
||||
|
||||
public Lastseen() {
|
||||
time = 0;
|
||||
presence = null;
|
||||
}
|
||||
|
||||
public Lastseen(final String presence, final long time) {
|
||||
this.time = time;
|
||||
this.presence = presence;
|
||||
}
|
||||
}
|
||||
|
||||
public class Options {
|
||||
public static final int TO = 0;
|
||||
public static final int FROM = 1;
|
||||
public static final int ASKING = 2;
|
||||
public static final int PREEMPTIVE_GRANT = 3;
|
||||
public static final int IN_ROSTER = 4;
|
||||
public static final int PENDING_SUBSCRIPTION_REQUEST = 5;
|
||||
public static final int DIRTY_PUSH = 6;
|
||||
public static final int DIRTY_DELETE = 7;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue