From 46fa7d8e457d85220b021b5f4373ffb8265df6c2 Mon Sep 17 00:00:00 2001 From: Arne Date: Fri, 3 Jan 2025 03:54:58 +0100 Subject: [PATCH] Add active indicator to contacts list --- .../eu/siacs/conversations/entities/Bookmark.java | 9 +++++++-- .../java/eu/siacs/conversations/entities/Contact.java | 11 ++++++++--- .../eu/siacs/conversations/entities/ListItem.java | 7 ++++++- .../eu/siacs/conversations/entities/RawBlockable.java | 5 +++++ .../conversations/ui/StartConversationActivity.java | 2 +- .../conversations/ui/adapter/ListItemAdapter.java | 7 +++++++ src/main/res/layout/item_contact.xml | 11 +++++++++++ .../java/de/monocles/chat/TagEditorView.java | 6 +++++- 8 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Bookmark.java b/src/main/java/eu/siacs/conversations/entities/Bookmark.java index 8e0c175dd..925ef51c2 100644 --- a/src/main/java/eu/siacs/conversations/entities/Bookmark.java +++ b/src/main/java/eu/siacs/conversations/entities/Bookmark.java @@ -221,7 +221,7 @@ public class Bookmark extends Element implements ListItem { for (Element element : getChildren()) { if (element.getName().equals("group") && element.getContent() != null) { String group = element.getContent(); - tags.add(new Tag(group)); + tags.add(new Tag(group, false)); } } @@ -231,11 +231,16 @@ public class Bookmark extends Element implements ListItem { @Override public List getTags(Context context) { ArrayList tags = new ArrayList<>(); - tags.add(new Tag("Channel")); + tags.add(new Tag("Channel", false)); tags.addAll(getGroupTags()); return tags; } + @Override + public boolean getActive() { + return false; + } + public String getNick() { return this.findChildContent("nick"); } diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java index e6b13dcd1..6e8b9b79d 100644 --- a/src/main/java/eu/siacs/conversations/entities/Contact.java +++ b/src/main/java/eu/siacs/conversations/entities/Contact.java @@ -206,7 +206,7 @@ public class Contact implements ListItem, Blockable { public List getGroupTags() { final ArrayList tags = new ArrayList<>(); for (final String group : getGroups(true)) { - tags.add(new Tag(group)); + tags.add(new Tag(group, false)); } return tags; } @@ -216,15 +216,20 @@ public class Contact implements ListItem, Blockable { final HashSet tags = new HashSet<>(); tags.addAll(getGroupTags()); for (final String tag : getSystemTags(true)) { - tags.add(new Tag(tag)); + tags.add(new Tag(tag, isActive())); } Presence.Status status = getShownStatus(); if (!showInRoster() && getSystemAccount() != null) { - tags.add(new Tag("Android")); + tags.add(new Tag("Android", isActive())); } return new ArrayList<>(tags); } + @Override + public boolean getActive() { + return isActive(); + } + public boolean match(Context context, String needle) { if (TextUtils.isEmpty(needle)) { return true; diff --git a/src/main/java/eu/siacs/conversations/entities/ListItem.java b/src/main/java/eu/siacs/conversations/entities/ListItem.java index f4a3a7bf3..572b135ed 100644 --- a/src/main/java/eu/siacs/conversations/entities/ListItem.java +++ b/src/main/java/eu/siacs/conversations/entities/ListItem.java @@ -20,11 +20,16 @@ public interface ListItem extends Comparable, AvatarService.Avatarable List getTags(Context context); + boolean getActive(); + final class Tag implements Serializable, Comparable { private final String name; + private final boolean active; - public Tag(final String name) { + + public Tag(final String name, final boolean active) { this.name = name; + this.active = active; } public String getName() { diff --git a/src/main/java/eu/siacs/conversations/entities/RawBlockable.java b/src/main/java/eu/siacs/conversations/entities/RawBlockable.java index 664a6a1c9..c7c2c67c8 100644 --- a/src/main/java/eu/siacs/conversations/entities/RawBlockable.java +++ b/src/main/java/eu/siacs/conversations/entities/RawBlockable.java @@ -54,6 +54,11 @@ public class RawBlockable implements ListItem, Blockable { return Collections.emptyList(); } + @Override + public boolean getActive() { + return false; + } + @Override public boolean match(Context context, String needle) { if (TextUtils.isEmpty(needle)) { diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index 0335044dc..d92f4ee04 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -1951,7 +1951,7 @@ public class StartConversationActivity extends XmppActivity } public void setTags(final List tags) { - ListItem.Tag channelTag = new ListItem.Tag("Channel"); + ListItem.Tag channelTag = new ListItem.Tag("Channel", false); String needle = mSearchEditText == null ? "" : mSearchEditText.getText().toString().toLowerCase(Locale.US).trim(); HashSet parts = new HashSet<>(Arrays.asList(needle.split("[,\\s]+"))); this.tags = tags.stream().filter( diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java index b89908c6e..ad01f9e47 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java @@ -153,6 +153,11 @@ public class ListItemAdapter extends ArrayAdapter { } viewHolder.name.setText(item.getDisplayName()); AvatarWorkerTask.loadAvatar(item, viewHolder.avatar, R.dimen.avatar); + if (item.getActive()) { + viewHolder.userActiveIndicator.setVisibility(View.VISIBLE); + } else { + viewHolder.userActiveIndicator.setVisibility(View.GONE); + } return view; } @@ -173,6 +178,7 @@ public class ListItemAdapter extends ArrayAdapter { private View inner; private ConstraintLayout tags; private Flow flowWidget; + private ImageView userActiveIndicator; private ViewHolder() { @@ -187,6 +193,7 @@ public class ListItemAdapter extends ArrayAdapter { viewHolder.tags = binding.tags; viewHolder.inner = binding.inner; viewHolder.flowWidget = binding.flowWidget; + viewHolder.userActiveIndicator = binding.userActiveIndicator; binding.getRoot().setTag(viewHolder); return viewHolder; } diff --git a/src/main/res/layout/item_contact.xml b/src/main/res/layout/item_contact.xml index 7219ed966..9590b4b8a 100644 --- a/src/main/res/layout/item_contact.xml +++ b/src/main/res/layout/item_contact.xml @@ -20,6 +20,17 @@ android:layout_alignParentStart="true" android:scaleType="centerCrop" /> + + { @Override protected ListItem.Tag defaultObject(String completionText) { - return new ListItem.Tag(completionText); + return defaultObject(completionText, false); + } + + protected ListItem.Tag defaultObject(String completionText, boolean isActive) { + return new ListItem.Tag(completionText, isActive); } @Override