implement "Unread messages" popup with normal button

replace com.nextcloud.ui.popupbubble.PopupBubble with MaterialButton.

com.nextcloud.ui.popupbubble.PopupBubble was forked from
https://github.com/webianks/PopupBubble
which is quite outdated.

com.nextcloud.ui.popupbubble.PopupBubble is still used in ConversationsListActivity but there it should also be removed.

Removing this recycler view stuff will also help a bit to switch to JetpackCompose

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2024-10-29 14:20:25 +01:00
parent 675bc9bec0
commit 29f7265b19
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
3 changed files with 29 additions and 42 deletions

View file

@ -24,7 +24,6 @@ public class UnreadNoticeMessageViewHolder extends MessageHolders.SystemMessageV
@Override
public void viewDetached() {
// messagesListAdapter.deleteById("-1");
}
@Override

View file

@ -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<ChatMessage>) {
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

View file

@ -157,8 +157,9 @@
app:textAutoLink="all"
tools:visibility="visible" />
<com.nextcloud.ui.popupbubble.PopupBubble
<com.google.android.material.button.MaterialButton
android:id="@+id/unreadMessagesPopup"
style="@style/Widget.AppTheme.Button.ElevatedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/typing_indicator_wrapper"
@ -172,6 +173,8 @@
android:minHeight="@dimen/min_size_clickable_area"
android:text="@string/nc_new_messages"
android:theme="@style/Button.Primary"
android:visibility="gone"
tools:visibility="visible"
app:background="@color/colorPrimary"
app:cornerRadius="@dimen/button_corner_radius"
app:icon="@drawable/ic_baseline_arrow_downward_24px" />