add LocationMessageViewHolder for ChatKit

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2021-05-27 17:35:19 +02:00 committed by Andy Scherzinger
parent 1e2960a72a
commit 4d29a4b638
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
5 changed files with 183 additions and 10 deletions

View File

@ -0,0 +1,78 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* @author Marcel Hibbe
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
* Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.adapters.messages;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.models.json.chat.ChatMessage;
import com.stfalcon.chatkit.messages.MessageHolders;
import javax.inject.Inject;
import autodagger.AutoInjector;
import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.OkHttpClient;
@AutoInjector(NextcloudTalkApplication.class)
public class LocationMessageViewHolder extends MessageHolders.IncomingTextMessageViewHolder<ChatMessage> {
private static String TAG = "LocationMessageViewHolder";
@BindView(R.id.locationText)
TextView messageText;
View progressBar;
@Inject
Context context;
@Inject
OkHttpClient okHttpClient;
public LocationMessageViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
progressBar = itemView.findViewById(R.id.progress_bar);
NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this);
}
@SuppressLint("SetTextI18n")
@Override
public void onBind(ChatMessage message) {
super.onBind(message);
if (message.getMessageType() == ChatMessage.MessageType.SINGLE_NC_GEOLOCATION_MESSAGE) {
Log.d(TAG, "handle geolocation here");
messageText.setText("geolocation...");
}
// text.setText("bbbbbb");
}
}

View File

@ -79,6 +79,7 @@ import com.google.android.flexbox.FlexboxLayout
import com.nextcloud.talk.R
import com.nextcloud.talk.activities.LeafletWebView
import com.nextcloud.talk.activities.MagicCallActivity
import com.nextcloud.talk.adapters.messages.LocationMessageViewHolder
import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder
import com.nextcloud.talk.adapters.messages.MagicOutcomingTextMessageViewHolder
import com.nextcloud.talk.adapters.messages.MagicPreviewMessageViewHolder
@ -134,6 +135,9 @@ import com.otaliastudios.autocomplete.Autocomplete
import com.stfalcon.chatkit.commons.ImageLoader
import com.stfalcon.chatkit.commons.models.IMessage
import com.stfalcon.chatkit.messages.MessageHolders
import com.stfalcon.chatkit.messages.MessageHolders.ContentChecker
import com.stfalcon.chatkit.messages.MessageInput
import com.stfalcon.chatkit.messages.MessagesList
import com.stfalcon.chatkit.messages.MessagesListAdapter
import com.stfalcon.chatkit.utils.DateFormatter
import com.vanniktech.emoji.EmojiPopup
@ -164,7 +168,7 @@ class ChatController(args: Bundle) :
MessagesListAdapter.OnLoadMoreListener,
MessagesListAdapter.Formatter<Date>,
MessagesListAdapter.OnMessageViewLongClickListener<IMessage>,
MessageHolders.ContentChecker<IMessage> {
ContentChecker<ChatMessage> {
private val binding: ControllerChatBinding by viewBinding(ControllerChatBinding::bind)
@Inject
@ -406,9 +410,20 @@ class ChatController(args: Bundle) :
R.layout.item_custom_outcoming_preview_message
)
// messageHolders.setIncomingLocationConfig(
// LocationMessageViewHolder::class.java,
// R.layout.item_custom_location_message
// )
// messageHolders.setOutcomingLocationConfig(
// LocationMessageViewHolder::class.java,
// R.layout.item_custom_location_message
// )
messageHolders.registerContentType(
CONTENT_TYPE_SYSTEM_MESSAGE, MagicSystemMessageViewHolder::class.java,
R.layout.item_system_message, MagicSystemMessageViewHolder::class.java,
CONTENT_TYPE_SYSTEM_MESSAGE,
MagicSystemMessageViewHolder::class.java,
R.layout.item_system_message,
MagicSystemMessageViewHolder::class.java,
R.layout.item_system_message,
this
)
@ -421,6 +436,15 @@ class ChatController(args: Bundle) :
R.layout.item_date_header, this
)
messageHolders.registerContentType(
CONTENT_TYPE_LOCATION,
LocationMessageViewHolder::class.java,
R.layout.item_custom_location_message,
LocationMessageViewHolder::class.java,
R.layout.item_custom_location_message,
this
)
var senderId = ""
if (!conversationUser?.userId.equals("?")) {
senderId = "users/" + conversationUser?.userId
@ -1897,8 +1921,9 @@ class ChatController(args: Bundle) :
return true
}
override fun hasContentFor(message: IMessage, type: Byte): Boolean {
override fun hasContentFor(message: ChatMessage, type: Byte): Boolean {
return when (type) {
CONTENT_TYPE_LOCATION -> return message.isLocationMessage()
CONTENT_TYPE_SYSTEM_MESSAGE -> !TextUtils.isEmpty(message.systemMessage)
CONTENT_TYPE_UNREAD_NOTICE_MESSAGE -> message.id == "-1"
else -> false
@ -2004,6 +2029,7 @@ class ChatController(args: Bundle) :
private const val TAG = "ChatController"
private const val CONTENT_TYPE_SYSTEM_MESSAGE: Byte = 1
private const val CONTENT_TYPE_UNREAD_NOTICE_MESSAGE: Byte = 2
private const val CONTENT_TYPE_LOCATION: Byte = 3
private const val NEW_MESSAGES_POPUP_BUBBLE_DELAY: Long = 200
private const val POP_CURRENT_CONTROLLER_DELAY: Long = 100
private const val LOBBY_TIMER_DELAY: Long = 5000

View File

@ -0,0 +1,11 @@
package com.nextcloud.talk.interfaces
import com.stfalcon.chatkit.commons.models.IMessage
interface ExtendedIMessage : IMessage {
// var isLocationMessage: Boolean
fun isLocationMessage() : Boolean
}

View File

@ -20,17 +20,18 @@
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;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.interfaces.ExtendedIMessage;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.models.json.converters.EnumSystemMessageTypeConverter;
import com.nextcloud.talk.utils.ApiUtils;
import com.nextcloud.talk.utils.TextMatchers;
import com.stfalcon.chatkit.commons.models.IMessage;
import com.stfalcon.chatkit.commons.models.IUser;
import com.stfalcon.chatkit.commons.models.MessageContentType;
@ -46,7 +47,9 @@ import androidx.annotation.Nullable;
@Parcel
@JsonObject
public class ChatMessage implements IMessage, MessageContentType, MessageContentType.Image {
public class ChatMessage implements ExtendedIMessage, MessageContentType, MessageContentType.Image {
private final String TAG = "ChatMessage";
@JsonIgnore
public boolean isGrouped;
@JsonIgnore
@ -87,9 +90,13 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent
public Enum<ReadStatus> readStatus = ReadStatus.NONE;
@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);
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);
public boolean hasFileAttachment() {
if (messageParameters != null && messageParameters.size() > 0) {
@ -108,6 +115,7 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent
for (String key : messageParameters.keySet()) {
Map<String, String> individualHashMap = messageParameters.get(key);
if (individualHashMap.get("type").equals("geo-location")) {
Log.d(TAG, "is geo-location");
return true;
}
}
@ -555,6 +563,11 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent
return "ChatMessage(isGrouped=" + this.isGrouped() + ", isOneToOneConversation=" + this.isOneToOneConversation() + ", activeUser=" + this.getActiveUser() + ", selectedIndividualHashMap=" + this.getSelectedIndividualHashMap() + ", isLinkPreviewAllowed=" + this.isLinkPreviewAllowed() + ", 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() + ")";
}
@Override
public boolean isLocationMessage() {
return hasGeoLocation();
}
public enum MessageType {
REGULAR_TEXT_MESSAGE,
SYSTEM_MESSAGE,

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ @author Marcel Hibbe
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~ Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp">
<TextView
android:id="@+id/locationText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/warm_grey_four"
android:textSize="12sp"
tools:text="17:30"
android:layout_marginStart="8dp"
app:layout_alignSelf="center"
app:layout_flexGrow="1"
app:layout_wrapBefore="false"/>
</RelativeLayout>