1package de.gultsch.chat.entities;
2
3import java.io.Serializable;
4
5import android.content.ContentValues;
6import android.database.Cursor;
7
8public class Contact extends AbstractEntity implements Serializable {
9 private static final long serialVersionUID = -4570817093119419962L;
10
11
12 public static final String TABLENAME = "contacts";
13
14 public static final String DISPLAYNAME = "name";
15 public static final String JID = "jid";
16 public static final String SUBSCRIPTION = "subscription";
17 public static final String SYSTEMACCOUNT = "systemaccount";
18 public static final String PHOTOURI = "photouri";
19 public static final String OPENPGPKEY = "pgpkey";
20 public static final String LASTONLINEPRESENCE = "presence";
21 public static final String ACCOUNT = "accountUuid";
22
23 protected String accountUuid;
24 protected String displayName;
25 protected String jid;
26 protected String subscription;
27 protected int systemAccount;
28 protected String photoUri;
29 protected String openPGPKey;
30 protected long lastOnlinePresence;
31
32 public Contact(Account account, String displayName, String jid, String photoUri) {
33 if (account == null) {
34 this.accountUuid = null;
35 } else {
36 this.accountUuid = account.getUuid();
37 }
38 this.displayName = displayName;
39 this.jid = jid;
40 this.photoUri = photoUri;
41 }
42
43 public Contact(String uuid, String account, String displayName, String jid, String subscription, String photoUri, int systemAccount, String pgpKey, long lastseen) {
44 this.uuid = uuid;
45 this.accountUuid = account;
46 this.displayName = displayName;
47 this.jid = jid;
48 this.subscription = subscription;
49 this.photoUri = photoUri;
50 this.systemAccount = systemAccount;
51 this.openPGPKey = pgpKey;
52 this.lastOnlinePresence = lastseen;
53 }
54
55 public String getDisplayName() {
56 return this.displayName;
57 }
58
59 public String getProfilePhoto() {
60 return this.photoUri;
61 }
62
63 public String getJid() {
64 return this.jid;
65 }
66
67 public boolean match(String needle) {
68 return (jid.toLowerCase().contains(needle.toLowerCase()) || (displayName.toLowerCase().contains(needle.toLowerCase())));
69 }
70
71 @Override
72 public ContentValues getContentValues() {
73 ContentValues values = new ContentValues();
74 values.put(UUID,uuid);
75 values.put(ACCOUNT,accountUuid);
76 values.put(DISPLAYNAME, displayName);
77 values.put(JID, jid);
78 values.put(SUBSCRIPTION,subscription);
79 values.put(SYSTEMACCOUNT, systemAccount);
80 values.put(PHOTOURI,photoUri);
81 values.put(OPENPGPKEY,openPGPKey);
82 values.put(LASTONLINEPRESENCE,lastOnlinePresence);
83 return values;
84 }
85
86 public static Contact fromCursor(Cursor cursor) {
87 return new Contact(cursor.getString(cursor.getColumnIndex(UUID)),
88 cursor.getString(cursor.getColumnIndex(ACCOUNT)),
89 cursor.getString(cursor.getColumnIndex(DISPLAYNAME)),
90 cursor.getString(cursor.getColumnIndex(JID)),
91 cursor.getString(cursor.getColumnIndex(SUBSCRIPTION)),
92 cursor.getString(cursor.getColumnIndex(PHOTOURI)),
93 cursor.getInt(cursor.getColumnIndex(SYSTEMACCOUNT)),
94 cursor.getString(cursor.getColumnIndex(OPENPGPKEY)),
95 cursor.getLong(cursor.getColumnIndex(LASTONLINEPRESENCE))
96 );
97 }
98}