aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/entities
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/de/gultsch/chat/entities/AbstractEntity.java21
-rw-r--r--src/de/gultsch/chat/entities/Account.java15
-rw-r--r--src/de/gultsch/chat/entities/Conversation.java67
-rw-r--r--src/de/gultsch/chat/entities/Message.java99
4 files changed, 158 insertions, 44 deletions
diff --git a/src/de/gultsch/chat/entities/AbstractEntity.java b/src/de/gultsch/chat/entities/AbstractEntity.java
new file mode 100644
index 00000000..d62385a6
--- /dev/null
+++ b/src/de/gultsch/chat/entities/AbstractEntity.java
@@ -0,0 +1,21 @@
+package de.gultsch.chat.entities;
+
+import java.io.Serializable;
+
+import android.content.ContentValues;
+
+public abstract class AbstractEntity implements Serializable {
+
+ private static final long serialVersionUID = -1895605706690653719L;
+
+ public static final String UUID = "uuid";
+
+ protected String uuid;
+
+ public String getUuid() {
+ return this.uuid;
+ }
+
+ public abstract ContentValues getContentValues();
+
+}
diff --git a/src/de/gultsch/chat/entities/Account.java b/src/de/gultsch/chat/entities/Account.java
index f1e15f0b..5b83ca79 100644
--- a/src/de/gultsch/chat/entities/Account.java
+++ b/src/de/gultsch/chat/entities/Account.java
@@ -1,11 +1,18 @@
package de.gultsch.chat.entities;
-public class Account {
+import android.content.ContentValues;
- private String uuid;
+public class Account extends AbstractEntity{
- public String getUuid() {
- return this.uuid;
+ private static final long serialVersionUID = 6174825093869578035L;
+
+ public Account() {
+ this.uuid = "";
+ }
+ @Override
+ public ContentValues getContentValues() {
+ // TODO Auto-generated method stub
+ return null;
}
}
diff --git a/src/de/gultsch/chat/entities/Conversation.java b/src/de/gultsch/chat/entities/Conversation.java
index 92d5bcba..2dd8a049 100644
--- a/src/de/gultsch/chat/entities/Conversation.java
+++ b/src/de/gultsch/chat/entities/Conversation.java
@@ -1,56 +1,62 @@
package de.gultsch.chat.entities;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.UUID;
+import java.util.List;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
-public class Conversation implements Serializable {
+public class Conversation extends AbstractEntity {
private static final long serialVersionUID = -6727528868973996739L;
public static final int STATUS_AVAILABLE = 0;
public static final int STATUS_ARCHIVED = 1;
public static final int STATUS_DELETED = 2;
- private String uuid;
+
+ public static final String NAME = "name";
+ public static final String PHOTO_URI = "profilePhotoUri";
+ public static final String ACCOUNT = "accountUuid";
+ public static final String CONTACT = "contactJid";
+ public static final String STATUS = "status";
+ public static final String CREATED = "created";
+
private String name;
private String profilePhotoUri;
private String accountUuid;
private String contactJid;
private int status;
+ private long created;
- // legacy. to be removed
- private ArrayList<Message> msgs = new ArrayList<Message>();
+ private transient List<Message> messages;
public Conversation(String name, Uri profilePhoto, Account account,
String contactJid) {
- this(UUID.randomUUID().toString(), name, profilePhoto.toString(),
- account.getUuid(), contactJid, STATUS_AVAILABLE);
+ this(java.util.UUID.randomUUID().toString(), name, profilePhoto
+ .toString(), account.getUuid(), contactJid, System
+ .currentTimeMillis(), STATUS_AVAILABLE);
}
public Conversation(String uuid, String name, String profilePhoto,
- String accountUuid, String contactJid, int status) {
+ String accountUuid, String contactJid, long created, int status) {
this.uuid = uuid;
this.name = name;
this.profilePhotoUri = profilePhoto;
this.accountUuid = accountUuid;
this.contactJid = contactJid;
+ this.created = created;
this.status = status;
}
- public ArrayList<Message> getLastMessages(int count, int offset) {
- msgs.add(new Message("this is my last message"));
- return msgs;
+ public List<Message> getMessages() {
+ return messages;
}
- public String getName() {
- return this.name;
+ public void setMessages(List<Message> msgs) {
+ this.messages = msgs;
}
- public String getUuid() {
- return this.uuid;
+ public String getName() {
+ return this.name;
}
public String getProfilePhotoString() {
@@ -78,22 +84,23 @@ public class Conversation implements Serializable {
public ContentValues getContentValues() {
ContentValues values = new ContentValues();
- values.put("uuid", this.uuid);
- values.put("name", this.name);
- values.put("profilePhotoUri", this.profilePhotoUri);
- values.put("accountUuid", this.accountUuid);
- values.put("contactJid", this.contactJid);
- values.put("status", this.status);
+ values.put(UUID, uuid);
+ values.put(NAME, name);
+ values.put(PHOTO_URI, profilePhotoUri);
+ values.put(ACCOUNT, accountUuid);
+ values.put(CONTACT, contactJid);
+ values.put(CREATED, created);
+ values.put(STATUS, status);
return values;
}
public static Conversation fromCursor(Cursor cursor) {
- return new Conversation(
- cursor.getString(cursor.getColumnIndex("uuid")),
- cursor.getString(cursor.getColumnIndex("name")),
- cursor.getString(cursor.getColumnIndex("profilePhotoUri")),
- cursor.getString(cursor.getColumnIndex("accountUuid")),
- cursor.getString(cursor.getColumnIndex("contactJid")),
- cursor.getInt(cursor.getColumnIndex("status")));
+ return new Conversation(cursor.getString(cursor.getColumnIndex(UUID)),
+ cursor.getString(cursor.getColumnIndex(NAME)),
+ cursor.getString(cursor.getColumnIndex(PHOTO_URI)),
+ cursor.getString(cursor.getColumnIndex(ACCOUNT)),
+ cursor.getString(cursor.getColumnIndex(CONTACT)),
+ cursor.getLong(cursor.getColumnIndex(CREATED)),
+ cursor.getInt(cursor.getColumnIndex(STATUS)));
}
}
diff --git a/src/de/gultsch/chat/entities/Message.java b/src/de/gultsch/chat/entities/Message.java
index 3b4e2115..5e5cfbe4 100644
--- a/src/de/gultsch/chat/entities/Message.java
+++ b/src/de/gultsch/chat/entities/Message.java
@@ -1,19 +1,98 @@
package de.gultsch.chat.entities;
-public class Message {
+import android.content.ContentValues;
+import android.database.Cursor;
- String msg;
-
- public Message(String msg) {
- this.msg = msg;
+public class Message extends AbstractEntity {
+
+ private static final long serialVersionUID = 7222081895167103025L;
+
+ public static final int STATUS_RECIEVED = 0;
+ public static final int STATUS_UNSEND = 1;
+ public static final int STATUS_SEND = 2;
+
+ public static final int ENCRYPTION_NONE = 0;
+ public static final int ENCRYPTION_PGP = 1;
+ public static final int ENCRYPTION_OTR = 2;
+
+ public static String CONVERSATION = "conversationUuid";
+ public static String COUNTERPART = "counterpart";
+ public static String BODY = "body";
+ public static String TIME_SENT = "timeSent";
+ public static String ENCRYPTION = "encryption";
+ public static String STATUS = "status";
+
+ protected String conversationUuid;
+ protected String counterpart;
+ protected String body;
+ protected long timeSent;
+ protected int encryption;
+ protected int status;
+
+ protected transient Conversation conversation = null;
+
+ public Message(Conversation conversation, String body, int encryption) {
+ this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
+ conversation.getContactJid(), body, 0, encryption,
+ Message.STATUS_UNSEND);
+ }
+
+ public Message(String uuid, String conversationUUid, String counterpart,
+ String body, long timeSent, int encryption, int status) {
+ this.uuid = uuid;
+ this.conversationUuid = conversationUUid;
+ this.counterpart = counterpart;
+ this.body = body;
+ this.timeSent = timeSent;
+ this.encryption = encryption;
+ this.status = status;
+ }
+
+ @Override
+ public ContentValues getContentValues() {
+ ContentValues values = new ContentValues();
+ values.put(UUID, this.uuid);
+ values.put(CONVERSATION, conversationUuid);
+ values.put(COUNTERPART, counterpart);
+ values.put(BODY, body);
+ values.put(TIME_SENT, timeSent);
+ values.put(ENCRYPTION, encryption);
+ values.put(STATUS, status);
+ return values;
}
-
- public String toString() {
- return msg;
+
+ public String getConversationUuid() {
+ return conversationUuid;
+ }
+
+ public String getCounterpart() {
+ return counterpart;
+ }
+
+ public String getBody() {
+ return body;
+ }
+
+ public long getTimeSent() {
+ return timeSent;
+ }
+
+ public int getEncryption() {
+ return encryption;
+ }
+
+ public int getStatus() {
+ return status;
}
- public String getTimeReadable() {
- return "2 min";
+ public static Message fromCursor(Cursor cursor) {
+ return new Message(cursor.getString(cursor.getColumnIndex(UUID)),
+ cursor.getString(cursor.getColumnIndex(CONVERSATION)),
+ cursor.getString(cursor.getColumnIndex(COUNTERPART)),
+ cursor.getString(cursor.getColumnIndex(BODY)),
+ cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
+ cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
+ cursor.getInt(cursor.getColumnIndex(STATUS)));
}
}