From f1aa6e269742b73162221c5c34c3a89eade93f8d Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Thu, 17 Sep 2020 11:39:34 +1000 Subject: [PATCH] Fix message details screen styling --- res/layout/message_details_header.xml | 7 +++++++ res/layout/message_recipient_list_item.xml | 16 ++++++--------- .../securesms/MessageDetailsActivity.java | 9 +++++++++ .../MessageDetailsRecipientAdapter.java | 20 ++++++++----------- .../conversation/ConversationItem.java | 4 ++-- .../loki/views/ProfilePictureView.kt | 2 +- .../securesms/loki/views/UserView.kt | 10 ++++++++-- 7 files changed, 41 insertions(+), 27 deletions(-) diff --git a/res/layout/message_details_header.xml b/res/layout/message_details_header.xml index 603f5d1e82..2525b7b53f 100644 --- a/res/layout/message_details_header.xml +++ b/res/layout/message_details_header.xml @@ -151,4 +151,11 @@ + + + diff --git a/res/layout/message_recipient_list_item.xml b/res/layout/message_recipient_list_item.xml index 4f78627f38..93821317c7 100644 --- a/res/layout/message_recipient_list_item.xml +++ b/res/layout/message_recipient_list_item.xml @@ -8,25 +8,21 @@ android:layout_height="wrap_content" android:padding="16dp"> - + android:layout_marginEnd="10dp" /> diff --git a/src/org/thoughtcrime/securesms/MessageDetailsActivity.java b/src/org/thoughtcrime/securesms/MessageDetailsActivity.java index 12d31377f0..4f7db5f7e5 100644 --- a/src/org/thoughtcrime/securesms/MessageDetailsActivity.java +++ b/src/org/thoughtcrime/securesms/MessageDetailsActivity.java @@ -59,6 +59,7 @@ import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.ExpirationUtil; import org.thoughtcrime.securesms.util.Util; import org.whispersystems.libsignal.util.guava.Optional; +import org.whispersystems.signalservice.loki.api.opengroups.PublicChat; import java.lang.ref.WeakReference; import java.sql.Date; @@ -97,6 +98,7 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity private View receivedContainer; private TextView transport; private TextView toFrom; + private View separator; private ListView recipientsList; private LayoutInflater inflater; @@ -177,6 +179,7 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity receivedDate = header.findViewById(R.id.received_time); transport = header.findViewById(R.id.transport); toFrom = header.findViewById(R.id.tofrom); + separator = header.findViewById(R.id.separator); expiresContainer = header.findViewById(R.id.expires_container); expiresInText = header.findViewById(R.id.expires_in); recipientsList.setHeaderDividersEnabled(false); @@ -262,6 +265,12 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity toFromRes = R.string.message_details_header__from; } toFrom.setText(toFromRes); + long threadID = messageRecord.getThreadId(); + PublicChat openGroup = DatabaseFactory.getLokiThreadDatabase(this).getPublicChat(threadID); + if (openGroup != null && messageRecord.isOutgoing()) { + toFrom.setVisibility(View.GONE); + separator.setVisibility(View.GONE); + } conversationItem.bind(messageRecord, Optional.absent(), Optional.absent(), glideRequests, dynamicLanguage.getCurrentLocale(), new HashSet<>(), recipient, null, false); recipientsList.setAdapter(new MessageDetailsRecipientAdapter(this, glideRequests, messageRecord, recipients, isPushGroup)); } diff --git a/src/org/thoughtcrime/securesms/MessageDetailsRecipientAdapter.java b/src/org/thoughtcrime/securesms/MessageDetailsRecipientAdapter.java index 0313011026..422330dd81 100644 --- a/src/org/thoughtcrime/securesms/MessageDetailsRecipientAdapter.java +++ b/src/org/thoughtcrime/securesms/MessageDetailsRecipientAdapter.java @@ -1,14 +1,15 @@ package org.thoughtcrime.securesms; import android.content.Context; -import androidx.annotation.NonNull; -import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.BaseAdapter; +import androidx.annotation.NonNull; + import org.thoughtcrime.securesms.database.model.MessageRecord; +import org.thoughtcrime.securesms.loki.views.UserView; import org.thoughtcrime.securesms.mms.GlideRequests; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.util.Conversions; @@ -17,8 +18,6 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.List; -import network.loki.messenger.R; - class MessageDetailsRecipientAdapter extends BaseAdapter implements AbsListView.RecyclerListener { private final Context context; @@ -59,14 +58,11 @@ class MessageDetailsRecipientAdapter extends BaseAdapter implements AbsListView. @Override public View getView(int position, View convertView, ViewGroup parent) { - if (convertView == null) { - convertView = LayoutInflater.from(context).inflate(R.layout.message_recipient_list_item, parent, false); - } - - RecipientDeliveryStatus member = members.get(position); - - ((MessageRecipientListItem)convertView).set(glideRequests, record, member, isPushGroup); - return convertView; + UserView result = new UserView(context); + Recipient recipient = members.get(position).getRecipient(); + result.setOpenGroupThreadID(record.getThreadId()); + result.bind(recipient, glideRequests, UserView.ActionIndicator.None, false); + return result; } @Override diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java index a86f02e073..a719e8c43e 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java @@ -793,7 +793,7 @@ public class ConversationItem extends LinearLayout } private void setContactPhoto(@NonNull Recipient recipient) { - if (messageRecord == null) return; // TODO: Figure out how this happens + if (messageRecord == null) { return; } // TODO: Figure out how this happens LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)bodyBubble.getLayoutParams(); int groupThreadMargin = (int)((12 * getResources().getDisplayMetrics().density) + getResources().getDimension(R.dimen.small_profile_picture_size)); int defaultMargin = 0; @@ -803,7 +803,7 @@ public class ConversationItem extends LinearLayout boolean isRSSFeed = threadName != null && (threadName.equals("Loki News") || threadName.equals("Session Updates")); layoutParams.setMarginStart((groupThread && !isRSSFeed) ? groupThreadMargin : defaultMargin); bodyBubble.setLayoutParams(layoutParams); - if (profilePictureView == null) return; + if (profilePictureView == null) { return; } String publicKey = recipient.getAddress().toString(); profilePictureView.setPublicKey(publicKey); String displayName = recipient.getName(); diff --git a/src/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt b/src/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt index 6331d4ff10..f27c38ad97 100644 --- a/src/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt +++ b/src/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt @@ -96,7 +96,7 @@ class ProfilePictureView : RelativeLayout { } } else { publicKey = recipient.address.toString() - displayName = recipient.name + displayName = getUserDisplayName(publicKey) additionalPublicKey = null isRSSFeed = false } diff --git a/src/org/thoughtcrime/securesms/loki/views/UserView.kt b/src/org/thoughtcrime/securesms/loki/views/UserView.kt index 96c1de080a..01455b9c00 100644 --- a/src/org/thoughtcrime/securesms/loki/views/UserView.kt +++ b/src/org/thoughtcrime/securesms/loki/views/UserView.kt @@ -16,6 +16,7 @@ import org.thoughtcrime.securesms.recipients.Recipient import org.whispersystems.signalservice.loki.protocol.mentions.MentionsManager class UserView : LinearLayout { + var openGroupThreadID: Long = -1 // FIXME: This is a bit ugly enum class ActionIndicator { None, @@ -53,7 +54,12 @@ class UserView : LinearLayout { if (publicKey == null || publicKey.isBlank()) { return null } else { - return DatabaseFactory.getLokiUserDatabase(context).getDisplayName(publicKey!!) + var result = DatabaseFactory.getLokiUserDatabase(context).getDisplayName(publicKey) + val publicChat = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(openGroupThreadID) + if (result == null && publicChat != null) { + result = DatabaseFactory.getLokiUserDatabase(context).getServerDisplayName(publicChat.id, publicKey) + } + return result } } val address = user.address.serialize() @@ -84,7 +90,7 @@ class UserView : LinearLayout { actionIndicatorImageView.setImageResource(R.drawable.ic_baseline_edit_24) profilePictureView.glide = glide profilePictureView.update() - nameTextView.text = user.name ?: "Unknown Contact" + nameTextView.text = getUserDisplayName(address) when (actionIndicator) { ActionIndicator.None -> { actionIndicatorImageView.visibility = View.GONE