aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/entities/Contact.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart/messenger/entities/Contact.java')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Contact.java61
1 files changed, 39 insertions, 22 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Contact.java b/src/main/java/de/pixart/messenger/entities/Contact.java
index a74b09dff..1df6e120a 100644
--- a/src/main/java/de/pixart/messenger/entities/Contact.java
+++ b/src/main/java/de/pixart/messenger/entities/Contact.java
@@ -20,6 +20,7 @@ import java.util.Locale;
import de.pixart.messenger.Config;
import de.pixart.messenger.R;
+import de.pixart.messenger.android.AbstractPhoneContact;
import de.pixart.messenger.utils.JidHelper;
import de.pixart.messenger.utils.UIHelper;
import de.pixart.messenger.xml.Element;
@@ -48,7 +49,7 @@ public class Contact implements ListItem, Blockable {
private String commonName;
protected Jid jid;
private int subscription = 0;
- private String systemAccount;
+ private Uri systemAccount;
private String photoUri;
private final JSONObject keys;
private JSONArray groups = new JSONArray();
@@ -62,7 +63,7 @@ public class Contact implements ListItem, Blockable {
public Contact(final String account, final String systemName, final String serverName,
final Jid jid, final int subscription, final String photoUri,
- final String systemAccount, final String keys, final String avatar, final long lastseen,
+ final Uri systemAccount, final String keys, final String avatar, final long lastseen,
final String presence, final String groups) {
this.accountUuid = account;
this.systemName = systemName;
@@ -105,13 +106,19 @@ public class Contact implements ListItem, Blockable {
// TODO: Borked DB... handle this somehow?
return null;
}
+ Uri systemAccount;
+ try {
+ systemAccount = Uri.parse(cursor.getString(cursor.getColumnIndex(SYSTEMACCOUNT)));
+ } catch (Exception e) {
+ systemAccount = null;
+ }
return new Contact(cursor.getString(cursor.getColumnIndex(ACCOUNT)),
cursor.getString(cursor.getColumnIndex(SYSTEMNAME)),
cursor.getString(cursor.getColumnIndex(SERVERNAME)),
jid,
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
cursor.getString(cursor.getColumnIndex(PHOTOURI)),
- cursor.getString(cursor.getColumnIndex(SYSTEMACCOUNT)),
+ systemAccount,
cursor.getString(cursor.getColumnIndex(KEYS)),
cursor.getString(cursor.getColumnIndex(AVATAR)),
cursor.getLong(cursor.getColumnIndex(LAST_TIME)),
@@ -159,9 +166,6 @@ public class Contact implements ListItem, Blockable {
if (isBlocked()) {
tags.add(new Tag(context.getString(R.string.blocked), 0xff2e2f3b, 0));
}
- if (showInPhoneBook()) {
- tags.add(new Tag(context.getString(R.string.phone_book), 0xFF1E88E5, 0));
- }
return tags;
}
@@ -203,7 +207,7 @@ public class Contact implements ListItem, Blockable {
values.put(SERVERNAME, serverName);
values.put(JID, jid.toString());
values.put(OPTIONS, subscription);
- values.put(SYSTEMACCOUNT, systemAccount);
+ values.put(SYSTEMACCOUNT, systemAccount != null ? systemAccount.toString() : null);
values.put(PHOTOURI, photoUri);
values.put(KEYS, keys.toString());
values.put(AVATAR, avatar == null ? null : avatar.getFilename());
@@ -277,21 +281,11 @@ public class Contact implements ListItem, Blockable {
}
public Uri getSystemAccount() {
- if (systemAccount == null) {
- return null;
- } else {
- String[] parts = systemAccount.split("#");
- if (parts.length != 2) {
- return null;
- } else {
- long id = Long.parseLong(parts[0]);
- return ContactsContract.Contacts.getLookupUri(id, parts[1]);
- }
- }
+ return systemAccount;
}
- public void setSystemAccount(String account) {
- this.systemAccount = account;
+ public void setSystemAccount(Uri lookupUri) {
+ this.systemAccount = lookupUri;
}
private Collection<String> getGroups(final boolean unique) {
@@ -390,8 +384,8 @@ public class Contact implements ListItem, Blockable {
|| (this.getOption(Contact.Options.DIRTY_PUSH));
}
- public boolean showInPhoneBook() {
- return systemAccount != null && !systemAccount.trim().isEmpty();
+ public boolean showInContactList() {
+ return showInRoster() || getOption(Options.SYNCED_VIA_OTHER);
}
public void parseSubscriptionFromElement(Element item) {
@@ -583,6 +577,27 @@ public class Contact implements ListItem, Blockable {
return serverName;
}
+ public synchronized boolean setPhoneContact(AbstractPhoneContact phoneContact) {
+ setOption(getOption(phoneContact.getClass()));
+ setSystemAccount(phoneContact.getLookupUri());
+ boolean changed = setSystemName(phoneContact.getDisplayName());
+ changed |= setPhotoUri(phoneContact.getPhotoUri());
+ return changed;
+ }
+ public synchronized boolean unsetPhoneContact(Class<?extends AbstractPhoneContact> clazz) {
+ resetOption(getOption(clazz));
+ boolean changed = false;
+ if (!getOption(Options.SYNCED_VIA_ADDRESSBOOK) && !getOption(Options.SYNCED_VIA_OTHER)) {
+ setSystemAccount(null);
+ changed |= setPhotoUri(null);
+ changed |= setSystemName(null);
+ }
+ return changed;
+ }
+ public static int getOption(Class<? extends AbstractPhoneContact> clazz) {
+ return Options.SYNCED_VIA_OTHER;
+ }
+
public final class Options {
public static final int TO = 0;
public static final int FROM = 1;
@@ -592,5 +607,7 @@ public class Contact implements ListItem, Blockable {
public static final int PENDING_SUBSCRIPTION_REQUEST = 5;
public static final int DIRTY_PUSH = 6;
public static final int DIRTY_DELETE = 7;
+ private static final int SYNCED_VIA_ADDRESSBOOK = 8;
+ public static final int SYNCED_VIA_OTHER = 9;
}
}