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