forked from upstream-mirrors/quik
Use flowable list of unmanaged conversations, fix search
This commit is contained in:
@@ -63,8 +63,9 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
private val cursorToRecipient: CursorToRecipient,
|
private val cursorToRecipient: CursorToRecipient,
|
||||||
private val prefs: Preferences) : MessageRepository {
|
private val prefs: Preferences) : MessageRepository {
|
||||||
|
|
||||||
override fun getConversations(archived: Boolean): RealmResults<Conversation> {
|
override fun getConversations(archived: Boolean): Flowable<List<Conversation>> {
|
||||||
return Realm.getDefaultInstance()
|
val realm = Realm.getDefaultInstance()
|
||||||
|
return realm
|
||||||
.where(Conversation::class.java)
|
.where(Conversation::class.java)
|
||||||
.notEqualTo("id", 0L)
|
.notEqualTo("id", 0L)
|
||||||
.equalTo("archived", archived)
|
.equalTo("archived", archived)
|
||||||
@@ -72,6 +73,10 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
.isNotEmpty("recipients")
|
.isNotEmpty("recipients")
|
||||||
.sort("date", Sort.DESCENDING)
|
.sort("date", Sort.DESCENDING)
|
||||||
.findAllAsync()
|
.findAllAsync()
|
||||||
|
.asFlowable()
|
||||||
|
.filter { it.isLoaded }
|
||||||
|
.filter { it.isValid }
|
||||||
|
.map { conversations -> realm.copyFromRealm(conversations) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getConversationsSnapshot(): List<Conversation> {
|
override fun getConversationsSnapshot(): List<Conversation> {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import model.MmsPart
|
|||||||
|
|
||||||
interface MessageRepository {
|
interface MessageRepository {
|
||||||
|
|
||||||
fun getConversations(archived: Boolean = false): RealmResults<Conversation>
|
fun getConversations(archived: Boolean = false): Flowable<List<Conversation>>
|
||||||
|
|
||||||
fun getConversationsSnapshot(): List<Conversation>
|
fun getConversationsSnapshot(): List<Conversation>
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ package common.base
|
|||||||
|
|
||||||
import android.support.annotation.CallSuper
|
import android.support.annotation.CallSuper
|
||||||
import android.support.v7.widget.RecyclerView
|
import android.support.v7.widget.RecyclerView
|
||||||
|
import android.view.View
|
||||||
|
import common.util.extensions.setVisible
|
||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
|
|
||||||
@@ -29,9 +31,19 @@ import io.reactivex.disposables.Disposable
|
|||||||
*/
|
*/
|
||||||
abstract class FlowableAdapter<T> : QkAdapter<T>() {
|
abstract class FlowableAdapter<T> : QkAdapter<T>() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This view can be set, and the adapter will automatically control the visibility of this view
|
||||||
|
* based on the data
|
||||||
|
*/
|
||||||
|
var emptyView: View? = null
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
value?.setVisible(false)
|
||||||
|
}
|
||||||
|
|
||||||
var flowable: Flowable<List<T>>? = null
|
var flowable: Flowable<List<T>>? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field == value) return
|
if (field === value) return
|
||||||
|
|
||||||
field = value
|
field = value
|
||||||
|
|
||||||
@@ -69,7 +81,10 @@ abstract class FlowableAdapter<T> : QkAdapter<T>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun subscribe() {
|
private fun subscribe() {
|
||||||
disposable = flowable?.subscribe { data = it }
|
disposable = flowable?.subscribe {
|
||||||
|
data = it
|
||||||
|
emptyView?.setVisible(data.isEmpty())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun dispose() {
|
private fun dispose() {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import android.view.ViewGroup
|
|||||||
import com.jakewharton.rxbinding2.view.clicks
|
import com.jakewharton.rxbinding2.view.clicks
|
||||||
import com.jakewharton.rxbinding2.view.longClicks
|
import com.jakewharton.rxbinding2.view.longClicks
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import common.base.QkRealmAdapter
|
import common.base.FlowableAdapter
|
||||||
import common.base.QkViewHolder
|
import common.base.QkViewHolder
|
||||||
import common.util.Colors
|
import common.util.Colors
|
||||||
import common.util.DateFormatter
|
import common.util.DateFormatter
|
||||||
@@ -42,7 +42,7 @@ class ConversationsAdapter @Inject constructor(
|
|||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val dateFormatter: DateFormatter,
|
private val dateFormatter: DateFormatter,
|
||||||
private val colors: Colors
|
private val colors: Colors
|
||||||
) : QkRealmAdapter<Conversation>() {
|
) : FlowableAdapter<Conversation>() {
|
||||||
|
|
||||||
val clicks: Subject<Long> = PublishSubject.create()
|
val clicks: Subject<Long> = PublishSubject.create()
|
||||||
val longClicks: Subject<Long> = PublishSubject.create()
|
val longClicks: Subject<Long> = PublishSubject.create()
|
||||||
@@ -71,7 +71,7 @@ class ConversationsAdapter @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
|
||||||
val conversation = getItem(position)!!
|
val conversation = getItem(position)
|
||||||
val view = viewHolder.itemView
|
val view = viewHolder.itemView
|
||||||
|
|
||||||
view.clicks().subscribe { clicks.onNext(conversation.id) }
|
view.clicks().subscribe { clicks.onNext(conversation.id) }
|
||||||
@@ -86,10 +86,10 @@ class ConversationsAdapter @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemId(index: Int): Long {
|
override fun getItemId(index: Int): Long {
|
||||||
return getItem(index)!!.id
|
return getItem(index).id
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemViewType(position: Int): Int {
|
override fun getItemViewType(position: Int): Int {
|
||||||
return if (getItem(position)!!.read) 0 else 1
|
return if (getItem(position).read) 0 else 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,7 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
|||||||
is Inbox -> {
|
is Inbox -> {
|
||||||
if (!inbox.isSelected) toolbarSearch.text = null
|
if (!inbox.isSelected) toolbarSearch.text = null
|
||||||
if (recyclerView.adapter !== conversationsAdapter) recyclerView.adapter = conversationsAdapter
|
if (recyclerView.adapter !== conversationsAdapter) recyclerView.adapter = conversationsAdapter
|
||||||
conversationsAdapter.updateData(state.page.data)
|
conversationsAdapter.flowable = state.page.data
|
||||||
itemTouchHelper.attachToRecyclerView(recyclerView)
|
itemTouchHelper.attachToRecyclerView(recyclerView)
|
||||||
menuItemAdapter.data = state.page.menu
|
menuItemAdapter.data = state.page.menu
|
||||||
empty.setText(R.string.inbox_empty_text)
|
empty.setText(R.string.inbox_empty_text)
|
||||||
@@ -198,7 +198,7 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
|||||||
is Archived -> {
|
is Archived -> {
|
||||||
if (!archived.isSelected) 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
|
||||||
conversationsAdapter.updateData(state.page.data)
|
conversationsAdapter.flowable = state.page.data
|
||||||
itemTouchHelper.attachToRecyclerView(null)
|
itemTouchHelper.attachToRecyclerView(null)
|
||||||
menuItemAdapter.data = state.page.menu
|
menuItemAdapter.data = state.page.menu
|
||||||
empty.setText(R.string.archived_empty_text)
|
empty.setText(R.string.archived_empty_text)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
package feature.main
|
package feature.main
|
||||||
|
|
||||||
import common.MenuItem
|
import common.MenuItem
|
||||||
import io.realm.RealmResults
|
import io.reactivex.Flowable
|
||||||
import model.Conversation
|
import model.Conversation
|
||||||
|
|
||||||
data class MainState(
|
data class MainState(
|
||||||
@@ -32,12 +32,12 @@ sealed class MainPage
|
|||||||
|
|
||||||
data class Inbox(
|
data class Inbox(
|
||||||
val showClearButton: Boolean = false,
|
val showClearButton: Boolean = false,
|
||||||
val data: RealmResults<Conversation>? = null,
|
val data: Flowable<List<Conversation>>? = null,
|
||||||
val menu: List<MenuItem> = ArrayList(),
|
val menu: List<MenuItem> = ArrayList(),
|
||||||
val showArchivedSnackbar: Boolean = false) : MainPage()
|
val showArchivedSnackbar: Boolean = false) : MainPage()
|
||||||
|
|
||||||
data class Archived(
|
data class Archived(
|
||||||
val data: RealmResults<Conversation>? = null,
|
val data: Flowable<List<Conversation>>? = null,
|
||||||
val menu: List<MenuItem> = ArrayList()) : MainPage()
|
val menu: List<MenuItem> = ArrayList()) : MainPage()
|
||||||
|
|
||||||
data class Scheduled(
|
data class Scheduled(
|
||||||
|
|||||||
@@ -114,11 +114,11 @@ 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 = messageRepo.getConversationsSnapshot()
|
val conversations = state.page.data
|
||||||
.filter { conversationFilter.filter(it, query) }
|
?.map { conversations -> conversations.filter { conversationFilter.filter(it, query) } }
|
||||||
|
|
||||||
val page = state.page.copy(showClearButton = query.isNotEmpty(), data = conversations)
|
val page = state.page.copy(showClearButton = query.isNotEmpty(), data = conversations)
|
||||||
newState { it.copy(page = page) }*/
|
newState { it.copy(page = page) }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
|
|||||||
Reference in New Issue
Block a user