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));
@@ -200,6 +204,9 @@ public class Contact implements ListItem, Blockable {
if (isBlocked()) {
tags.add(new Tag(context.getString(R.string.blocked), 0xff2e2f3b));
}
+ if (!showInRoster() && getSystemAccount() != null) {
+ tags.add(new Tag("Android", UIHelper.getColorForName("Android")));
+ }
return tags;
}
@@ -306,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;
@@ -331,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")) {
@@ -242,7 +242,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
recreate();
} else {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
- this.showDynamicTags = preferences.getBoolean(SettingsActivity.SHOW_DYNAMIC_TAGS, false);
+ this.showDynamicTags = preferences.getBoolean(SettingsActivity.SHOW_DYNAMIC_TAGS, getResources().getBoolean(R.bool.show_dynamic_tags));
this.showLastSeen = preferences.getBoolean("last_activity", false);
}
binding.mediaWrapper.setVisibility(Compatibility.hasStoragePermission(this) ? View.VISIBLE : View.GONE);
@@ -47,7 +47,7 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
public void refreshSettings() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
- this.showDynamicTags = preferences.getBoolean(SettingsActivity.SHOW_DYNAMIC_TAGS, false);
+ this.showDynamicTags = preferences.getBoolean(SettingsActivity.SHOW_DYNAMIC_TAGS, activity.getResources().getBoolean(R.bool.show_dynamic_tags));
}
@Override
@@ -20,7 +20,7 @@
<string name="picture_compression">auto</string>
<bool name="use_green_background">true</bool>
<string name="quick_action">recent</string>
- <bool name="show_dynamic_tags">false</bool>
+ <bool name="show_dynamic_tags">true</bool>
<bool name="btbv">true</bool>
<integer name="automatic_message_deletion">0</integer>
<bool name="dont_trust_system_cas">false</bool>