From 0356f5ac3c0c7a9126db7d324c8ab6cbcdccc571 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 3 Jan 2025 14:49:08 +0100 Subject: [PATCH] fix to not accidentally show unread messages popup reason was that the UI was not yet loaded but isScrolledToBottom was already called, so findFirstVisibleItemPosition returned -1. Fix for now is to return true for isScrolledToBottom when position is -1 They does not solve the root cause for now. It should be made sure the code is not executed until UI is ready. A quick try with repeatOnLifecycle(Lifecycle.State.STARTED) when collecting getMessageFlow did not help. Signed-off-by: Marcel Hibbe --- .../java/com/nextcloud/talk/chat/ChatActivity.kt | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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 5f3dbbd32..b34481076 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -65,8 +65,10 @@ import androidx.core.text.bold import androidx.emoji2.text.EmojiCompat import androidx.fragment.app.DialogFragment import androidx.fragment.app.commit +import androidx.lifecycle.Lifecycle import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -2926,17 +2928,10 @@ class ChatActivity : private fun isScrolledToBottom(): Boolean { val position = layoutManager?.findFirstVisibleItemPosition() - Log.d(TAG, "first visible item position is :" + position) - if (position == -1) { - Log.d(TAG, "position is -1") - } else if (position != null) { - val item = adapter?.items?.get(position)?.item - if (item is ChatMessage) { - Log.d(TAG, "first visible item message is :" + item.message) - } else if (item is Date) { - Log.d(TAG, "first visible item time is :" + item.time) - } + Log.w(TAG, "FirstVisibleItemPosition was -1 but true is returned for isScrolledToBottom(). This can " + + "happen when the UI is not yet ready") + return true } return layoutManager?.findFirstVisibleItemPosition() == 0