Merge pull request #3417 from sowjanyakch/issue-2464-hide-unread-mention-bubble-in-search

hide "unread mention" bubble in search mode
This commit is contained in:
Marcel Hibbe 2023-11-06 15:20:48 +01:00 committed by GitHub
commit cf381744ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -131,6 +131,7 @@ import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.BehaviorSubject
import org.apache.commons.lang3.builder.CompareToBuilder import org.apache.commons.lang3.builder.CompareToBuilder
import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode import org.greenrobot.eventbus.ThreadMode
@ -197,6 +198,7 @@ class ConversationsListActivity :
FilterConversationFragment.MENTION to false, FilterConversationFragment.MENTION to false,
FilterConversationFragment.UNREAD to false FilterConversationFragment.UNREAD to false
) )
val searchBehaviorSubject = BehaviorSubject.createDefault(false)
private val onBackPressedCallback = object : OnBackPressedCallback(true) { private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() { override fun handleOnBackPressed() {
@ -217,7 +219,6 @@ class ConversationsListActivity :
viewThemeUtils.material.themeSearchBarText(binding.searchText) viewThemeUtils.material.themeSearchBarText(binding.searchText)
forwardMessage = intent.getBooleanExtra(KEY_FORWARD_MSG_FLAG, false) forwardMessage = intent.getBooleanExtra(KEY_FORWARD_MSG_FLAG, false)
onBackPressedDispatcher.addCallback(this, onBackPressedCallback) onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
} }
@ -266,7 +267,7 @@ class ConversationsListActivity :
loadUserAvatar(binding.switchAccountButton) loadUserAvatar(binding.switchAccountButton)
viewThemeUtils.material.colorMaterialTextButton(binding.switchAccountButton) viewThemeUtils.material.colorMaterialTextButton(binding.switchAccountButton)
searchBehaviorSubject.onNext(false)
fetchRooms() fetchRooms()
} else { } else {
Log.e(TAG, "userManager.currentUser.blockingGet() returned null") Log.e(TAG, "userManager.currentUser.blockingGet() returned null")
@ -275,6 +276,7 @@ class ConversationsListActivity :
showSearchOrToolbar() showSearchOrToolbar()
} }
fun filterConversation() { fun filterConversation() {
val accountId = UserIdUtils.getIdForUser(userManager.currentUser.blockingGet()) val accountId = UserIdUtils.getIdForUser(userManager.currentUser.blockingGet())
filterState[FilterConversationFragment.UNREAD] = ( filterState[FilterConversationFragment.UNREAD] = (
@ -327,6 +329,7 @@ class ConversationsListActivity :
) && ) &&
(conversation.unreadMessages > 0) (conversation.unreadMessages > 0)
) )
FilterConversationFragment.UNREAD -> result = result && (conversation.unreadMessages > 0) FilterConversationFragment.UNREAD -> result = result && (conversation.unreadMessages > 0)
} }
} }
@ -498,6 +501,7 @@ class ConversationsListActivity :
adapter!!.updateDataSet(filterableConversationItems, false) adapter!!.updateDataSet(filterableConversationItems, false)
adapter!!.showAllHeaders() adapter!!.showAllHeaders()
binding?.swipeRefreshLayoutView?.isEnabled = false binding?.swipeRefreshLayoutView?.isEnabled = false
searchBehaviorSubject.onNext(true)
return true return true
} }
@ -510,6 +514,7 @@ class ConversationsListActivity :
// cancel any pending searches // cancel any pending searches
searchHelper!!.cancelSearch() searchHelper!!.cancelSearch()
binding?.swipeRefreshLayoutView?.isRefreshing = false binding?.swipeRefreshLayoutView?.isRefreshing = false
searchBehaviorSubject.onNext(false)
} }
binding?.swipeRefreshLayoutView?.isEnabled = true binding?.swipeRefreshLayoutView?.isEnabled = true
searchView!!.onActionViewCollapsed() searchView!!.onActionViewCollapsed()
@ -601,6 +606,7 @@ class ConversationsListActivity :
fun showSnackbar(text: String) { fun showSnackbar(text: String) {
Snackbar.make(binding.root, text, Snackbar.LENGTH_LONG).show() Snackbar.make(binding.root, text, Snackbar.LENGTH_LONG).show()
} }
fun fetchRooms() { fun fetchRooms() {
val includeStatus = isUserStatusAvailable(userManager.currentUser.blockingGet()) val includeStatus = isUserStatusAvailable(userManager.currentUser.blockingGet())
@ -820,9 +826,12 @@ class ConversationsListActivity :
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState) super.onScrollStateChanged(recyclerView, newState)
if (newState == RecyclerView.SCROLL_STATE_IDLE) { if (newState == RecyclerView.SCROLL_STATE_IDLE) {
val isSearchActive = searchBehaviorSubject.value
if (!isSearchActive!!) {
checkToShowUnreadBubble() checkToShowUnreadBubble()
} }
} }
}
}) })
binding?.recyclerView?.setOnTouchListener { v: View, _: MotionEvent? -> binding?.recyclerView?.setOnTouchListener { v: View, _: MotionEvent? ->
if (!isDestroyed) { if (!isDestroyed) {
@ -869,8 +878,14 @@ class ConversationsListActivity :
binding?.newMentionPopupBubble?.let { viewThemeUtils.material.colorMaterialButtonPrimaryFilled(it) } binding?.newMentionPopupBubble?.let { viewThemeUtils.material.colorMaterialButtonPrimaryFilled(it) }
} }
@SuppressLint("CheckResult")
@Suppress("Detekt.TooGenericExceptionCaught") @Suppress("Detekt.TooGenericExceptionCaught")
private fun checkToShowUnreadBubble() { private fun checkToShowUnreadBubble() {
searchBehaviorSubject.subscribe { value ->
if (value) {
nextUnreadConversationScrollPosition = 0
binding.newMentionPopupBubble.hide()
} else {
try { try {
val lastVisibleItem = layoutManager!!.findLastCompletelyVisibleItemPosition() val lastVisibleItem = layoutManager!!.findLastCompletelyVisibleItemPosition()
for (flexItem in conversationItems) { for (flexItem in conversationItems) {
@ -881,20 +896,23 @@ class ConversationsListActivity :
if (!binding?.newMentionPopupBubble?.isShown!!) { if (!binding?.newMentionPopupBubble?.isShown!!) {
binding?.newMentionPopupBubble?.show() binding?.newMentionPopupBubble?.show()
} }
return return@subscribe
}
} }
nextUnreadConversationScrollPosition = 0 nextUnreadConversationScrollPosition = 0
binding?.newMentionPopupBubble?.hide() binding?.newMentionPopupBubble?.hide()
}
} catch (e: NullPointerException) { } catch (e: NullPointerException) {
Log.d( Log.d(
TAG, TAG,
"A NPE was caught when trying to show the unread popup bubble. This might happen when the " + "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 e
) )
} }
} }
}
}
private fun hasUnreadItems(conversation: Conversation) = private fun hasUnreadItems(conversation: Conversation) =
conversation.unreadMention || conversation.unreadMention ||