aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/entities
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-11-16 23:58:30 +0100
committeriNPUTmice <daniel@gultsch.de>2014-11-16 23:58:30 +0100
commit2036c58cd7793c25ce227bdc44f0377b07be45e1 (patch)
tree0bbe6db7d6e0043eed032cd36812bec47bf14598 /src/main/java/eu/siacs/conversations/entities
parent8c4236b01bc1d594ee80909e8a84b5b672e86725 (diff)
made tags searchable
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Bookmark.java93
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Contact.java244
2 files changed, 180 insertions, 157 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Bookmark.java b/src/main/java/eu/siacs/conversations/entities/Bookmark.java
index 862523a5b..2156ab2ce 100644
--- a/src/main/java/eu/siacs/conversations/entities/Bookmark.java
+++ b/src/main/java/eu/siacs/conversations/entities/Bookmark.java
@@ -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,30 +39,11 @@ 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(
- another.getDisplayName());
- }
+ return this.getDisplayName().compareToIgnoreCase(
+ another.getDisplayName());
+ }
@Override
public String getDisplayName() {
@@ -80,19 +61,26 @@ public class Bookmark extends Element implements ListItem {
public Jid getJid() {
final String jid = this.getAttribute("jid");
if (jid != null) {
- try {
- return Jid.fromString(jid);
- } catch (final InvalidJidException e) {
- return null;
- }
- } else {
+ try {
+ return Jid.fromString(jid);
+ } catch (final InvalidJidException e) {
+ return null;
+ }
+ } else {
return null;
}
}
@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);
}
- public Account getAccount() {
- return this.account;
+ private boolean matchInTag(String needle) {
+ for (Tag tag : getTags()) {
+ if (tag.getName().toLowerCase().contains(needle)) {
+ return true;
+ }
+ }
+ return false;
}
- public void setConversation(Conversation conversation) {
- this.mJoinedConversation = conversation;
+ public Account getAccount() {
+ return this.account;
}
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();
diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java
index 6046abefd..99a749072 100644
--- a/src/main/java/eu/siacs/conversations/entities/Contact.java
+++ b/src/main/java/eu/siacs/conversations/entities/Contact.java
@@ -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;
@@ -29,10 +27,10 @@ public class Contact implements ListItem {
public static final String KEYS = "pgpkey";
public static final String ACCOUNT = "accountUuid";
public static final String AVATAR = "avatar";
- public static final String LAST_PRESENCE = "last_presence";
- public static final String LAST_TIME = "last_time";
+ 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,14 +43,11 @@ 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) {
+ final Jid jid, final int subscription, final String photoUri,
+ final String systemAccount, final String keys, final String avatar, final Lastseen lastseen, final String groups) {
this.accountUuid = account;
this.systemName = systemName;
this.serverName = serverName;
@@ -78,18 +73,42 @@ 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;
- } else if (this.serverName != null) {
- return this.serverName;
+ return this.systemName;
+ } else if (this.serverName != null) {
+ return this.serverName;
} else if (this.presenceName != null) {
- return this.presenceName;
+ return this.presenceName;
} else if (jid.hasLocalpart()) {
- return jid.getLocalpart();
+ return jid.getLocalpart();
} else {
- return jid.getDomainpart();
- }
+ return jid.getDomainpart();
+ }
}
public String getProfilePhoto() {
@@ -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;
}
@@ -325,26 +330,26 @@ public class Contact implements ListItem {
String subscription = item.getAttribute("subscription");
if (subscription != null) {
- switch (subscription) {
- case "to":
- this.resetOption(Options.FROM);
- this.setOption(Options.TO);
- break;
- case "from":
- this.resetOption(Options.TO);
- this.setOption(Options.FROM);
- this.resetOption(Options.PREEMPTIVE_GRANT);
- break;
- case "both":
- this.setOption(Options.TO);
- this.setOption(Options.FROM);
- this.resetOption(Options.PREEMPTIVE_GRANT);
- break;
- case "none":
- this.resetOption(Options.FROM);
- this.resetOption(Options.TO);
- break;
- }
+ switch (subscription) {
+ case "to":
+ this.resetOption(Options.FROM);
+ this.setOption(Options.TO);
+ break;
+ case "from":
+ this.resetOption(Options.TO);
+ this.setOption(Options.FROM);
+ this.resetOption(Options.PREEMPTIVE_GRANT);
+ break;
+ case "both":
+ this.setOption(Options.TO);
+ this.setOption(Options.FROM);
+ this.resetOption(Options.PREEMPTIVE_GRANT);
+ break;
+ case "none":
+ this.resetOption(Options.FROM);
+ this.resetOption(Options.TO);
+ break;
+ }
}
// do NOT override asking if pending push request
@@ -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;
+ }
}