From ce248a7fc0e48bb511f38f69e1560e4db3f5e381 Mon Sep 17 00:00:00 2001 From: Sowjanya Kota <101803542+sowjanyakch@users.noreply.github.com> Date: Mon, 30 Oct 2023 19:59:20 +0100 Subject: [PATCH 1/2] hide "unread mention" bubble in search mode --- .../ConversationsListActivity.kt | 65 ++++++++++++------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt index 666663011..c9825447f 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt @@ -131,6 +131,7 @@ import io.reactivex.Observable import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers +import io.reactivex.subjects.BehaviorSubject import org.apache.commons.lang3.builder.CompareToBuilder import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode @@ -197,6 +198,7 @@ class ConversationsListActivity : FilterConversationFragment.MENTION to false, FilterConversationFragment.UNREAD to false ) + val searchBehaviorSubject = BehaviorSubject.createDefault(false) private val onBackPressedCallback = object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { @@ -217,10 +219,10 @@ class ConversationsListActivity : viewThemeUtils.material.themeSearchBarText(binding.searchText) forwardMessage = intent.getBooleanExtra(KEY_FORWARD_MSG_FLAG, false) - onBackPressedDispatcher.addCallback(this, onBackPressedCallback) } + override fun onPostCreate(savedInstanceState: Bundle?) { super.onPostCreate(savedInstanceState) @@ -266,7 +268,7 @@ class ConversationsListActivity : loadUserAvatar(binding.switchAccountButton) viewThemeUtils.material.colorMaterialTextButton(binding.switchAccountButton) - + searchBehaviorSubject.onNext(false) fetchRooms() } else { Log.e(TAG, "userManager.currentUser.blockingGet() returned null") @@ -498,6 +500,7 @@ class ConversationsListActivity : adapter!!.updateDataSet(filterableConversationItems, false) adapter!!.showAllHeaders() binding?.swipeRefreshLayoutView?.isEnabled = false + searchBehaviorSubject.onNext(true) return true } @@ -510,6 +513,7 @@ class ConversationsListActivity : // cancel any pending searches searchHelper!!.cancelSearch() binding?.swipeRefreshLayoutView?.isRefreshing = false + searchBehaviorSubject.onNext(false ) } binding?.swipeRefreshLayoutView?.isEnabled = true searchView!!.onActionViewCollapsed() @@ -645,7 +649,8 @@ class ConversationsListActivity : if (!filterState.containsValue(true)) filterableConversationItems = conversationItems filterConversation() adapter!!.updateDataSet(filterableConversationItems, false) - Handler().postDelayed({ checkToShowUnreadBubble() }, UNREAD_BUBBLE_DELAY.toLong()) + Handler().postDelayed({ checkToShowUnreadBubble() }, UNREAD_BUBBLE_DELAY + .toLong()) fetchOpenConversations(apiVersion) binding?.swipeRefreshLayoutView?.isRefreshing = false }, { throwable: Throwable -> @@ -820,7 +825,10 @@ class ConversationsListActivity : override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { super.onScrollStateChanged(recyclerView, newState) if (newState == RecyclerView.SCROLL_STATE_IDLE) { - checkToShowUnreadBubble() + val isSearchActive = searchBehaviorSubject.value + if(!isSearchActive!!){ + checkToShowUnreadBubble() + } } } }) @@ -869,31 +877,39 @@ class ConversationsListActivity : binding?.newMentionPopupBubble?.let { viewThemeUtils.material.colorMaterialButtonPrimaryFilled(it) } } + @Suppress("Detekt.TooGenericExceptionCaught") private fun checkToShowUnreadBubble() { - try { - val lastVisibleItem = layoutManager!!.findLastCompletelyVisibleItemPosition() - for (flexItem in conversationItems) { - val conversation: Conversation = (flexItem as ConversationItem).model - val position = adapter!!.getGlobalPositionOf(flexItem) - if (hasUnreadItems(conversation) && position > lastVisibleItem) { - nextUnreadConversationScrollPosition = position - if (!binding?.newMentionPopupBubble?.isShown!!) { - binding?.newMentionPopupBubble?.show() + searchBehaviorSubject.subscribe { value -> + if (value) { + nextUnreadConversationScrollPosition = 0 + binding.newMentionPopupBubble.hide() + } else { + try { + val lastVisibleItem = layoutManager!!.findLastCompletelyVisibleItemPosition() + for (flexItem in conversationItems) { + val conversation: Conversation = (flexItem as ConversationItem).model + val position = adapter!!.getGlobalPositionOf(flexItem) + if (hasUnreadItems(conversation) && position > lastVisibleItem) { + nextUnreadConversationScrollPosition = position + if (!binding?.newMentionPopupBubble?.isShown!!) { + binding?.newMentionPopupBubble?.show() + } + return@subscribe + } + nextUnreadConversationScrollPosition = 0 + binding?.newMentionPopupBubble?.hide() } - return + } catch (e: NullPointerException) { + Log.d( + TAG, + "A NPE was caught when trying to show the unread popup bubble. This might happen when the " + + "user already left the conversations-list screen so the popup bubble is not available anymore.", + e + ) } } - nextUnreadConversationScrollPosition = 0 - binding?.newMentionPopupBubble?.hide() - } catch (e: NullPointerException) { - Log.d( - TAG, - "A NPE was caught when trying to show the unread popup bubble. This might happen when the " + - "user already left the conversations-list screen so the popup bubble is not available anymore.", - e - ) - } + } } private fun hasUnreadItems(conversation: Conversation) = @@ -907,6 +923,7 @@ class ConversationsListActivity : startActivity(intent) } + private fun dispose(disposable: Disposable?) { if (disposable != null && !disposable.isDisposed) { disposable.dispose() From 305ec470c8b8cfa321d7ef88d42d4c129ae73df8 Mon Sep 17 00:00:00 2001 From: Sowjanya Kota <101803542+sowjanyakch@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:07:48 +0100 Subject: [PATCH 2/2] format code and suppress KtLint CheckResult rule --- .../ConversationsListActivity.kt | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt index c9825447f..0aa943d05 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt @@ -198,7 +198,7 @@ class ConversationsListActivity : FilterConversationFragment.MENTION to false, FilterConversationFragment.UNREAD to false ) - val searchBehaviorSubject = BehaviorSubject.createDefault(false) + val searchBehaviorSubject = BehaviorSubject.createDefault(false) private val onBackPressedCallback = object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { @@ -222,7 +222,6 @@ class ConversationsListActivity : onBackPressedDispatcher.addCallback(this, onBackPressedCallback) } - override fun onPostCreate(savedInstanceState: Bundle?) { super.onPostCreate(savedInstanceState) @@ -277,6 +276,7 @@ class ConversationsListActivity : showSearchOrToolbar() } + fun filterConversation() { val accountId = UserIdUtils.getIdForUser(userManager.currentUser.blockingGet()) filterState[FilterConversationFragment.UNREAD] = ( @@ -329,6 +329,7 @@ class ConversationsListActivity : ) && (conversation.unreadMessages > 0) ) + FilterConversationFragment.UNREAD -> result = result && (conversation.unreadMessages > 0) } } @@ -513,7 +514,7 @@ class ConversationsListActivity : // cancel any pending searches searchHelper!!.cancelSearch() binding?.swipeRefreshLayoutView?.isRefreshing = false - searchBehaviorSubject.onNext(false ) + searchBehaviorSubject.onNext(false) } binding?.swipeRefreshLayoutView?.isEnabled = true searchView!!.onActionViewCollapsed() @@ -605,6 +606,7 @@ class ConversationsListActivity : fun showSnackbar(text: String) { Snackbar.make(binding.root, text, Snackbar.LENGTH_LONG).show() } + fun fetchRooms() { val includeStatus = isUserStatusAvailable(userManager.currentUser.blockingGet()) @@ -649,8 +651,7 @@ class ConversationsListActivity : if (!filterState.containsValue(true)) filterableConversationItems = conversationItems filterConversation() adapter!!.updateDataSet(filterableConversationItems, false) - Handler().postDelayed({ checkToShowUnreadBubble() }, UNREAD_BUBBLE_DELAY - .toLong()) + Handler().postDelayed({ checkToShowUnreadBubble() }, UNREAD_BUBBLE_DELAY.toLong()) fetchOpenConversations(apiVersion) binding?.swipeRefreshLayoutView?.isRefreshing = false }, { throwable: Throwable -> @@ -826,9 +827,9 @@ class ConversationsListActivity : super.onScrollStateChanged(recyclerView, newState) if (newState == RecyclerView.SCROLL_STATE_IDLE) { val isSearchActive = searchBehaviorSubject.value - if(!isSearchActive!!){ - checkToShowUnreadBubble() - } + if (!isSearchActive!!) { + checkToShowUnreadBubble() + } } } }) @@ -877,7 +878,7 @@ class ConversationsListActivity : binding?.newMentionPopupBubble?.let { viewThemeUtils.material.colorMaterialButtonPrimaryFilled(it) } } - + @SuppressLint("CheckResult") @Suppress("Detekt.TooGenericExceptionCaught") private fun checkToShowUnreadBubble() { searchBehaviorSubject.subscribe { value -> @@ -904,12 +905,13 @@ class ConversationsListActivity : Log.d( TAG, "A NPE was caught when trying to show the unread popup bubble. This might happen when the " + - "user already left the conversations-list screen so the popup bubble is not available anymore.", + "user already left the conversations-list screen so the popup bubble is not available " + + "anymore.", e ) } } - } + } } private fun hasUnreadItems(conversation: Conversation) = @@ -923,7 +925,6 @@ class ConversationsListActivity : startActivity(intent) } - private fun dispose(disposable: Disposable?) { if (disposable != null && !disposable.isDisposed) { disposable.dispose()