aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/gultsch/chat/entities')
-rw-r--r--src/de/gultsch/chat/entities/Contact.java33
-rw-r--r--src/de/gultsch/chat/entities/Presences.java76
2 files changed, 103 insertions, 6 deletions
diff --git a/src/de/gultsch/chat/entities/Contact.java b/src/de/gultsch/chat/entities/Contact.java
index 6079d9bb..da3c0810 100644
--- a/src/de/gultsch/chat/entities/Contact.java
+++ b/src/de/gultsch/chat/entities/Contact.java
@@ -1,6 +1,7 @@
package de.gultsch.chat.entities;
import java.io.Serializable;
+import java.util.Hashtable;
import android.content.ContentValues;
import android.database.Cursor;
@@ -16,7 +17,7 @@ public class Contact extends AbstractEntity implements Serializable {
public static final String SYSTEMACCOUNT = "systemaccount";
public static final String PHOTOURI = "photouri";
public static final String OPENPGPKEY = "pgpkey";
- public static final String LASTPRESENCE = "presence";
+ public static final String PRESENCES = "presences";
public static final String ACCOUNT = "accountUuid";
protected String accountUuid;
@@ -26,7 +27,7 @@ public class Contact extends AbstractEntity implements Serializable {
protected int systemAccount;
protected String photoUri;
protected String openPGPKey;
- protected long lastPresence;
+ protected Presences presences = new Presences();
protected Account account;
@@ -44,7 +45,7 @@ public class Contact extends AbstractEntity implements Serializable {
public Contact(String uuid, String account, String displayName, String jid,
String subscription, String photoUri, int systemAccount,
- String pgpKey, long lastseen) {
+ String pgpKey,String presences) {
this.uuid = uuid;
this.accountUuid = account;
this.displayName = displayName;
@@ -53,7 +54,7 @@ public class Contact extends AbstractEntity implements Serializable {
this.photoUri = photoUri;
this.systemAccount = systemAccount;
this.openPGPKey = pgpKey;
- this.lastPresence = lastseen;
+ this.presences = Presences.fromJsonString(presences);
}
public String getDisplayName() {
@@ -84,7 +85,7 @@ public class Contact extends AbstractEntity implements Serializable {
values.put(SYSTEMACCOUNT, systemAccount);
values.put(PHOTOURI, photoUri);
values.put(OPENPGPKEY, openPGPKey);
- values.put(LASTPRESENCE, lastPresence);
+ values.put(PRESENCES, presences.toJsonString());
return values;
}
@@ -97,12 +98,16 @@ public class Contact extends AbstractEntity implements Serializable {
cursor.getString(cursor.getColumnIndex(PHOTOURI)),
cursor.getInt(cursor.getColumnIndex(SYSTEMACCOUNT)),
cursor.getString(cursor.getColumnIndex(OPENPGPKEY)),
- cursor.getLong(cursor.getColumnIndex(LASTPRESENCE)));
+ cursor.getString(cursor.getColumnIndex(PRESENCES)));
}
public void setSubscription(String subscription) {
this.subscription = subscription;
}
+
+ public String getSubscription() {
+ return this.subscription;
+ }
public void setSystemAccount(int account) {
this.systemAccount = account;
@@ -136,4 +141,20 @@ public class Contact extends AbstractEntity implements Serializable {
}
}
}
+
+ public Hashtable<String, Integer> getPresences() {
+ return this.presences.getPresences();
+ }
+
+ public void updatePresence(String resource, int status) {
+ this.presences.updatePresence(resource, status);
+ }
+
+ public void removePresence(String resource) {
+ this.presences.removePresence(resource);
+ }
+
+ public int getMostAvailableStatus() {
+ return this.presences.getMostAvailableStatus();
+ }
}
diff --git a/src/de/gultsch/chat/entities/Presences.java b/src/de/gultsch/chat/entities/Presences.java
new file mode 100644
index 00000000..aabc8440
--- /dev/null
+++ b/src/de/gultsch/chat/entities/Presences.java
@@ -0,0 +1,76 @@
+package de.gultsch.chat.entities;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class Presences {
+
+ public static final int CHAT = -1;
+ public static final int ONLINE = 0;
+ public static final int AWAY = 1;
+ public static final int XA = 2;
+ public static final int DND = 3;
+ public static final int OFFLINE = 4;
+
+ private Hashtable<String, Integer> presences = new Hashtable<String, Integer>();
+
+ public Hashtable<String, Integer> getPresences() {
+ return this.presences;
+ }
+
+ public void updatePresence(String resource, int status) {
+ this.presences.put(resource, status);
+ }
+
+ public void removePresence(String resource) {
+ this.presences.remove(resource);
+ }
+
+ public int getMostAvailableStatus() {
+ int status = OFFLINE;
+ Iterator<Entry<String, Integer>> it = presences.entrySet().iterator();
+ while (it.hasNext()) {
+ Entry<String, Integer> entry = it.next();
+ if (entry.getValue()<status) status = entry.getValue();
+ }
+ return status;
+ }
+
+ public String toJsonString() {
+ JSONArray json = new JSONArray();
+ Iterator<Entry<String, Integer>> it = presences.entrySet().iterator();
+
+ while (it.hasNext()) {
+ Entry<String, Integer> entry = it.next();
+ JSONObject jObj = new JSONObject();
+ try {
+ jObj.put("resource", entry.getKey());
+ jObj.put("status", entry.getValue());
+ } catch (JSONException e) {
+
+ }
+ json.put(jObj);
+ }
+ return json.toString();
+ }
+
+ public static Presences fromJsonString(String jsonString) {
+ Presences presences = new Presences();
+ try {
+ JSONArray json = new JSONArray(jsonString);
+ for (int i = 0; i < json.length(); ++i) {
+ JSONObject jObj = json.getJSONObject(i);
+ presences.updatePresence(jObj.getString("resource"),
+ jObj.getInt("status"));
+ }
+ } catch (JSONException e1) {
+
+ }
+ return presences;
+ }
+}