forked from upstream-mirrors/quik
Fix glitching when filtering conversations
This commit is contained in:
@@ -166,7 +166,7 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
toolbarSearch.textSize = if (state.page is Inbox) 16f else 20f
|
||||
|
||||
toolbar.menu.findItem(R.id.clear)?.run {
|
||||
isVisible = state.page is Inbox && state.page.query.isNotEmpty()
|
||||
isVisible = state.page is Inbox && state.page.showClearButton
|
||||
}
|
||||
|
||||
syncing.setVisible(state.syncing)
|
||||
@@ -174,7 +174,7 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
|
||||
when (state.page) {
|
||||
is Inbox -> {
|
||||
if (toolbarSearch.text.toString() != state.page.query.toString()) toolbarSearch.setText(state.page.query)
|
||||
if (!inbox.isSelected) toolbarSearch.text = null
|
||||
if (recyclerView.adapter != conversationsAdapter) recyclerView.adapter = conversationsAdapter
|
||||
if (conversationsAdapter.flowable != state.page.data) conversationsAdapter.flowable = state.page.data
|
||||
itemTouchHelper.attachToRecyclerView(recyclerView)
|
||||
@@ -182,7 +182,7 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
}
|
||||
|
||||
is Archived -> {
|
||||
toolbarSearch.setText(R.string.title_archived)
|
||||
if (!archived.isSelected) toolbarSearch.setText(R.string.title_archived)
|
||||
if (recyclerView.adapter != conversationsAdapter) recyclerView.adapter = conversationsAdapter
|
||||
if (conversationsAdapter.flowable != state.page.data) conversationsAdapter.flowable = state.page.data
|
||||
itemTouchHelper.attachToRecyclerView(null)
|
||||
@@ -190,14 +190,14 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
}
|
||||
|
||||
is Scheduled -> {
|
||||
toolbarSearch.setText(R.string.title_scheduled)
|
||||
if (!scheduled.isSelected) toolbarSearch.setText(R.string.title_scheduled)
|
||||
recyclerView.adapter = null
|
||||
itemTouchHelper.attachToRecyclerView(null)
|
||||
menuItemAdapter.data = ArrayList()
|
||||
}
|
||||
|
||||
is Blocked -> {
|
||||
toolbarSearch.setText(R.string.title_blocked)
|
||||
if (!blocked.isSelected) toolbarSearch.setText(R.string.title_blocked)
|
||||
recyclerView.adapter = null
|
||||
itemTouchHelper.attachToRecyclerView(null)
|
||||
menuItemAdapter.data = ArrayList()
|
||||
@@ -225,6 +225,10 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
else if (!conversationMenuDialog.isShowing && menuItemAdapter.data.isNotEmpty()) conversationMenuDialog.show()
|
||||
}
|
||||
|
||||
override fun clearSearch() {
|
||||
toolbarSearch.text = null
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.main, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
|
||||
@@ -13,7 +13,7 @@ data class MainState(
|
||||
sealed class MainPage
|
||||
|
||||
data class Inbox(
|
||||
val query: CharSequence = "",
|
||||
val showClearButton: Boolean = false,
|
||||
val data: Flowable<List<InboxItem>>? = null,
|
||||
val menu: List<MenuItem> = ArrayList(),
|
||||
val showArchivedSnackbar: Boolean = false) : MainPage()
|
||||
|
||||
@@ -17,6 +17,8 @@ interface MainView : QkView<MainState> {
|
||||
val swipeConversationIntent: Observable<Int>
|
||||
val undoSwipeConversationIntent: Subject<Unit>
|
||||
|
||||
fun clearSearch()
|
||||
|
||||
}
|
||||
|
||||
enum class DrawerItem { INBOX, ARCHIVED, SCHEDULED, BLOCKED, SETTINGS }
|
||||
@@ -84,23 +84,19 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
.debounce(200, TimeUnit.MILLISECONDS)
|
||||
.withLatestFrom(state, { query, state ->
|
||||
if (state.page is Inbox) {
|
||||
val conversations = conversations.map { list ->
|
||||
list.filter { conversationFilter.filter(it.conversation, query) }
|
||||
val conversations = when {
|
||||
query.isEmpty() -> conversations
|
||||
else -> conversations.map { list -> list.filter { conversationFilter.filter(it.conversation, query) } }
|
||||
}
|
||||
val page = state.page.copy(query = query, data = conversations)
|
||||
|
||||
val page = state.page.copy(showClearButton = query.isNotEmpty(), data = conversations)
|
||||
newState { it.copy(page = page) }
|
||||
}
|
||||
})
|
||||
.subscribe()
|
||||
|
||||
intents += view.queryCancelledIntent
|
||||
.withLatestFrom(state, { _, state ->
|
||||
if (state.page is Inbox) {
|
||||
val page = state.page.copy(query = "")
|
||||
newState { it.copy(page = page) }
|
||||
}
|
||||
})
|
||||
.subscribe()
|
||||
.subscribe { view.clearSearch() }
|
||||
|
||||
intents += view.composeIntent
|
||||
.subscribe { navigator.showCompose() }
|
||||
@@ -114,7 +110,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
.distinctUntilChanged()
|
||||
.doOnNext {
|
||||
when (it) {
|
||||
DrawerItem.INBOX -> newState { it.copy(page = Inbox(query = "", data = conversations)) }
|
||||
DrawerItem.INBOX -> newState { it.copy(page = Inbox(data = conversations)) }
|
||||
DrawerItem.ARCHIVED -> newState { it.copy(page = Archived(messageRepo.getConversations(true))) }
|
||||
DrawerItem.SCHEDULED -> newState { it.copy(page = Scheduled()) }
|
||||
DrawerItem.BLOCKED -> newState { it.copy(page = Blocked()) }
|
||||
@@ -123,13 +119,8 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
.subscribe()
|
||||
|
||||
intents += view.conversationClickIntent
|
||||
.doOnNext { view.clearSearch() }
|
||||
.doOnNext { threadId -> navigator.showConversation(threadId) }
|
||||
.withLatestFrom(state, { _, state ->
|
||||
if (state.page is Inbox && state.page.query != "") {
|
||||
val page = state.page.copy(query = "", data = conversations)
|
||||
newState { it.copy(page = page) }
|
||||
}
|
||||
})
|
||||
.subscribe()
|
||||
|
||||
intents += view.conversationLongClickIntent
|
||||
|
||||
Reference in New Issue
Block a user