From d7d922c1d16b73bf579ade63648277ae332fc499 Mon Sep 17 00:00:00 2001 From: kosyak Date: Mon, 5 Aug 2024 23:18:55 +0200 Subject: [PATCH] account indicator near conversations --- .../ui/adapter/AccountAdapter.java | 9 ++++++++ .../ui/adapter/ConversationAdapter.java | 9 ++++++++ .../ui/adapter/ListItemAdapter.java | 21 +++++++++++++++++++ src/main/res/layout/account_row.xml | 7 +++++++ src/main/res/layout/contact.xml | 7 +++++++ src/main/res/layout/conversation_list_row.xml | 7 +++++++ src/main/res/values/dimens.xml | 1 + 7 files changed, 61 insertions(+) diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java index 038f255ea..a074fd6c8 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java @@ -1,5 +1,6 @@ package eu.siacs.conversations.ui.adapter; +import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -17,6 +18,7 @@ import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.ui.util.AvatarWorkerTask; import eu.siacs.conversations.ui.util.StyledAttributes; +import eu.siacs.conversations.utils.UIHelper; public class AccountAdapter extends ArrayAdapter { @@ -80,6 +82,13 @@ public class AccountAdapter extends ArrayAdapter { ((OnTglAccountState) activity).onClickTglAccountState(account, b); } }); + + if (activity.xmppConnectionService.getAccounts().size() > 1) { + viewHolder.binding.accountIndicator.setBackgroundColor(UIHelper.getColorForName(account.getJid().asBareJid().getEscapedLocal())); + } else { + viewHolder.binding.accountIndicator.setBackgroundColor(Color.TRANSPARENT); + } + return view; } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java index 4862e0ca1..69d4c7df4 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java @@ -2,6 +2,7 @@ package eu.siacs.conversations.ui.adapter; import android.content.Context; import android.content.SharedPreferences; +import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.preference.PreferenceManager; @@ -397,6 +398,14 @@ public class ConversationAdapter viewHolder.binding.presenceIndicator.setStatus(null); } + Account account = conversation.getAccount(); + + if (account != null && activity.xmppConnectionService.getAccounts().size() > 1) { + viewHolder.binding.accountIndicator.setBackgroundColor(UIHelper.getColorForName(account.getJid().asBareJid().getEscapedLocal())); + } else { + viewHolder.binding.accountIndicator.setBackgroundColor(Color.TRANSPARENT); + } + if (draft != null) { viewHolder.binding.conversationLastmsgImg.setVisibility(View.GONE); viewHolder.binding.conversationLastmsg.setText(draft.getMessage()); 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 febfb964f..b342ccf0d 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java @@ -1,6 +1,7 @@ package eu.siacs.conversations.ui.adapter; import android.content.SharedPreferences; +import android.graphics.Color; import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; @@ -17,6 +18,8 @@ import java.util.List; import eu.siacs.conversations.R; import eu.siacs.conversations.databinding.ContactBinding; +import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.ListItem; import eu.siacs.conversations.ui.SettingsActivity; @@ -25,6 +28,7 @@ import eu.siacs.conversations.ui.util.AvatarWorkerTask; import eu.siacs.conversations.ui.util.StyledAttributes; import eu.siacs.conversations.ui.widget.PresenceIndicator; import eu.siacs.conversations.utils.IrregularUnicodeDetector; +import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xmpp.Jid; public class ListItemAdapter extends ArrayAdapter { @@ -95,6 +99,20 @@ public class ListItemAdapter extends ArrayAdapter { viewHolder.presenceIndicator.setStatus(null); } + + Account account = null; + if (item instanceof Contact) { + account = ((Contact) item).getAccount(); + } else if (item instanceof Bookmark) { + account = ((Bookmark) item).getAccount(); + } + + if (account != null && activity.xmppConnectionService.getAccounts().size() > 1) { + viewHolder.accountIndicator.setBackgroundColor(UIHelper.getColorForName(account.getJid().asBareJid().getEscapedLocal())); + } else { + viewHolder.accountIndicator.setBackgroundColor(Color.TRANSPARENT); + } + return view; } @@ -115,6 +133,8 @@ public class ListItemAdapter extends ArrayAdapter { private PresenceIndicator presenceIndicator; + private View accountIndicator; + private ViewHolder() { } @@ -126,6 +146,7 @@ public class ListItemAdapter extends ArrayAdapter { viewHolder.avatar = binding.contactPhoto; viewHolder.tags = binding.tags; viewHolder.presenceIndicator = binding.presenceIndicator; + viewHolder.accountIndicator = binding.accountIndicator; binding.getRoot().setTag(viewHolder); return viewHolder; } diff --git a/src/main/res/layout/account_row.xml b/src/main/res/layout/account_row.xml index dfe0e1d22..ee3f7c138 100644 --- a/src/main/res/layout/account_row.xml +++ b/src/main/res/layout/account_row.xml @@ -6,10 +6,17 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?selectableItemBackground" + android:clipToPadding="false" android:paddingLeft="8dp" android:paddingBottom="8dp" android:paddingTop="8dp"> + + + + + + 8dp 12dp 2dp + 2dp