Message.java

  1package de.gultsch.chat.entities;
  2
  3import android.content.ContentValues;
  4import android.database.Cursor;
  5
  6public class Message extends AbstractEntity {
  7
  8	private static final long serialVersionUID = 7222081895167103025L;
  9	
 10	public static final String TABLENAME = "messages";
 11
 12	public static final int STATUS_RECIEVED = 0;
 13	public static final int STATUS_UNSEND = 1;
 14	public static final int STATUS_SEND = 2;
 15
 16	public static final int ENCRYPTION_NONE = 0;
 17	public static final int ENCRYPTION_PGP = 1;
 18	public static final int ENCRYPTION_OTR = 2;
 19
 20	public static String CONVERSATION = "conversationUuid";
 21	public static String COUNTERPART = "counterpart";
 22	public static String BODY = "body";
 23	public static String TIME_SENT = "timeSent";
 24	public static String ENCRYPTION = "encryption";
 25	public static String STATUS = "status";
 26
 27	protected String conversationUuid;
 28	protected String counterpart;
 29	protected String body;
 30	protected long timeSent;
 31	protected int encryption;
 32	protected int status;
 33
 34	protected transient Conversation conversation = null;
 35
 36	public Message(Conversation conversation, String body, int encryption) {
 37		this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
 38				conversation.getContactJid(), body, System.currentTimeMillis(), encryption,
 39				Message.STATUS_UNSEND);
 40		this.conversation = conversation;
 41	}
 42
 43	public Message(String uuid, String conversationUUid, String counterpart,
 44			String body, long timeSent, int encryption, int status) {
 45		this.uuid = uuid;
 46		this.conversationUuid = conversationUUid;
 47		this.counterpart = counterpart;
 48		this.body = body;
 49		this.timeSent = timeSent;
 50		this.encryption = encryption;
 51		this.status = status;
 52	}
 53
 54	@Override
 55	public ContentValues getContentValues() {
 56		ContentValues values = new ContentValues();
 57		values.put(UUID, this.uuid);
 58		values.put(CONVERSATION, conversationUuid);
 59		values.put(COUNTERPART, counterpart);
 60		values.put(BODY, body);
 61		values.put(TIME_SENT, timeSent);
 62		values.put(ENCRYPTION, encryption);
 63		values.put(STATUS, status);
 64		return values;
 65	}
 66
 67	public String getConversationUuid() {
 68		return conversationUuid;
 69	}
 70	
 71	public Conversation getConversation() {
 72		return this.conversation;
 73	}
 74
 75	public String getCounterpart() {
 76		return counterpart;
 77	}
 78
 79	public String getBody() {
 80		return body;
 81	}
 82
 83	public long getTimeSent() {
 84		return timeSent;
 85	}
 86
 87	public int getEncryption() {
 88		return encryption;
 89	}
 90
 91	public int getStatus() {
 92		return status;
 93	}
 94
 95	public static Message fromCursor(Cursor cursor) {
 96		return new Message(cursor.getString(cursor.getColumnIndex(UUID)),
 97				cursor.getString(cursor.getColumnIndex(CONVERSATION)),
 98				cursor.getString(cursor.getColumnIndex(COUNTERPART)),
 99				cursor.getString(cursor.getColumnIndex(BODY)),
100				cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
101				cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
102				cursor.getInt(cursor.getColumnIndex(STATUS)));
103	}
104
105	public void setConversation(Conversation conv) {
106		this.conversation = conv;
107	}
108
109}