From 95068ee776d9ec8e6c390133ca2bed083a46546f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 7 Feb 2014 16:50:29 +0100 Subject: reworked new conversation activity again. less asking more knowing. mucs are now connected on creation of the conversation. no reconnect required --- src/de/gultsch/chat/entities/Contact.java | 59 ++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 21 deletions(-) (limited to 'src/de/gultsch/chat/entities/Contact.java') diff --git a/src/de/gultsch/chat/entities/Contact.java b/src/de/gultsch/chat/entities/Contact.java index 3478eac7..6079d9bb 100644 --- a/src/de/gultsch/chat/entities/Contact.java +++ b/src/de/gultsch/chat/entities/Contact.java @@ -7,10 +7,9 @@ import android.database.Cursor; public class Contact extends AbstractEntity implements Serializable { private static final long serialVersionUID = -4570817093119419962L; - - + public static final String TABLENAME = "contacts"; - + public static final String DISPLAYNAME = "name"; public static final String JID = "jid"; public static final String SUBSCRIPTION = "subscription"; @@ -19,7 +18,7 @@ public class Contact extends AbstractEntity implements Serializable { public static final String OPENPGPKEY = "pgpkey"; public static final String LASTPRESENCE = "presence"; public static final String ACCOUNT = "accountUuid"; - + protected String accountUuid; protected String displayName; protected String jid; @@ -29,10 +28,10 @@ public class Contact extends AbstractEntity implements Serializable { protected String openPGPKey; protected long lastPresence; - protected Account account; - - public Contact(Account account, String displayName, String jid, String photoUri) { + + public Contact(Account account, String displayName, String jid, + String photoUri) { if (account == null) { this.accountUuid = null; } else { @@ -42,8 +41,10 @@ public class Contact extends AbstractEntity implements Serializable { this.jid = jid; this.photoUri = photoUri; } - - public Contact(String uuid, String account, String displayName, String jid, String subscription, String photoUri, int systemAccount, String pgpKey, long lastseen) { + + public Contact(String uuid, String account, String displayName, String jid, + String subscription, String photoUri, int systemAccount, + String pgpKey, long lastseen) { this.uuid = uuid; this.accountUuid = account; this.displayName = displayName; @@ -62,30 +63,31 @@ public class Contact extends AbstractEntity implements Serializable { public String getProfilePhoto() { return this.photoUri; } - + public String getJid() { return this.jid; } - + public boolean match(String needle) { - return (jid.toLowerCase().contains(needle.toLowerCase()) || (displayName.toLowerCase().contains(needle.toLowerCase()))); + return (jid.toLowerCase().contains(needle.toLowerCase()) || (displayName + .toLowerCase().contains(needle.toLowerCase()))); } @Override public ContentValues getContentValues() { ContentValues values = new ContentValues(); - values.put(UUID,uuid); - values.put(ACCOUNT,accountUuid); + values.put(UUID, uuid); + values.put(ACCOUNT, accountUuid); values.put(DISPLAYNAME, displayName); values.put(JID, jid); - values.put(SUBSCRIPTION,subscription); + values.put(SUBSCRIPTION, subscription); values.put(SYSTEMACCOUNT, systemAccount); - values.put(PHOTOURI,photoUri); - values.put(OPENPGPKEY,openPGPKey); - values.put(LASTPRESENCE,lastPresence); + values.put(PHOTOURI, photoUri); + values.put(OPENPGPKEY, openPGPKey); + values.put(LASTPRESENCE, lastPresence); return values; } - + public static Contact fromCursor(Cursor cursor) { return new Contact(cursor.getString(cursor.getColumnIndex(UUID)), cursor.getString(cursor.getColumnIndex(ACCOUNT)), @@ -95,8 +97,7 @@ public class Contact extends AbstractEntity implements Serializable { cursor.getString(cursor.getColumnIndex(PHOTOURI)), cursor.getInt(cursor.getColumnIndex(SYSTEMACCOUNT)), cursor.getString(cursor.getColumnIndex(OPENPGPKEY)), - cursor.getLong(cursor.getColumnIndex(LASTPRESENCE)) - ); + cursor.getLong(cursor.getColumnIndex(LASTPRESENCE))); } public void setSubscription(String subscription) { @@ -119,4 +120,20 @@ public class Contact extends AbstractEntity implements Serializable { public void setUuid(String uuid) { this.uuid = uuid; } + + public boolean couldBeMuc() { + String[] split = this.getJid().split("@"); + if (split.length != 2) { + return false; + } else { + String[] domainParts = split[1].split("\\."); + if (domainParts.length < 3) { + return false; + } else { + return (domainParts[0].equals("conf") + || domainParts[0].equals("conference") || domainParts[0] + .equals("muc")); + } + } + } } -- cgit v1.2.3