fix invalid ui state

This commit is contained in:
kosyak 2024-05-22 20:55:34 +02:00
parent 8c78febaa8
commit 0494569a29

View file

@ -663,44 +663,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements DraggableLi
applyQuoteSpan(body, start, end, darkBackground, message.getReplyMessage() != null, message);
}
if (fileOrImageReply) {
viewHolder.nonTextReplyContent.setVisibility(View.VISIBLE);
WeakReference<ReplyClickListener> listener = new WeakReference<>(replyClickListener);
viewHolder.nonTextReplyContent.setOnClickListener(v -> {
ReplyClickListener l = listener.get();
if (l != null) {
l.onReplyClick(message);
}
});
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);
View contextPreviewDoc = viewHolder.nonTextReplyContent.findViewById(R.id.context_preview_doc);
View contextPreviewAudio = viewHolder.nonTextReplyContent.findViewById(R.id.context_preview_audio);
text.setText(replyMessage.getBodyForReplyPreview(activity.xmppConnectionService));
author.setText(replyMessage.getAvatarName());
if (replyMessage.getFileParams().width > 0 && replyMessage.getFileParams().height > 0) {
contextPreviewImage.setVisibility(View.VISIBLE);
contextPreviewDoc.setVisibility(View.GONE);
contextPreviewAudio.setVisibility(View.GONE);
activity.loadBitmap(replyMessage, contextPreviewImage);
} else if (replyMessage.getFileParams().runtime > 0) {
contextPreviewImage.setVisibility(View.GONE);
contextPreviewDoc.setVisibility(View.GONE);
contextPreviewAudio.setVisibility(View.VISIBLE);
} else {
contextPreviewImage.setVisibility(View.GONE);
contextPreviewDoc.setVisibility(View.VISIBLE);
contextPreviewAudio.setVisibility(View.GONE);
}
} else {
viewHolder.nonTextReplyContent.setVisibility(View.GONE);
}
maybeShowReply(replyMessage, fileOrImageReply, viewHolder, message);
handleTextQuotes(body, darkBackground, message.getReplyMessage() != null && !fileOrImageReply, message);
if (!message.isPrivateMessage()) {
@ -763,6 +726,46 @@ public class MessageAdapter extends ArrayAdapter<Message> implements DraggableLi
}
}
private void maybeShowReply(Message replyMessage, boolean showAsSeparatePart, ViewHolder viewHolder, Message message) {
if (showAsSeparatePart && replyMessage != null) {
viewHolder.nonTextReplyContent.setVisibility(View.VISIBLE);
WeakReference<ReplyClickListener> listener = new WeakReference<>(replyClickListener);
viewHolder.nonTextReplyContent.setOnClickListener(v -> {
ReplyClickListener l = listener.get();
if (l != null) {
l.onReplyClick(message);
}
});
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);
View contextPreviewDoc = viewHolder.nonTextReplyContent.findViewById(R.id.context_preview_doc);
View contextPreviewAudio = viewHolder.nonTextReplyContent.findViewById(R.id.context_preview_audio);
text.setText(replyMessage.getBodyForReplyPreview(activity.xmppConnectionService));
author.setText(replyMessage.getAvatarName());
if (replyMessage.getFileParams().width > 0 && replyMessage.getFileParams().height > 0) {
contextPreviewImage.setVisibility(View.VISIBLE);
contextPreviewDoc.setVisibility(View.GONE);
contextPreviewAudio.setVisibility(View.GONE);
activity.loadBitmap(replyMessage, contextPreviewImage);
} else if (replyMessage.getFileParams().runtime > 0) {
contextPreviewImage.setVisibility(View.GONE);
contextPreviewDoc.setVisibility(View.GONE);
contextPreviewAudio.setVisibility(View.VISIBLE);
} else {
contextPreviewImage.setVisibility(View.GONE);
contextPreviewDoc.setVisibility(View.VISIBLE);
contextPreviewAudio.setVisibility(View.GONE);
}
} else {
viewHolder.nonTextReplyContent.setVisibility(View.GONE);
}
}
private void displayDownloadableMessage(ViewHolder viewHolder, final Message message, String text, final boolean darkBackground) {
toggleWhisperInfo(viewHolder, message, darkBackground);
viewHolder.image.setVisibility(View.GONE);
@ -770,6 +773,8 @@ public class MessageAdapter extends ArrayAdapter<Message> implements DraggableLi
viewHolder.download_button.setVisibility(View.VISIBLE);
viewHolder.download_button.setText(text);
viewHolder.download_button.setOnClickListener(v -> ConversationFragment.downloadFile(activity, message));
maybeShowReply(message.getReplyMessage(), true, viewHolder, message);
}
private void displayOpenableMessage(ViewHolder viewHolder, final Message message, final boolean darkBackground) {
@ -779,6 +784,8 @@ public class MessageAdapter extends ArrayAdapter<Message> implements DraggableLi
viewHolder.download_button.setVisibility(View.VISIBLE);
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);
}
private void displayLocationMessage(ViewHolder viewHolder, final Message message, final boolean darkBackground) {
@ -788,6 +795,8 @@ public class MessageAdapter extends ArrayAdapter<Message> implements DraggableLi
viewHolder.download_button.setVisibility(View.VISIBLE);
viewHolder.download_button.setText(R.string.show_location);
viewHolder.download_button.setOnClickListener(v -> showLocation(message));
maybeShowReply(message.getReplyMessage(), true, viewHolder, message);
}
private void displayAudioMessage(ViewHolder viewHolder, Message message, boolean darkBackground) {
@ -798,6 +807,8 @@ public class MessageAdapter extends ArrayAdapter<Message> implements DraggableLi
audioPlayer.setVisibility(View.VISIBLE);
AudioPlayer.ViewHolder.get(audioPlayer).setDarkBackground(darkBackground);
this.audioPlayer.init(audioPlayer, message);
maybeShowReply(message.getReplyMessage(), true, viewHolder, message);
}
private void displayMediaPreviewMessage(ViewHolder viewHolder, final Message message, final boolean darkBackground) {
@ -805,6 +816,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);
final FileParams params = message.getFileParams();
final float target = activity.getResources().getDimension(R.dimen.image_preview_width);
final int scaledW;