From 582178991b1729b5372371ccbef1e6756e8420b2 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 16 Jun 2018 18:14:49 +0200 Subject: [PATCH] deduplicate tags + translate 'blocked' tag --- .../eu/siacs/conversations/entities/Contact.java | 13 ++++++++----- src/main/res/values/strings.xml | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java index ad264c792..f47fd2e3c 100644 --- a/src/main/java/eu/siacs/conversations/entities/Contact.java +++ b/src/main/java/eu/siacs/conversations/entities/Contact.java @@ -13,10 +13,13 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Locale; import eu.siacs.conversations.Config; +import eu.siacs.conversations.R; import eu.siacs.conversations.utils.JidHelper; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xml.Element; @@ -143,7 +146,7 @@ public class Contact implements ListItem, Blockable { @Override public List getTags(Context context) { final ArrayList tags = new ArrayList<>(); - for (final String group : getGroups()) { + for (final String group : getGroups(true)) { tags.add(new Tag(group, UIHelper.getColorForName(group))); } Presence.Status status = getShownStatus(); @@ -151,7 +154,7 @@ public class Contact implements ListItem, Blockable { tags.add(UIHelper.getTagForStatus(context, status)); } if (isBlocked()) { - tags.add(new Tag("blocked", 0xff2e2f3b)); + tags.add(new Tag(context.getString(R.string.blocked), 0xff2e2f3b)); } return tags; } @@ -281,8 +284,8 @@ public class Contact implements ListItem, Blockable { this.systemAccount = account; } - private List getGroups() { - ArrayList groups = new ArrayList<>(); + private Collection getGroups(final boolean unique) { + final Collection groups = unique ? new HashSet<>() : new ArrayList<>(); for (int i = 0; i < this.groups.length(); ++i) { try { groups.add(this.groups.getString(i)); @@ -387,7 +390,7 @@ public class Contact implements ListItem, Blockable { if (this.serverName != null) { item.setAttribute("name", this.serverName); } - for (String group : getGroups()) { + for (String group : getGroups(false)) { item.addChild("group").setContent(group); } return item; diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index c5879d10a..155410ade 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -42,6 +42,7 @@ Block all contacts from %s? Unblock all contacts from %s? Contact blocked + Blocked Would you like to remove %s as a bookmark? The conversation associated with this bookmark will not be removed. Register new account on server Change password on server