diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/UnreadNoticeMessageViewHolder.java b/app/src/main/java/com/nextcloud/talk/adapters/messages/UnreadNoticeMessageViewHolder.java index 6ae3d5003f..2628470c4e 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/UnreadNoticeMessageViewHolder.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/UnreadNoticeMessageViewHolder.java @@ -24,7 +24,6 @@ public UnreadNoticeMessageViewHolder(View itemView, Object payload) { @Override public void viewDetached() { -// messagesListAdapter.deleteById("-1"); } @Override diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index 552a14c8de..1ca68beb3b 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -296,7 +296,6 @@ class ChatActivity : var mentionAutocomplete: Autocomplete<*>? = null var layoutManager: LinearLayoutManager? = null var pullChatMessagesPending = false - var newMessagesCount = 0 var startCallFromNotification: Boolean = false var startCallFromRoomSwitch: Boolean = false @@ -758,8 +757,8 @@ class ChatActivity : removeUnreadMessagesMarker() - if (binding.unreadMessagesPopup.isShown == true) { - binding.unreadMessagesPopup.hide() + if (binding.unreadMessagesPopup.isShown) { + binding.unreadMessagesPopup.visibility = View.GONE } binding.messagesListView.smoothScrollToPosition(0) } @@ -770,8 +769,8 @@ class ChatActivity : if (code.toString().startsWith("2")) { myFirstMessage = state.message - if (binding.unreadMessagesPopup.isShown == true) { - binding.unreadMessagesPopup.hide() + if (binding.unreadMessagesPopup.isShown) { + binding.unreadMessagesPopup.visibility = View.GONE } binding.messagesListView.smoothScrollToPosition(0) @@ -1016,7 +1015,7 @@ class ChatActivity : } private fun removeUnreadMessagesMarker() { - val index = adapter?.getMessagePositionById("-1") + val index = adapter?.getMessagePositionById(UNREAD_MESSAGES_MARKER_ID.toString()) if (index != null && index != -1) { adapter?.items?.removeAt(index) } @@ -1041,22 +1040,9 @@ class ChatActivity : setupSwipeToReply() - binding.unreadMessagesPopup.setRecyclerView(binding.messagesListView) - - binding.unreadMessagesPopup.setPopupBubbleListener { _ -> - if (newMessagesCount != 0) { - val scrollPosition = if (newMessagesCount - 1 < 0) { - 0 - } else { - newMessagesCount - 1 - } - Handler().postDelayed( - { - binding.messagesListView.smoothScrollToPosition(scrollPosition) - }, - NEW_MESSAGES_POPUP_BUBBLE_DELAY - ) - } + binding.unreadMessagesPopup.setOnClickListener { + binding.messagesListView.smoothScrollToPosition(0) + binding.unreadMessagesPopup.visibility = View.GONE } binding.scrollDownButton.setOnClickListener { @@ -1075,21 +1061,14 @@ class ChatActivity : super.onScrollStateChanged(recyclerView, newState) if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { - if (layoutManager!!.findFirstCompletelyVisibleItemPosition() > 0 && - !binding.unreadMessagesPopup.isShown - ) { - binding.scrollDownButton.visibility = View.VISIBLE - } else { + if (isScrolledToBottom()) { + binding.unreadMessagesPopup.visibility = View.GONE binding.scrollDownButton.visibility = View.GONE - } - - if (newMessagesCount != 0 && layoutManager != null) { - if (layoutManager!!.findFirstCompletelyVisibleItemPosition() < newMessagesCount) { - newMessagesCount = 0 - - if (binding.unreadMessagesPopup.isShown) { - binding.unreadMessagesPopup.hide() - } + } else { + if (binding.unreadMessagesPopup.isShown) { + binding.scrollDownButton.visibility = View.GONE + } else { + binding.scrollDownButton.visibility = View.VISIBLE } } } @@ -2677,7 +2656,7 @@ class ChatActivity : scrollToBottom = true } else { scrollToBottom = false - binding.unreadMessagesPopup.show() + binding.unreadMessagesPopup.visibility = View.VISIBLE // here we have the problem that the chat jumps for every update } } @@ -2698,13 +2677,18 @@ class ChatActivity : it.addToStart(chatMessage, scrollToBottom) } } + + // workaround to jump back to unread messages marker + if (setUnreadMessagesMarker) { + scrollToFirstUnreadMessage() + } } private fun isScrolledToBottom() = layoutManager?.findFirstVisibleItemPosition() == 0 private fun setUnreadMessageMarker(chatMessageList: List) { val unreadChatMessage = ChatMessage() - unreadChatMessage.jsonMessageId = -1 + unreadChatMessage.jsonMessageId = UNREAD_MESSAGES_MARKER_ID unreadChatMessage.actorId = "-1" unreadChatMessage.timestamp = chatMessageList[0].timestamp unreadChatMessage.message = context.getString(R.string.nc_new_messages) @@ -2736,7 +2720,7 @@ class ChatActivity : private fun scrollToFirstUnreadMessage() { adapter?.let { - scrollToAndCenterMessageWithId("-1") + scrollToAndCenterMessageWithId(UNREAD_MESSAGES_MARKER_ID.toString()) } } @@ -3552,7 +3536,7 @@ class ChatActivity : CONTENT_TYPE_POLL -> message.isPoll() CONTENT_TYPE_LINK_PREVIEW -> message.isLinkPreview() CONTENT_TYPE_SYSTEM_MESSAGE -> !TextUtils.isEmpty(message.systemMessage) - CONTENT_TYPE_UNREAD_NOTICE_MESSAGE -> message.id == "-1" + CONTENT_TYPE_UNREAD_NOTICE_MESSAGE -> message.id == UNREAD_MESSAGES_MARKER_ID.toString() CONTENT_TYPE_CALL_STARTED -> message.id == "-2" CONTENT_TYPE_TEMP -> message.id == "-3" CONTENT_TYPE_DECK_CARD -> message.isDeckCard() @@ -3762,6 +3746,7 @@ class ChatActivity : private const val CONTENT_TYPE_LINK_PREVIEW: Byte = 7 private const val CONTENT_TYPE_DECK_CARD: Byte = 8 private const val CONTENT_TYPE_TEMP: Byte = 9 + private const val UNREAD_MESSAGES_MARKER_ID = -1 private const val NEW_MESSAGES_POPUP_BUBBLE_DELAY: Long = 200 private const val GET_ROOM_INFO_DELAY_NORMAL: Long = 30000 private const val GET_ROOM_INFO_DELAY_LOBBY: Long = 5000 diff --git a/app/src/main/res/layout/activity_chat.xml b/app/src/main/res/layout/activity_chat.xml index b73e404d93..c6d5e791be 100644 --- a/app/src/main/res/layout/activity_chat.xml +++ b/app/src/main/res/layout/activity_chat.xml @@ -157,8 +157,9 @@ app:textAutoLink="all" tools:visibility="visible" /> -