Conversation.java

 1package de.gultsch.chat.entities;
 2
 3import java.io.Serializable;
 4import java.util.ArrayList;
 5import java.util.UUID;
 6
 7import android.content.ContentValues;
 8import android.database.Cursor;
 9import android.net.Uri;
10
11public class Conversation implements Serializable {
12
13	private static final long serialVersionUID = -6727528868973996739L;
14	public static final int STATUS_AVAILABLE = 0;
15	public static final int STATUS_ARCHIVED = 1;
16	public static final int STATUS_DELETED = 2;
17	private String uuid;
18	private String name;
19	private String profilePhotoUri;
20	private String accountUuid;
21	private String contactJid;
22	private int status;
23
24	// legacy. to be removed
25	private ArrayList<Message> msgs = new ArrayList<Message>();
26
27	public Conversation(String name, Uri profilePhoto, Account account,
28			String contactJid) {
29		this(UUID.randomUUID().toString(), name, profilePhoto.toString(),
30				account.getUuid(), contactJid, STATUS_AVAILABLE);
31	}
32
33	public Conversation(String uuid, String name, String profilePhoto,
34			String accountUuid, String contactJid, int status) {
35		this.uuid = uuid;
36		this.name = name;
37		this.profilePhotoUri = profilePhoto;
38		this.accountUuid = accountUuid;
39		this.contactJid = contactJid;
40		this.status = status;
41	}
42
43	public ArrayList<Message> getLastMessages(int count, int offset) {
44		msgs.add(new Message("this is my last message"));
45		return msgs;
46	}
47
48	public String getName() {
49		return this.name;
50	}
51
52	public String getUuid() {
53		return this.uuid;
54	}
55
56	public String getProfilePhotoString() {
57		return this.profilePhotoUri;
58	}
59
60	public String getAccountUuid() {
61		return this.accountUuid;
62	}
63
64	public String getContactJid() {
65		return this.contactJid;
66	}
67
68	public Uri getProfilePhotoUri() {
69		if (this.profilePhotoUri != null) {
70			return Uri.parse(profilePhotoUri);
71		}
72		return null;
73	}
74
75	public int getStatus() {
76		return this.status;
77	}
78
79	public ContentValues getContentValues() {
80		ContentValues values = new ContentValues();
81		values.put("uuid", this.uuid);
82		values.put("name", this.name);
83		values.put("profilePhotoUri", this.profilePhotoUri);
84		values.put("accountUuid", this.accountUuid);
85		values.put("contactJid", this.contactJid);
86		values.put("status", this.status);
87		return values;
88	}
89
90	public static Conversation fromCursor(Cursor cursor) {
91		return new Conversation(
92				cursor.getString(cursor.getColumnIndex("uuid")),
93				cursor.getString(cursor.getColumnIndex("name")),
94				cursor.getString(cursor.getColumnIndex("profilePhotoUri")),
95				cursor.getString(cursor.getColumnIndex("accountUuid")),
96				cursor.getString(cursor.getColumnIndex("contactJid")),
97				cursor.getInt(cursor.getColumnIndex("status")));
98	}
99}