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 int STATUS_RECIEVED = 0;
11	public static final int STATUS_UNSEND = 1;
12	public static final int STATUS_SEND = 2;
13
14	public static final int ENCRYPTION_NONE = 0;
15	public static final int ENCRYPTION_PGP = 1;
16	public static final int ENCRYPTION_OTR = 2;
17
18	public static String CONVERSATION = "conversationUuid";
19	public static String COUNTERPART = "counterpart";
20	public static String BODY = "body";
21	public static String TIME_SENT = "timeSent";
22	public static String ENCRYPTION = "encryption";
23	public static String STATUS = "status";
24
25	protected String conversationUuid;
26	protected String counterpart;
27	protected String body;
28	protected long timeSent;
29	protected int encryption;
30	protected int status;
31
32	protected transient Conversation conversation = null;
33
34	public Message(Conversation conversation, String body, int encryption) {
35		this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
36				conversation.getContactJid(), body, 0, encryption,
37				Message.STATUS_UNSEND);
38	}
39
40	public Message(String uuid, String conversationUUid, String counterpart,
41			String body, long timeSent, int encryption, int status) {
42		this.uuid = uuid;
43		this.conversationUuid = conversationUUid;
44		this.counterpart = counterpart;
45		this.body = body;
46		this.timeSent = timeSent;
47		this.encryption = encryption;
48		this.status = status;
49	}
50
51	@Override
52	public ContentValues getContentValues() {
53		ContentValues values = new ContentValues();
54		values.put(UUID, this.uuid);
55		values.put(CONVERSATION, conversationUuid);
56		values.put(COUNTERPART, counterpart);
57		values.put(BODY, body);
58		values.put(TIME_SENT, timeSent);
59		values.put(ENCRYPTION, encryption);
60		values.put(STATUS, status);
61		return values;
62	}
63
64	public String getConversationUuid() {
65		return conversationUuid;
66	}
67
68	public String getCounterpart() {
69		return counterpart;
70	}
71
72	public String getBody() {
73		return body;
74	}
75
76	public long getTimeSent() {
77		return timeSent;
78	}
79
80	public int getEncryption() {
81		return encryption;
82	}
83
84	public int getStatus() {
85		return status;
86	}
87
88	public static Message fromCursor(Cursor cursor) {
89		return new Message(cursor.getString(cursor.getColumnIndex(UUID)),
90				cursor.getString(cursor.getColumnIndex(CONVERSATION)),
91				cursor.getString(cursor.getColumnIndex(COUNTERPART)),
92				cursor.getString(cursor.getColumnIndex(BODY)),
93				cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
94				cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
95				cursor.getInt(cursor.getColumnIndex(STATUS)));
96	}
97
98}