Contact.java

  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
 33	protected Account account;
 34	
 35	public Contact(Account account, String displayName, String jid, String photoUri) {
 36		if (account == null) {
 37			this.accountUuid = null;
 38		} else {
 39			this.accountUuid = account.getUuid();
 40		}
 41		this.displayName = displayName;
 42		this.jid = jid;
 43		this.photoUri = photoUri;
 44	}
 45	
 46	public Contact(String uuid, String account, String displayName, String jid, String subscription, String photoUri, int systemAccount, String pgpKey, long lastseen) {
 47		this.uuid = uuid;
 48		this.accountUuid = account;
 49		this.displayName = displayName;
 50		this.jid = jid;
 51		this.subscription = subscription;
 52		this.photoUri = photoUri;
 53		this.systemAccount = systemAccount;
 54		this.openPGPKey = pgpKey;
 55		this.lastOnlinePresence = lastseen;
 56	}
 57
 58	public String getDisplayName() {
 59		return this.displayName;
 60	}
 61
 62	public String getProfilePhoto() {
 63		return this.photoUri;
 64	}
 65	
 66	public String getJid() {
 67		return this.jid;
 68	}
 69	
 70	public boolean match(String needle) {
 71		return (jid.toLowerCase().contains(needle.toLowerCase()) || (displayName.toLowerCase().contains(needle.toLowerCase())));
 72	}
 73
 74	@Override
 75	public ContentValues getContentValues() {
 76		ContentValues values = new ContentValues();
 77		values.put(UUID,uuid);
 78		values.put(ACCOUNT,accountUuid);
 79		values.put(DISPLAYNAME, displayName);
 80		values.put(JID, jid);
 81		values.put(SUBSCRIPTION,subscription);
 82		values.put(SYSTEMACCOUNT, systemAccount);
 83		values.put(PHOTOURI,photoUri);
 84		values.put(OPENPGPKEY,openPGPKey);
 85		values.put(LASTONLINEPRESENCE,lastOnlinePresence);
 86		return values;
 87	}
 88	
 89	public static Contact fromCursor(Cursor cursor) {
 90		return new Contact(cursor.getString(cursor.getColumnIndex(UUID)),
 91				cursor.getString(cursor.getColumnIndex(ACCOUNT)),
 92				cursor.getString(cursor.getColumnIndex(DISPLAYNAME)),
 93				cursor.getString(cursor.getColumnIndex(JID)),
 94				cursor.getString(cursor.getColumnIndex(SUBSCRIPTION)),
 95				cursor.getString(cursor.getColumnIndex(PHOTOURI)),
 96				cursor.getInt(cursor.getColumnIndex(SYSTEMACCOUNT)),
 97				cursor.getString(cursor.getColumnIndex(OPENPGPKEY)),
 98				cursor.getLong(cursor.getColumnIndex(LASTONLINEPRESENCE))
 99				);
100	}
101
102	public void setSubscription(String subscription) {
103		this.subscription = subscription;
104	}
105
106	public void setSystemAccount(int account) {
107		this.systemAccount = account;
108	}
109
110	public void setAccount(Account account) {
111		this.account = account;
112		this.accountUuid = account.getUuid();
113	}
114
115	public Account getAccount() {
116		return this.account;
117	}
118
119	public void setUuid(String uuid) {
120		this.uuid = uuid;
121	}
122}