add reactions for previewMessageHolders

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-04-08 09:19:41 +02:00
parent 0b49f6fc65
commit 65fb284c6c
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
10 changed files with 124 additions and 59 deletions

View File

@ -56,16 +56,7 @@
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" static="false" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
</value>
</option>
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
@ -212,8 +203,7 @@
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<indentOptions>
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
</code_scheme>

View File

@ -27,6 +27,7 @@ import android.widget.ProgressBar;
import com.facebook.drawee.view.SimpleDraweeView;
import com.nextcloud.talk.databinding.ItemCustomIncomingPreviewMessageBinding;
import com.nextcloud.talk.databinding.ReactionsInsideMessageBinding;
import androidx.emoji.widget.EmojiTextView;
@ -77,4 +78,7 @@ public class IncomingPreviewMessageViewHolder extends MagicPreviewMessageViewHol
public ProgressBar getPreviewContactProgressBar() {
return binding.contactProgressBar;
}
@Override
public ReactionsInsideMessageBinding getReactionsBinding(){ return binding.reactions; }
}

View File

@ -52,6 +52,7 @@ import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.components.filebrowser.models.BrowserFile;
import com.nextcloud.talk.components.filebrowser.models.DavResponse;
import com.nextcloud.talk.components.filebrowser.webdav.ReadFilesystemOperation;
import com.nextcloud.talk.databinding.ReactionsInsideMessageBinding;
import com.nextcloud.talk.jobs.DownloadFileToCacheWorker;
import com.nextcloud.talk.models.database.CapabilitiesUtil;
import com.nextcloud.talk.models.database.UserEntity;
@ -111,8 +112,13 @@ public abstract class MagicPreviewMessageViewHolder extends MessageHolders.Incom
ProgressBar progressBar;
ReactionsInsideMessageBinding reactionsBinding;
View clickView;
ReactionsInterface reactionsInterface;
PreviewMessageInterface previewMessageInterface;
public MagicPreviewMessageViewHolder(View itemView, Object payload) {
super(itemView, payload);
NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this);
@ -185,25 +191,30 @@ public abstract class MagicPreviewMessageViewHolder extends MessageHolders.Incom
fetchFileInformation("/" + message.getSelectedIndividualHashMap().get(KEY_PATH), message.activeUser);
}
String accountString =
if(message.activeUser != null && message.activeUser.getUsername() != null && message.activeUser.getBaseUrl() != null){
String accountString =
message.activeUser.getUsername() + "@" +
message.activeUser.getBaseUrl()
.replace("https://", "")
.replace("http://", "");
message.activeUser.getBaseUrl()
.replace("https://", "")
.replace("http://", "");
clickView.setOnClickListener(v -> {
String mimetype = message.getSelectedIndividualHashMap().get(KEY_MIMETYPE);
if (isSupportedForInternalViewer(mimetype) || canBeHandledByExternalApp(mimetype, fileName)) {
openOrDownloadFile(message);
} else {
openFileInFilesApp(message, accountString);
}
});
clickView.setOnClickListener(v -> {
String mimetype = message.getSelectedIndividualHashMap().get(KEY_MIMETYPE);
if (isSupportedForInternalViewer(mimetype) || canBeHandledByExternalApp(mimetype, fileName)) {
openOrDownloadFile(message);
} else {
openFileInFilesApp(message, accountString);
}
});
clickView.setOnLongClickListener(l -> {
onMessageViewLongClick(message, accountString);
return true;
});
} else {
Log.e(TAG, "failed to set click listener because activeUser, username or baseUrl were null");
}
clickView.setOnLongClickListener(l -> {
onMessageViewLongClick(message, accountString);
return true;
});
// check if download worker is already running
String fileId = message.getSelectedIndividualHashMap().get(KEY_ID);
@ -246,8 +257,14 @@ public abstract class MagicPreviewMessageViewHolder extends MessageHolders.Incom
}
itemView.setTag(REPLYABLE_VIEW_TAG, message.isReplyable());
}
reactionsBinding = getReactionsBinding();
new Reaction().showReactions(message, reactionsBinding, context);
reactionsBinding.reactionsEmojiWrapper.setOnClickListener(l -> {
reactionsInterface.onClickReactions(message);
});
}
private Drawable getDrawableFromContactDetails(Context context, String base64) {
Drawable drawable = null;
@ -283,6 +300,8 @@ public abstract class MagicPreviewMessageViewHolder extends MessageHolders.Incom
public abstract ProgressBar getPreviewContactProgressBar();
public abstract ReactionsInsideMessageBinding getReactionsBinding();
private void openOrDownloadFile(ChatMessage message) {
String filename = message.getSelectedIndividualHashMap().get(KEY_NAME);
String mimetype = message.getSelectedIndividualHashMap().get(KEY_MIMETYPE);
@ -410,6 +429,7 @@ public abstract class MagicPreviewMessageViewHolder extends MessageHolders.Incom
private void onMessageViewLongClick(ChatMessage message, String accountString) {
if (isSupportedForInternalViewer(message.getSelectedIndividualHashMap().get(KEY_MIMETYPE))) {
previewMessageInterface.onPreviewMessageLongClick(message);
return;
}
@ -591,4 +611,12 @@ public abstract class MagicPreviewMessageViewHolder extends MessageHolders.Incom
}
});
}
public void assignReactionInterface(ReactionsInterface reactionsInterface) {
this.reactionsInterface = reactionsInterface;
}
public void assignPreviewMessageInterface(PreviewMessageInterface previewMessageInterface) {
this.previewMessageInterface = previewMessageInterface;
}
}

View File

@ -27,6 +27,7 @@ import android.widget.ProgressBar;
import com.facebook.drawee.view.SimpleDraweeView;
import com.nextcloud.talk.databinding.ItemCustomOutcomingPreviewMessageBinding;
import com.nextcloud.talk.databinding.ReactionsInsideMessageBinding;
import androidx.emoji.widget.EmojiTextView;
@ -77,4 +78,7 @@ public class OutcomingPreviewMessageViewHolder extends MagicPreviewMessageViewHo
public ProgressBar getPreviewContactProgressBar() {
return binding.contactProgressBar;
}
@Override
public ReactionsInsideMessageBinding getReactionsBinding() { return binding.reactions; }
}

View File

@ -0,0 +1,7 @@
package com.nextcloud.talk.adapters.messages
import com.nextcloud.talk.models.json.chat.ChatMessage
interface PreviewMessageInterface {
fun onPreviewMessageLongClick(chatMessage: ChatMessage)
}

View File

@ -59,6 +59,9 @@ public class TalkMessagesListAdapter<M extends IMessage> extends MessagesListAda
} else if (holder instanceof OutcomingVoiceMessageViewHolder) {
((OutcomingVoiceMessageViewHolder) holder).assignVoiceMessageInterface(chatController);
((OutcomingVoiceMessageViewHolder) holder).assignReactionInterface(chatController);
} else if (holder instanceof MagicPreviewMessageViewHolder) {
((MagicPreviewMessageViewHolder) holder).assignPreviewMessageInterface(chatController);
((MagicPreviewMessageViewHolder) holder).assignReactionInterface(chatController);
}
}
}

View File

@ -110,6 +110,7 @@ import com.nextcloud.talk.adapters.messages.MagicUnreadNoticeMessageViewHolder
import com.nextcloud.talk.adapters.messages.OutcomingLocationMessageViewHolder
import com.nextcloud.talk.adapters.messages.OutcomingPreviewMessageViewHolder
import com.nextcloud.talk.adapters.messages.OutcomingVoiceMessageViewHolder
import com.nextcloud.talk.adapters.messages.PreviewMessageInterface
import com.nextcloud.talk.adapters.messages.ReactionsInterface
import com.nextcloud.talk.adapters.messages.TalkMessagesListAdapter
import com.nextcloud.talk.adapters.messages.VoiceMessageInterface
@ -206,7 +207,8 @@ class ChatController(args: Bundle) :
MessagesListAdapter.OnMessageViewLongClickListener<IMessage>,
ContentChecker<ChatMessage>,
VoiceMessageInterface,
ReactionsInterface {
ReactionsInterface,
PreviewMessageInterface {
private val binding: ControllerChatBinding by viewBinding(ControllerChatBinding::bind)
@ -2431,6 +2433,14 @@ class ChatController(args: Bundle) :
}
override fun onMessageViewLongClick(view: View?, message: IMessage?) {
openMessageActionsDialog(message)
}
override fun onPreviewMessageLongClick(chatMessage: ChatMessage) {
openMessageActionsDialog(chatMessage)
}
private fun openMessageActionsDialog(message: IMessage?) {
if (hasVisibleItems(message as ChatMessage)) {
activity?.let {
MessageActionsDialog(
@ -2717,6 +2727,7 @@ class ChatController(args: Bundle) :
messageTemp.isOneToOneConversation =
currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL
messageTemp.activeUser = conversationUser
adapter?.update(messageTemp)
}

View File

@ -22,6 +22,7 @@
package com.nextcloud.talk.models.json.chat;
import android.text.TextUtils;
import android.util.Log;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonIgnore;
@ -50,6 +51,8 @@ import kotlin.text.Charsets;
@Parcel
@JsonObject
public class ChatMessage implements MessageContentType, MessageContentType.Image {
private static String TAG = "ChatMessage";
@JsonIgnore
public boolean isGrouped;
@JsonIgnore
@ -102,21 +105,21 @@ public class ChatMessage implements MessageContentType, MessageContentType.Image
@JsonIgnore
List<MessageType> messageTypesToIgnore = Arrays.asList(
MessageType.REGULAR_TEXT_MESSAGE,
MessageType.SYSTEM_MESSAGE,
MessageType.SINGLE_LINK_VIDEO_MESSAGE,
MessageType.SINGLE_LINK_AUDIO_MESSAGE,
MessageType.SINGLE_LINK_MESSAGE,
MessageType.SINGLE_NC_GEOLOCATION_MESSAGE,
MessageType.VOICE_MESSAGE);
MessageType.REGULAR_TEXT_MESSAGE,
MessageType.SYSTEM_MESSAGE,
MessageType.SINGLE_LINK_VIDEO_MESSAGE,
MessageType.SINGLE_LINK_AUDIO_MESSAGE,
MessageType.SINGLE_LINK_MESSAGE,
MessageType.SINGLE_NC_GEOLOCATION_MESSAGE,
MessageType.VOICE_MESSAGE);
public boolean hasFileAttachment() {
if (messageParameters != null && messageParameters.size() > 0) {
for (HashMap.Entry<String, HashMap<String, String>> entry : messageParameters.entrySet()) {
Map<String, String> individualHashMap = entry.getValue();
if(MessageDigest.isEqual(
Objects.requireNonNull(individualHashMap.get("type")).getBytes(Charsets.UTF_8),
("file").getBytes(Charsets.UTF_8))) {
if (MessageDigest.isEqual(
Objects.requireNonNull(individualHashMap.get("type")).getBytes(Charsets.UTF_8),
("file").getBytes(Charsets.UTF_8))) {
return true;
}
}
@ -129,9 +132,9 @@ public class ChatMessage implements MessageContentType, MessageContentType.Image
for (HashMap.Entry<String, HashMap<String, String>> entry : messageParameters.entrySet()) {
Map<String, String> individualHashMap = entry.getValue();
if(MessageDigest.isEqual(
Objects.requireNonNull(individualHashMap.get("type")).getBytes(Charsets.UTF_8),
("geo-location").getBytes(Charsets.UTF_8))) {
if (MessageDigest.isEqual(
Objects.requireNonNull(individualHashMap.get("type")).getBytes(Charsets.UTF_8),
("geo-location").getBytes(Charsets.UTF_8))) {
return true;
}
}
@ -146,13 +149,20 @@ public class ChatMessage implements MessageContentType, MessageContentType.Image
if (messageParameters != null && messageParameters.size() > 0) {
for (HashMap.Entry<String, HashMap<String, String>> entry : messageParameters.entrySet()) {
Map<String, String> individualHashMap = entry.getValue();
if(MessageDigest.isEqual(
Objects.requireNonNull(individualHashMap.get("type")).getBytes(Charsets.UTF_8),
("file").getBytes(Charsets.UTF_8))) {
if (MessageDigest.isEqual(
Objects.requireNonNull(individualHashMap.get("type")).getBytes(Charsets.UTF_8),
("file").getBytes(Charsets.UTF_8))) {
selectedIndividualHashMap = individualHashMap;
if(!isVoiceMessage()){
return (ApiUtils.getUrlForFilePreviewWithFileId(getActiveUser().getBaseUrl(),
individualHashMap.get("id"), NextcloudTalkApplication.Companion.getSharedApplication().getResources().getDimensionPixelSize(R.dimen.maximum_file_preview_size)));
if (!isVoiceMessage()) {
if (getActiveUser() != null && getActiveUser().getBaseUrl() != null) {
return (ApiUtils.getUrlForFilePreviewWithFileId(
getActiveUser().getBaseUrl(),
individualHashMap.get("id"),
NextcloudTalkApplication.Companion.getSharedApplication().getResources().getDimensionPixelSize(R.dimen.maximum_file_preview_size)));
} else {
Log.e(TAG, "getActiveUser() or getActiveUser().getBaseUrl() were null when trying to " +
"getImageUrl()");
}
}
}
}
@ -170,7 +180,7 @@ public class ChatMessage implements MessageContentType, MessageContentType.Image
return MessageType.SYSTEM_MESSAGE;
}
if (isVoiceMessage()){
if (isVoiceMessage()) {
return MessageType.VOICE_MESSAGE;
}
@ -209,20 +219,20 @@ public class ChatMessage implements MessageContentType, MessageContentType.Image
return getText();
} else {
if (MessageType.SINGLE_LINK_GIPHY_MESSAGE == getMessageType()
|| MessageType.SINGLE_LINK_TENOR_MESSAGE == getMessageType()
|| MessageType.SINGLE_LINK_GIF_MESSAGE == getMessageType()) {
|| MessageType.SINGLE_LINK_TENOR_MESSAGE == getMessageType()
|| MessageType.SINGLE_LINK_GIF_MESSAGE == getMessageType()) {
if (getActorId().equals(getActiveUser().getUserId())) {
return (NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_sent_a_gif_you));
} else {
return (String.format(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getString(R.string.nc_sent_a_gif),
!TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest)));
!TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest)));
}
} else if (MessageType.SINGLE_NC_ATTACHMENT_MESSAGE == getMessageType()) {
if (getActorId().equals(getActiveUser().getUserId())) {
return (NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_sent_an_attachment_you));
} else {
return (String.format(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getString(R.string.nc_sent_an_attachment),
!TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest)));
!TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest)));
}
} else if (MessageType.SINGLE_NC_GEOLOCATION_MESSAGE == getMessageType()) {
if (getActorId().equals(getActiveUser().getUserId())) {
@ -250,21 +260,21 @@ public class ChatMessage implements MessageContentType, MessageContentType.Image
return (NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_sent_an_audio_you));
} else {
return (String.format(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getString(R.string.nc_sent_an_audio),
!TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest)));
!TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest)));
}
} else if (MessageType.SINGLE_LINK_VIDEO_MESSAGE == getMessageType()) {
if (getActorId().equals(getActiveUser().getUserId())) {
return (NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_sent_a_video_you));
} else {
return (String.format(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getString(R.string.nc_sent_a_video),
!TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest)));
!TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest)));
}
} else if (MessageType.SINGLE_LINK_IMAGE_MESSAGE == getMessageType()) {
if (getActorId().equals(getActiveUser().getUserId())) {
return (NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_sent_an_image_you));
} else {
return (String.format(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getString(R.string.nc_sent_an_image),
!TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest)));
!TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest)));
}
}
}
@ -300,7 +310,7 @@ public class ChatMessage implements MessageContentType, MessageContentType.Image
true);
} else {
String apiId =
NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest);
NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest);
if (!TextUtils.isEmpty(getActorDisplayName())) {
apiId = getActorDisplayName();
@ -596,7 +606,7 @@ public class ChatMessage implements MessageContentType, MessageContentType.Image
return "ChatMessage(isGrouped=" + this.isGrouped() + ", isOneToOneConversation=" + this.isOneToOneConversation() + ", activeUser=" + this.getActiveUser() + ", selectedIndividualHashMap=" + this.getSelectedIndividualHashMap() + ", isDeleted=" + this.isDeleted() + ", jsonMessageId=" + this.getJsonMessageId() + ", token=" + this.getToken() + ", actorType=" + this.getActorType() + ", actorId=" + this.getActorId() + ", actorDisplayName=" + this.getActorDisplayName() + ", timestamp=" + this.getTimestamp() + ", message=" + this.getMessage() + ", messageParameters=" + this.getMessageParameters() + ", systemMessageType=" + this.getSystemMessageType() + ", replyable=" + this.isReplyable() + ", parentMessage=" + this.getParentMessage() + ", readStatus=" + this.getReadStatus() + ", messageTypesToIgnore=" + this.getMessageTypesToIgnore() + ")";
}
public boolean isVoiceMessage(){
public boolean isVoiceMessage() {
return "voice-message".equals(messageType);
}

View File

@ -173,6 +173,10 @@
android:textColor="@color/warm_grey_four"
app:layout_alignSelf="center"
tools:text="12:38" />
<include
android:id="@+id/reactions"
layout="@layout/reactions_inside_message" />
</com.google.android.flexbox.FlexboxLayout>
</RelativeLayout>

View File

@ -163,6 +163,10 @@
android:textColor="@color/warm_grey_four"
app:layout_alignSelf="center"
tools:text="12:34" />
<include
android:id="@+id/reactions"
layout="@layout/reactions_inside_message" />
</com.google.android.flexbox.FlexboxLayout>
</RelativeLayout>