Skip to content

Commit

Permalink
WIP file captions
Browse files Browse the repository at this point in the history
- Added dialog_file_attachment_preview.xml
- Added FileAttachmentPreviewFragment.kt
- Edited ChatActivity to add captions to uploaded files, also refactored some code
- Edited the Outgoing, Incoming, and Generic Preview holders to have a caption
- Fixed some bugs with RemoteFileBrowser

Signed-off-by: Julius Linus <[email protected]>
  • Loading branch information
rapterjet2004 committed Nov 13, 2023
1 parent 4a92790 commit 21b7264
Show file tree
Hide file tree
Showing 11 changed files with 430 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

package com.nextcloud.talk.adapters.messages;

import android.text.Spanned;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
Expand All @@ -33,6 +35,10 @@
import com.nextcloud.talk.databinding.ItemCustomIncomingPreviewMessageBinding;
import com.nextcloud.talk.databinding.ReactionsInsideMessageBinding;
import com.nextcloud.talk.models.json.chat.ChatMessage;
import com.nextcloud.talk.utils.TextMatchers;

import java.util.HashMap;
import java.util.Objects;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
Expand All @@ -49,7 +55,48 @@ public IncomingPreviewMessageViewHolder(View itemView, Object payload) {
@Override
public void onBind(@NonNull ChatMessage message) {
super.onBind(message);

if(!message.isVoiceMessage()
&& !Objects.equals(message.getMessage(), "{file}")
) {
Spanned processedMessageText = null;
binding.incomingPreviewMessageBubble.setBackgroundResource(R.drawable.shape_grouped_incoming_message);
if (viewThemeUtils != null ) {
processedMessageText = messageUtils.enrichChatMessageText(
binding.messageCaption.getContext(),
message,
true,
viewThemeUtils);
viewThemeUtils.talk.themeIncomingMessageBubble(binding.incomingPreviewMessageBubble, true, false);
}

if (processedMessageText != null) {
processedMessageText = messageUtils.processMessageParameters(
binding.messageCaption.getContext(),
viewThemeUtils,
processedMessageText,
message,
itemView);
}

float textSize = 0;
if (context != null) {
textSize = context.getResources().getDimension(R.dimen.chat_text_size);
}
HashMap<String, HashMap<String, String>> messageParameters = message.getMessageParameters();
if (
(messageParameters == null || messageParameters.size() <= 0) &&
TextMatchers.isMessageWithSingleEmoticonOnly(message.getText())
) {
textSize = (float) (textSize * IncomingTextMessageViewHolder.TEXT_SIZE_MULTIPLIER);
itemView.setSelected(true);
}
binding.messageCaption.setVisibility(View.VISIBLE);
binding.messageCaption.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
binding.messageCaption.setText(processedMessageText);
} else {
binding.incomingPreviewMessageBubble.setBackground(null);
binding.messageCaption.setVisibility(View.GONE);
}
binding.messageAuthor.setText(message.getActorDisplayName());
binding.messageText.setTextColor(ContextCompat.getColor(binding.messageText.getContext(),
R.color.no_emphasis_text));
Expand All @@ -63,6 +110,12 @@ public EmojiTextView getMessageText() {
return binding.messageText;
}

@NonNull
@Override
public EmojiTextView getMessageCaption() {
return binding.messageCaption;
}

@Override
public ProgressBar getProgressBar() {
return binding.progressBar;
Expand Down Expand Up @@ -99,5 +152,4 @@ public ProgressBar getPreviewContactProgressBar() {

@Override
public ReactionsInsideMessageBinding getReactionsBinding(){ return binding.reactions; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

package com.nextcloud.talk.adapters.messages;

import android.text.Spanned;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
Expand All @@ -31,7 +34,12 @@
import com.nextcloud.talk.databinding.ItemCustomOutcomingPreviewMessageBinding;
import com.nextcloud.talk.databinding.ReactionsInsideMessageBinding;
import com.nextcloud.talk.models.json.chat.ChatMessage;
import com.nextcloud.talk.utils.TextMatchers;

import java.util.HashMap;
import java.util.Objects;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.emoji2.widget.EmojiTextView;

Expand All @@ -45,15 +53,60 @@ public OutcomingPreviewMessageViewHolder(View itemView) {
}

@Override
public void onBind(ChatMessage message) {
public void onBind(@NonNull ChatMessage message) {
super.onBind(message);
Log.d("Julius", "The caption is " + message.getMessage());
Log.d("Julius", "will render: " + !Objects.equals(message.getMessage(), "{file}"));
if(!message.isVoiceMessage()
&& !Objects.equals(message.getMessage(), "{file}")
) {
Spanned processedMessageText = null;
binding.outgoingPreviewMessageBubble.setBackgroundResource(R.drawable.shape_grouped_outcoming_message);
if (viewThemeUtils != null) {
processedMessageText = messageUtils.enrichChatMessageText(
binding.messageCaption.getContext(),
message,
false,
viewThemeUtils);
viewThemeUtils.talk.themeOutgoingMessageBubble(binding.outgoingPreviewMessageBubble, true, false);
}

if (processedMessageText != null) {
processedMessageText = messageUtils.processMessageParameters(
binding.messageCaption.getContext(),
viewThemeUtils,
processedMessageText,
message,
itemView);
}

float textSize = 0;
if (context != null) {
textSize = context.getResources().getDimension(R.dimen.chat_text_size);
}
HashMap<String, HashMap<String, String>> messageParameters = message.getMessageParameters();
if (
(messageParameters == null || messageParameters.size() <= 0) &&
TextMatchers.isMessageWithSingleEmoticonOnly(message.getText())
) {
textSize = (float)(textSize * IncomingTextMessageViewHolder.TEXT_SIZE_MULTIPLIER);
itemView.setSelected(true);
}
binding.messageCaption.setVisibility(View.VISIBLE);
binding.messageCaption.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
binding.messageCaption.setText(processedMessageText);
} else {
binding.outgoingPreviewMessageBubble.setBackground(null);
binding.messageCaption.setVisibility(View.GONE);
}

binding.messageText.setTextColor(ContextCompat.getColor(binding.messageText.getContext(),
R.color.no_emphasis_text));
binding.messageTime.setTextColor(ContextCompat.getColor(binding.messageText.getContext(),
R.color.no_emphasis_text));
}

@NonNull
@Override
public EmojiTextView getMessageText() {
return binding.messageText;
Expand All @@ -64,21 +117,25 @@ public ProgressBar getProgressBar() {
return binding.progressBar;
}

@NonNull
@Override
public View getPreviewContainer() {
return binding.previewContainer;
}

@NonNull
@Override
public MaterialCardView getPreviewContactContainer() {
return binding.contactContainer;
}

@NonNull
@Override
public ImageView getPreviewContactPhoto() {
return binding.contactPhoto;
}

@NonNull
@Override
public EmojiTextView getPreviewContactName() {
return binding.contactName;
Expand All @@ -91,4 +148,8 @@ public ProgressBar getPreviewContactProgressBar() {

@Override
public ReactionsInsideMessageBinding getReactionsBinding() { return binding.reactions; }

@NonNull
@Override
public EmojiTextView getMessageCaption() { return binding.messageCaption; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ import com.nextcloud.talk.databinding.ReactionsInsideMessageBinding
import com.nextcloud.talk.extensions.loadChangelogBotAvatar
import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.DateUtils
import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.DrawableUtils.getDrawableResourceIdForMimeType
import com.nextcloud.talk.utils.FileViewerUtils
import com.nextcloud.talk.utils.FileViewerUtils.ProgressUi
import com.nextcloud.talk.utils.message.MessageUtils
import com.stfalcon.chatkit.messages.MessageHolders.IncomingImageMessageViewHolder
import io.reactivex.Single
import io.reactivex.SingleObserver
Expand All @@ -80,6 +82,12 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
@Inject
lateinit var dateUtils: DateUtils

@Inject
lateinit var messageUtils: MessageUtils

@Inject
lateinit var userManager: UserManager

@JvmField
@Inject
var okHttpClient: OkHttpClient? = null
Expand Down Expand Up @@ -111,6 +119,7 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
if (message.getCalculateMessageType() === ChatMessage.MessageType.SINGLE_NC_ATTACHMENT_MESSAGE) {
fileViewerUtils = FileViewerUtils(context!!, message.activeUser!!)
val fileName = message.selectedIndividualHashMap!![KEY_NAME]

messageText.text = fileName

if (message.activeUser != null &&
Expand Down Expand Up @@ -312,6 +321,7 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
}

abstract val messageText: EmojiTextView
abstract val messageCaption: EmojiTextView
abstract val previewContainer: View
abstract val previewContactContainer: MaterialCardView
abstract val previewContactPhoto: ImageView
Expand Down
Loading

0 comments on commit 21b7264

Please sign in to comment.