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