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, 0, encryption,
 39				Message.STATUS_UNSEND);
 40	}
 41
 42	public Message(String uuid, String conversationUUid, String counterpart,
 43			String body, long timeSent, int encryption, int status) {
 44		this.uuid = uuid;
 45		this.conversationUuid = conversationUUid;
 46		this.counterpart = counterpart;
 47		this.body = body;
 48		this.timeSent = timeSent;
 49		this.encryption = encryption;
 50		this.status = status;
 51	}
 52
 53	@Override
 54	public ContentValues getContentValues() {
 55		ContentValues values = new ContentValues();
 56		values.put(UUID, this.uuid);
 57		values.put(CONVERSATION, conversationUuid);
 58		values.put(COUNTERPART, counterpart);
 59		values.put(BODY, body);
 60		values.put(TIME_SENT, timeSent);
 61		values.put(ENCRYPTION, encryption);
 62		values.put(STATUS, status);
 63		return values;
 64	}
 65
 66	public String getConversationUuid() {
 67		return conversationUuid;
 68	}
 69
 70	public String getCounterpart() {
 71		return counterpart;
 72	}
 73
 74	public String getBody() {
 75		return body;
 76	}
 77
 78	public long getTimeSent() {
 79		return timeSent;
 80	}
 81
 82	public int getEncryption() {
 83		return encryption;
 84	}
 85
 86	public int getStatus() {
 87		return status;
 88	}
 89
 90	public static Message fromCursor(Cursor cursor) {
 91		return new Message(cursor.getString(cursor.getColumnIndex(UUID)),
 92				cursor.getString(cursor.getColumnIndex(CONVERSATION)),
 93				cursor.getString(cursor.getColumnIndex(COUNTERPART)),
 94				cursor.getString(cursor.getColumnIndex(BODY)),
 95				cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
 96				cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
 97				cursor.getInt(cursor.getColumnIndex(STATUS)));
 98	}
 99
100}