From 018120cfe6901477c4f3cc4d3b130e5aa3ae37b8 Mon Sep 17 00:00:00 2001 From: kosyak Date: Sun, 2 Jun 2024 20:03:29 +0200 Subject: [PATCH] render reply message author name on the top of replied text --- .../ui/adapter/MessageAdapter.java | 56 +++++++++++++------ src/main/res/drawable/reply_divider.xml | 4 ++ src/main/res/layout/message_content.xml | 16 ++---- 3 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 src/main/res/drawable/reply_divider.xml diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 40f0b3094..827b085b2 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -635,9 +635,9 @@ public class MessageAdapter extends ArrayAdapter implements DraggableLi final String nick = UIHelper.getMessageDisplayName(message); Message replyMessage = message.getReplyMessage(); - Boolean fileOrImageReply = replyMessage != null && replyMessage.isFileOrImage(); + Boolean showReplyAsSeparatePart = (replyMessage != null && replyMessage.isFileOrImage()) || message.isFileOrImage(); - SpannableStringBuilder body = message.getBodyForDisplaying(fileOrImageReply); + SpannableStringBuilder body = message.getBodyForDisplaying(showReplyAsSeparatePart); boolean hasMeCommand = message.hasMeCommand(); if (hasMeCommand) { @@ -663,8 +663,8 @@ public class MessageAdapter extends ArrayAdapter implements DraggableLi applyQuoteSpan(body, start, end, darkBackground, message.getReplyMessage() != null, message); } - maybeShowReply(replyMessage, fileOrImageReply, viewHolder, message); - handleTextQuotes(body, darkBackground, message.getReplyMessage() != null && !fileOrImageReply, message); + maybeShowReply(replyMessage, showReplyAsSeparatePart, viewHolder, message, darkBackground); + handleTextQuotes(body, darkBackground, message.getReplyMessage() != null && !showReplyAsSeparatePart, message); if (!message.isPrivateMessage()) { if (hasMeCommand) { @@ -726,7 +726,14 @@ public class MessageAdapter extends ArrayAdapter implements DraggableLi } } - private void maybeShowReply(Message replyMessage, boolean showAsSeparatePart, ViewHolder viewHolder, Message message) { + private void maybeShowReply(Message replyMessage, boolean showAsSeparatePart, ViewHolder viewHolder, Message message, boolean darkBackground) { + TextView text = viewHolder.nonTextReplyContent.findViewById(R.id.reply_body); + TextView author = viewHolder.nonTextReplyContent.findViewById(R.id.context_preview_author); + ImageView contextPreviewImage = viewHolder.nonTextReplyContent.findViewById(R.id.context_preview_image); + ImageView contextPreviewDoc = viewHolder.nonTextReplyContent.findViewById(R.id.context_preview_doc); + ImageView contextPreviewAudio = viewHolder.nonTextReplyContent.findViewById(R.id.context_preview_audio); + View iconsContainer = viewHolder.nonTextReplyContent.findViewById(R.id.icons_container); + if (showAsSeparatePart && replyMessage != null) { viewHolder.nonTextReplyContent.setVisibility(View.VISIBLE); WeakReference listener = new WeakReference<>(replyClickListener); @@ -737,30 +744,47 @@ public class MessageAdapter extends ArrayAdapter implements DraggableLi } }); - TextView text = viewHolder.nonTextReplyContent.findViewById(R.id.reply_body); + text.setVisibility(View.VISIBLE); - TextView author = viewHolder.nonTextReplyContent.findViewById(R.id.context_preview_author); - ImageView contextPreviewImage = viewHolder.nonTextReplyContent.findViewById(R.id.context_preview_image); - View contextPreviewDoc = viewHolder.nonTextReplyContent.findViewById(R.id.context_preview_doc); - View contextPreviewAudio = viewHolder.nonTextReplyContent.findViewById(R.id.context_preview_audio); + int color = this.getMessageTextColor(darkBackground, false); + text.setTextColor(color); + author.setTextColor(color); + contextPreviewDoc.setColorFilter(color); + contextPreviewAudio.setColorFilter(color); text.setText(replyMessage.getBodyForReplyPreview(activity.xmppConnectionService)); author.setText(replyMessage.getAvatarName()); if (replyMessage.getFileParams().width > 0 && replyMessage.getFileParams().height > 0) { + iconsContainer.setVisibility(View.VISIBLE); contextPreviewImage.setVisibility(View.VISIBLE); contextPreviewDoc.setVisibility(View.GONE); contextPreviewAudio.setVisibility(View.GONE); activity.loadBitmap(replyMessage, contextPreviewImage); } else if (replyMessage.getFileParams().runtime > 0) { + iconsContainer.setVisibility(View.VISIBLE); contextPreviewImage.setVisibility(View.GONE); contextPreviewDoc.setVisibility(View.GONE); contextPreviewAudio.setVisibility(View.VISIBLE); - } else { + } else if (replyMessage.isFileOrImage()) { + iconsContainer.setVisibility(View.VISIBLE); contextPreviewImage.setVisibility(View.GONE); contextPreviewDoc.setVisibility(View.VISIBLE); contextPreviewAudio.setVisibility(View.GONE); + } else { + iconsContainer.setVisibility(View.GONE); } + } else if (replyMessage != null) { + viewHolder.nonTextReplyContent.setVisibility(View.VISIBLE); + contextPreviewImage.setVisibility(View.GONE); + contextPreviewDoc.setVisibility(View.GONE); + contextPreviewAudio.setVisibility(View.GONE); + text.setVisibility(View.GONE); + iconsContainer.setVisibility(View.GONE); + + int color = this.getMessageTextColor(darkBackground, false); + author.setTextColor(color); + author.setText(replyMessage.getAvatarName()); } else { viewHolder.nonTextReplyContent.setVisibility(View.GONE); } @@ -774,7 +798,7 @@ public class MessageAdapter extends ArrayAdapter implements DraggableLi viewHolder.download_button.setText(text); viewHolder.download_button.setOnClickListener(v -> ConversationFragment.downloadFile(activity, message)); - maybeShowReply(message.getReplyMessage(), true, viewHolder, message); + maybeShowReply(message.getReplyMessage(), true, viewHolder, message, darkBackground); } private void displayOpenableMessage(ViewHolder viewHolder, final Message message, final boolean darkBackground) { @@ -785,7 +809,7 @@ public class MessageAdapter extends ArrayAdapter implements DraggableLi viewHolder.download_button.setText(activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity, message))); viewHolder.download_button.setOnClickListener(v -> openDownloadable(message)); - maybeShowReply(message.getReplyMessage(), true, viewHolder, message); + maybeShowReply(message.getReplyMessage(), true, viewHolder, message, darkBackground); } private void displayLocationMessage(ViewHolder viewHolder, final Message message, final boolean darkBackground) { @@ -796,7 +820,7 @@ public class MessageAdapter extends ArrayAdapter implements DraggableLi viewHolder.download_button.setText(R.string.show_location); viewHolder.download_button.setOnClickListener(v -> showLocation(message)); - maybeShowReply(message.getReplyMessage(), true, viewHolder, message); + maybeShowReply(message.getReplyMessage(), true, viewHolder, message, darkBackground); } private void displayAudioMessage(ViewHolder viewHolder, Message message, boolean darkBackground) { @@ -808,7 +832,7 @@ public class MessageAdapter extends ArrayAdapter implements DraggableLi AudioPlayer.ViewHolder.get(audioPlayer).setDarkBackground(darkBackground); this.audioPlayer.init(audioPlayer, message); - maybeShowReply(message.getReplyMessage(), true, viewHolder, message); + maybeShowReply(message.getReplyMessage(), true, viewHolder, message, darkBackground); } private void displayMediaPreviewMessage(ViewHolder viewHolder, final Message message, final boolean darkBackground) { @@ -816,7 +840,7 @@ public class MessageAdapter extends ArrayAdapter implements DraggableLi viewHolder.download_button.setVisibility(View.GONE); viewHolder.audioPlayer.setVisibility(View.GONE); viewHolder.image.setVisibility(View.VISIBLE); - maybeShowReply(message.getReplyMessage(), true, viewHolder, message); + maybeShowReply(message.getReplyMessage(), true, viewHolder, message, darkBackground); final FileParams params = message.getFileParams(); final float target = activity.getResources().getDimension(R.dimen.image_preview_width); final int scaledW; diff --git a/src/main/res/drawable/reply_divider.xml b/src/main/res/drawable/reply_divider.xml new file mode 100644 index 000000000..f8cc39980 --- /dev/null +++ b/src/main/res/drawable/reply_divider.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/main/res/layout/message_content.xml b/src/main/res/layout/message_content.xml index 2b7d68a5c..2b2285c95 100644 --- a/src/main/res/layout/message_content.xml +++ b/src/main/res/layout/message_content.xml @@ -6,23 +6,15 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" + android:background="@drawable/reply_divider" + android:paddingStart="11.5sp" android:visibility="gone"> - -