hide "unread mention" bubble in search mode

This commit is contained in:
Sowjanya Kota 2023-10-30 19:59:20 +01:00 committed by Marcel Hibbe
parent 540ec1ab71
commit ce248a7fc0

View file

@ -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,9 +825,12 @@ class ConversationsListActivity :
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
val isSearchActive = searchBehaviorSubject.value
if(!isSearchActive!!){
checkToShowUnreadBubble()
}
}
}
})
binding?.recyclerView?.setOnTouchListener { v: View, _: MotionEvent? ->
if (!isDestroyed) {
@ -869,8 +877,14 @@ class ConversationsListActivity :
binding?.newMentionPopupBubble?.let { viewThemeUtils.material.colorMaterialButtonPrimaryFilled(it) }
}
@Suppress("Detekt.TooGenericExceptionCaught")
private fun checkToShowUnreadBubble() {
searchBehaviorSubject.subscribe { value ->
if (value) {
nextUnreadConversationScrollPosition = 0
binding.newMentionPopupBubble.hide()
} else {
try {
val lastVisibleItem = layoutManager!!.findLastCompletelyVisibleItemPosition()
for (flexItem in conversationItems) {
@ -881,11 +895,11 @@ class ConversationsListActivity :
if (!binding?.newMentionPopupBubble?.isShown!!) {
binding?.newMentionPopupBubble?.show()
}
return
}
return@subscribe
}
nextUnreadConversationScrollPosition = 0
binding?.newMentionPopupBubble?.hide()
}
} catch (e: NullPointerException) {
Log.d(
TAG,
@ -895,6 +909,8 @@ class ConversationsListActivity :
)
}
}
}
}
private fun hasUnreadItems(conversation: Conversation) =
conversation.unreadMention ||
@ -907,6 +923,7 @@ class ConversationsListActivity :
startActivity(intent)
}
private fun dispose(disposable: Disposable?) {
if (disposable != null && !disposable.isDisposed) {
disposable.dispose()