From d9f26d3d001b5e382e8b95bb14e97b21dbb5f96a Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Wed, 8 Aug 2018 01:37:03 +0200 Subject: [PATCH] Partial support for #264 Signed-off-by: Mario Danic --- app/build.gradle | 2 +- .../MagicSystemMessageViewHolder.java | 39 +++++++++++++++ .../CallNotificationController.java | 6 ++- .../talk/controllers/ChatController.java | 23 ++++++++- .../main/res/layout/item_system_message.xml | 47 +++++++++++++++++++ 5 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java create mode 100644 app/src/main/res/layout/item_system_message.xml diff --git a/app/build.gradle b/app/build.gradle index 4166b9e54..603c85a2a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -157,7 +157,7 @@ dependencies { implementation 'com.github.wooplr:Spotlight:1.2.3' - implementation 'com.github.mario:ChatKit:40a8e9cf69' + implementation 'com.github.mario:ChatKit:64c1a2fee1' implementation 'com.otaliastudios:autocomplete:1.1.0' diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java new file mode 100644 index 000000000..f52be7e06 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java @@ -0,0 +1,39 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * 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 . + */ + +package com.nextcloud.talk.adapters.messages; + +import android.view.View; + +import com.nextcloud.talk.models.json.chat.ChatMessage; +import com.stfalcon.chatkit.messages.MessageHolders; + +public class MagicSystemMessageViewHolder extends MessageHolders.IncomingTextMessageViewHolder { + + public MagicSystemMessageViewHolder(View itemView) { + super(itemView); + } + + @Override + public void onBind(ChatMessage message) { + super.onBind(message); + text.setText(message.getText()); + } +} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java b/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java index 0406b761a..a95293191 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java @@ -485,8 +485,10 @@ public class CallNotificationController extends BaseController { public void onDestroy() { AvatarStatusCodeHolder.getInstance().setStatusCode(0); leavingScreen = true; - handler.removeCallbacksAndMessages(null); - handler = null; + if (handler != null) { + handler.removeCallbacksAndMessages(null); + handler = null; + } dispose(); endMediaAndVibratorNotifications(); super.onDestroy(); diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java index 2dc4ca706..584919533 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java @@ -62,6 +62,7 @@ import com.nextcloud.talk.R; import com.nextcloud.talk.activities.MagicCallActivity; import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder; import com.nextcloud.talk.adapters.messages.MagicOutcomingTextMessageViewHolder; +import com.nextcloud.talk.adapters.messages.MagicSystemMessageViewHolder; import com.nextcloud.talk.api.NcApi; import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.callbacks.MentionAutocompleteCallback; @@ -123,7 +124,7 @@ import retrofit2.Response; @AutoInjector(NextcloudTalkApplication.class) public class ChatController extends BaseController implements MessagesListAdapter.OnLoadMoreListener, - MessagesListAdapter.Formatter, MessagesListAdapter.OnMessageLongClickListener { + MessagesListAdapter.Formatter, MessagesListAdapter.OnMessageLongClickListener, MessageHolders.ContentChecker { private static final String TAG = "ChatController"; @Inject NcApi ncApi; @@ -167,6 +168,8 @@ public class ChatController extends BaseController implements MessagesListAdapte private boolean isFirstMessagesProcessing = true; private boolean isHelloClicked; + private static final byte CONTENT_TYPE_SYSTEM_MESSAGE = 1; + public ChatController(Bundle args) { super(args); setHasOptionsMenu(true); @@ -314,6 +317,10 @@ public class ChatController extends BaseController implements MessagesListAdapte messageHolders.setIncomingTextConfig(MagicIncomingTextMessageViewHolder.class, R.layout.item_custom_incoming_text_message); messageHolders.setOutcomingTextConfig(MagicOutcomingTextMessageViewHolder.class, R.layout.item_custom_outcoming_text_message); + messageHolders.registerContentType(CONTENT_TYPE_SYSTEM_MESSAGE, MagicSystemMessageViewHolder.class, + R.layout.item_system_message, MagicSystemMessageViewHolder.class, R.layout.item_system_message, + this); + adapter = new MessagesListAdapter<>(conversationUser.getUserId(), messageHolders, new ImageLoader() { @Override public void loadImage(ImageView imageView, String url) { @@ -794,7 +801,9 @@ public class ChatController extends BaseController implements MessagesListAdapte for (int i = 0; i < chatMessageList.size(); i++) { if (chatMessageList.size() > i + 1) { - if (chatMessageList.get(i + 1).getActorId().equals(chatMessageList.get(i).getActorId()) && + if (TextUtils.isEmpty(chatMessageList.get(i).getSystemMessage()) && + TextUtils.isEmpty(chatMessageList.get(i + 1).getSystemMessage()) && + chatMessageList.get(i + 1).getActorId().equals(chatMessageList.get(i).getActorId()) && countGroupedMessages < 4 && DateFormatter.isSameDay(chatMessageList.get(i).getCreatedAt(), chatMessageList.get(i + 1).getCreatedAt())) { chatMessageList.get(i).setGrouped(true); @@ -980,4 +989,14 @@ public class ChatController extends BaseController implements MessagesListAdapte } } } + + @Override + public boolean hasContentFor(IMessage message, byte type) { + switch (type) { + case CONTENT_TYPE_SYSTEM_MESSAGE: + return !TextUtils.isEmpty(message.getSystemMessage()); + } + + return false; + } } diff --git a/app/src/main/res/layout/item_system_message.xml b/app/src/main/res/layout/item_system_message.xml new file mode 100644 index 000000000..31b0fba11 --- /dev/null +++ b/app/src/main/res/layout/item_system_message.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + \ No newline at end of file