Change summary
src/cheogram/java/eu/siacs/conversations/android/PhoneNumberContact.java | 12
src/cheogram/java/eu/siacs/conversations/services/QuickConversationsService.java | 4
src/main/java/eu/siacs/conversations/entities/Contact.java | 24
3 files changed, 39 insertions(+), 1 deletion(-)
Detailed changes
@@ -23,15 +23,25 @@ import io.michaelrocks.libphonenumber.android.NumberParseException;
public class PhoneNumberContact extends AbstractPhoneContact {
private final String phoneNumber;
+ private final String typeLabel;
public String getPhoneNumber() {
return phoneNumber;
}
+ public String getTypeLabel() {
+ return typeLabel;
+ }
+
private PhoneNumberContact(Context context, Cursor cursor) throws IllegalArgumentException {
super(cursor);
try {
this.phoneNumber = PhoneNumberUtilWrapper.normalize(context, cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
+ this.typeLabel = ContactsContract.CommonDataKinds.Phone.getTypeLabel(
+ context.getResources(),
+ cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)),
+ cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL))
+ ).toString();
} catch (NumberParseException | NullPointerException e) {
throw new IllegalArgumentException(e);
}
@@ -45,6 +55,8 @@ public class PhoneNumberContact extends AbstractPhoneContact {
ContactsContract.Data.DISPLAY_NAME,
ContactsContract.Data.PHOTO_URI,
ContactsContract.Data.LOOKUP_KEY,
+ ContactsContract.CommonDataKinds.Phone.TYPE,
+ ContactsContract.CommonDataKinds.Phone.LABEL,
ContactsContract.CommonDataKinds.Phone.NUMBER};
final HashMap<String, PhoneNumberContact> contacts = new HashMap<>();
try (final Cursor cursor = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PROJECTION, null, null, null)){
@@ -2,6 +2,7 @@ package eu.siacs.conversations.services;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Objects;
import java.util.ArrayList;
@@ -132,7 +133,8 @@ public class QuickConversationsService extends AbstractQuickConversationsService
for(String gateway : gateways) {
final Jid jid = Jid.ofLocalAndDomain(phoneContact.getPhoneNumber(), gateway);
final Contact contact = account.getRoster().getContact(jid);
- final boolean needsCacheClean = contact.setPhoneContact(phoneContact);
+ boolean needsCacheClean = contact.setPhoneContact(phoneContact);
+ needsCacheClean |= contact.setSystemTags(Collections.singleton(phoneContact.getTypeLabel()));
if (needsCacheClean) {
service.getAvatarService().clear(contact);
}
@@ -69,6 +69,7 @@ public class Contact implements ListItem, Blockable {
private String photoUri;
private final JSONObject keys;
private JSONArray groups = new JSONArray();
+ private JSONArray systemTags = new JSONArray();
private final Presences presences = new Presences();
protected Account account;
protected Avatar avatar;
@@ -193,6 +194,9 @@ public class Contact implements ListItem, Blockable {
for (final String group : getGroups(true)) {
tags.add(new Tag(group, UIHelper.getColorForName(group)));
}
+ for (final String tag : getSystemTags(true)) {
+ tags.add(new Tag(tag, UIHelper.getColorForName(tag)));
+ }
Presence.Status status = getShownStatus();
if (status != Presence.Status.OFFLINE) {
tags.add(UIHelper.getTagForStatus(context, status));
@@ -309,6 +313,15 @@ public class Contact implements ListItem, Blockable {
return !old.equals(getDisplayName());
}
+ public boolean setSystemTags(Collection<String> systemTags) {
+ final JSONArray old = this.systemTags;
+ this.systemTags = new JSONArray();
+ for(String tag : systemTags) {
+ this.systemTags.put(tag);
+ }
+ return !old.equals(this.systemTags);
+ }
+
public boolean setPresenceName(String presenceName) {
final String old = getDisplayName();
this.presenceName = presenceName;
@@ -334,6 +347,17 @@ public class Contact implements ListItem, Blockable {
return groups;
}
+ private Collection<String> getSystemTags(final boolean unique) {
+ final Collection<String> tags = unique ? new HashSet<>() : new ArrayList<>();
+ for (int i = 0; i < this.systemTags.length(); ++i) {
+ try {
+ tags.add(this.systemTags.getString(i));
+ } catch (final JSONException ignored) {
+ }
+ }
+ return tags;
+ }
+
public long getPgpKeyId() {
synchronized (this.keys) {
if (this.keys.has("pgp_keyid")) {