mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-18 11:58:52 +01:00
Add support for filtering conversations
This commit is contained in:
@@ -13,6 +13,7 @@ import android.support.v7.widget.helper.ItemTouchHelper
|
||||
import android.view.Gravity
|
||||
import com.jakewharton.rxbinding2.support.v4.widget.drawerOpen
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.jakewharton.rxbinding2.widget.textChanges
|
||||
import com.karumi.dexter.Dexter
|
||||
import com.karumi.dexter.MultiplePermissionsReport
|
||||
import com.karumi.dexter.PermissionToken
|
||||
@@ -41,6 +42,7 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
@Inject lateinit var itemTouchCallback: ConversationItemTouchCallback
|
||||
|
||||
override val viewModelClass = MainViewModel::class
|
||||
override val queryChangedIntent by lazy { toolbarSearch.textChanges() }
|
||||
override val composeIntent by lazy { compose.clicks() }
|
||||
override val drawerOpenIntent by lazy { drawerLayout.drawerOpen(Gravity.START) }
|
||||
override val inboxIntent by lazy { inbox.clicks() }
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.reactivex.subjects.Subject
|
||||
|
||||
interface MainView : QkView<MainState> {
|
||||
|
||||
val queryChangedIntent: Observable<CharSequence>
|
||||
val composeIntent: Observable<Unit>
|
||||
val drawerOpenIntent: Observable<Boolean>
|
||||
val inboxIntent: Observable<Unit>
|
||||
|
||||
@@ -23,6 +23,8 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
@Inject lateinit var markArchived: MarkArchived
|
||||
@Inject lateinit var partialSync: PartialSync
|
||||
|
||||
private val conversations by lazy { messageRepo.getConversations() }
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
|
||||
@@ -43,6 +45,23 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
override fun bindView(view: MainView) {
|
||||
super.bindView(view)
|
||||
|
||||
intents += view.queryChangedIntent.subscribe { query ->
|
||||
val filteredConversations = conversations.map { list ->
|
||||
list.filter { inboxItem ->
|
||||
inboxItem.conversation.recipients.forEach { recipient ->
|
||||
when {
|
||||
recipient.contact?.name?.contains(query, true) == true -> return@filter true
|
||||
recipient.address.contains(query, true) == true -> return@filter true
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
newState { it.copy(page = Inbox(filteredConversations)) }
|
||||
}
|
||||
|
||||
intents += view.composeIntent.subscribe {
|
||||
navigator.showCompose()
|
||||
newState { it.copy(drawerOpen = false) }
|
||||
@@ -53,7 +72,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
}
|
||||
|
||||
intents += view.inboxIntent.subscribe {
|
||||
newState { it.copy(page = Inbox(messageRepo.getConversations()), drawerOpen = false) }
|
||||
newState { it.copy(page = Inbox(conversations), drawerOpen = false) }
|
||||
}
|
||||
|
||||
intents += view.archivedIntent.subscribe {
|
||||
|
||||
Reference in New Issue
Block a user