mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-28 17:38:55 +03:00
hide "unread mention" bubble in search mode
This commit is contained in:
parent
540ec1ab71
commit
ce248a7fc0
1 changed files with 41 additions and 24 deletions
|
@ -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,10 +219,10 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||||
super.onPostCreate(savedInstanceState)
|
super.onPostCreate(savedInstanceState)
|
||||||
|
|
||||||
|
@ -266,7 +268,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")
|
||||||
|
@ -498,6 +500,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 +513,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()
|
||||||
|
@ -645,7 +649,8 @@ class ConversationsListActivity :
|
||||||
if (!filterState.containsValue(true)) filterableConversationItems = conversationItems
|
if (!filterState.containsValue(true)) filterableConversationItems = conversationItems
|
||||||
filterConversation()
|
filterConversation()
|
||||||
adapter!!.updateDataSet(filterableConversationItems, false)
|
adapter!!.updateDataSet(filterableConversationItems, false)
|
||||||
Handler().postDelayed({ checkToShowUnreadBubble() }, UNREAD_BUBBLE_DELAY.toLong())
|
Handler().postDelayed({ checkToShowUnreadBubble() }, UNREAD_BUBBLE_DELAY
|
||||||
|
.toLong())
|
||||||
fetchOpenConversations(apiVersion)
|
fetchOpenConversations(apiVersion)
|
||||||
binding?.swipeRefreshLayoutView?.isRefreshing = false
|
binding?.swipeRefreshLayoutView?.isRefreshing = false
|
||||||
}, { throwable: Throwable ->
|
}, { throwable: Throwable ->
|
||||||
|
@ -820,7 +825,10 @@ 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) {
|
||||||
checkToShowUnreadBubble()
|
val isSearchActive = searchBehaviorSubject.value
|
||||||
|
if(!isSearchActive!!){
|
||||||
|
checkToShowUnreadBubble()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -869,31 +877,39 @@ class ConversationsListActivity :
|
||||||
binding?.newMentionPopupBubble?.let { viewThemeUtils.material.colorMaterialButtonPrimaryFilled(it) }
|
binding?.newMentionPopupBubble?.let { viewThemeUtils.material.colorMaterialButtonPrimaryFilled(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||||
private fun checkToShowUnreadBubble() {
|
private fun checkToShowUnreadBubble() {
|
||||||
try {
|
searchBehaviorSubject.subscribe { value ->
|
||||||
val lastVisibleItem = layoutManager!!.findLastCompletelyVisibleItemPosition()
|
if (value) {
|
||||||
for (flexItem in conversationItems) {
|
nextUnreadConversationScrollPosition = 0
|
||||||
val conversation: Conversation = (flexItem as ConversationItem).model
|
binding.newMentionPopupBubble.hide()
|
||||||
val position = adapter!!.getGlobalPositionOf(flexItem)
|
} else {
|
||||||
if (hasUnreadItems(conversation) && position > lastVisibleItem) {
|
try {
|
||||||
nextUnreadConversationScrollPosition = position
|
val lastVisibleItem = layoutManager!!.findLastCompletelyVisibleItemPosition()
|
||||||
if (!binding?.newMentionPopupBubble?.isShown!!) {
|
for (flexItem in conversationItems) {
|
||||||
binding?.newMentionPopupBubble?.show()
|
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) =
|
private fun hasUnreadItems(conversation: Conversation) =
|
||||||
|
@ -907,6 +923,7 @@ class ConversationsListActivity :
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun dispose(disposable: Disposable?) {
|
private fun dispose(disposable: Disposable?) {
|
||||||
if (disposable != null && !disposable.isDisposed) {
|
if (disposable != null && !disposable.isDisposed) {
|
||||||
disposable.dispose()
|
disposable.dispose()
|
||||||
|
|
Loading…
Reference in a new issue