render reply message author name on the top of replied text

This commit is contained in:
kosyak 2024-06-02 20:03:29 +02:00
parent a7a00b70d7
commit 018120cfe6
3 changed files with 49 additions and 27 deletions

View file

@ -635,9 +635,9 @@ public class MessageAdapter extends ArrayAdapter<Message> 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<Message> 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<Message> 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<ReplyClickListener> listener = new WeakReference<>(replyClickListener);
@ -737,30 +744,47 @@ public class MessageAdapter extends ArrayAdapter<Message> 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<Message> 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<Message> 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<Message> 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<Message> 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<Message> 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;

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@color/blue_a100" android:width="2sp" android:left="1.5sp"/>
</layer-list>

View file

@ -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">
<View
android:id="@+id/divider"
android:layout_width="2sp"
android:layout_height="32dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="1dp"
android:layout_centerVertical="true"
android:background="@color/blue_a100" />
<FrameLayout
android:id="@+id/icons_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_toEndOf="@id/divider"
android:layout_centerVertical="true">
<ImageView
@ -56,15 +48,17 @@
android:id="@+id/context_preview_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-2dp"
android:layout_toEndOf="@id/icons_container"
android:textAppearance="@style/TextAppearance.Conversations.Body1"
android:fontFamily="sans-serif-medium" />
<TextView
android:id="@+id/reply_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-2dp"
android:longClickable="false"
android:textAppearance="@style/TextAppearance.Conversations.Body1"
android:layout_toEndOf="@id/icons_container"
android:layout_below="@id/context_preview_author"/>
</RelativeLayout>