mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-21 13:18:52 +01:00
@@ -27,6 +27,8 @@ import data.model.Contact
|
|||||||
import data.model.PhoneNumber
|
import data.model.PhoneNumber
|
||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.schedulers.Schedulers
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -44,21 +46,17 @@ class ContactRepository @Inject constructor(val context: Context) {
|
|||||||
.map { id -> Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, id) }
|
.map { id -> Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getContacts(): List<Contact> {
|
fun getUnmanagedContacts(): Flowable<List<Contact>> {
|
||||||
val realm = Realm.getDefaultInstance()
|
val realm = Realm.getDefaultInstance()
|
||||||
val results = realm.copyFromRealm(realm
|
return realm.where(Contact::class.java)
|
||||||
.where(Contact::class.java)
|
.sort("name")
|
||||||
.findAllSorted("name"))
|
.findAllAsync()
|
||||||
realm.close()
|
.asFlowable()
|
||||||
|
.filter { it.isLoaded }
|
||||||
return results
|
.filter { it.isValid }
|
||||||
}
|
.map { realm.copyFromRealm(it) }
|
||||||
|
.subscribeOn(AndroidSchedulers.mainThread())
|
||||||
fun getContact(address: String): Flowable<Contact> {
|
.observeOn(Schedulers.io())
|
||||||
return Flowable.fromPublisher<Contact> { emitter ->
|
|
||||||
getContactBlocking(address)?.let { emitter.onNext(it) }
|
|
||||||
emitter.onComplete()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getContactBlocking(address: String): Contact? {
|
fun getContactBlocking(address: String): Contact? {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
|
|||||||
|
|
||||||
private var draft: String = ""
|
private var draft: String = ""
|
||||||
private val attachments: Subject<List<Bitmap>> = BehaviorSubject.createDefault(ArrayList())
|
private val attachments: Subject<List<Bitmap>> = BehaviorSubject.createDefault(ArrayList())
|
||||||
private val contacts: List<Contact> by lazy { contactsRepo.getContacts() }
|
private val contacts: Observable<List<Contact>> by lazy { contactsRepo.getUnmanagedContacts().toObservable() }
|
||||||
private val contactsReducer: Subject<(List<Contact>) -> List<Contact>> = PublishSubject.create()
|
private val contactsReducer: Subject<(List<Contact>) -> List<Contact>> = PublishSubject.create()
|
||||||
private val selectedContacts: Observable<List<Contact>>
|
private val selectedContacts: Observable<List<Contact>>
|
||||||
private val conversation: Observable<Conversation>
|
private val conversation: Observable<Conversation>
|
||||||
@@ -184,7 +184,7 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
|
|||||||
// Update the list of contact suggestions based on the query input, while also filtering out any contacts
|
// Update the list of contact suggestions based on the query input, while also filtering out any contacts
|
||||||
// that have already been selected
|
// that have already been selected
|
||||||
intents += Observables
|
intents += Observables
|
||||||
.combineLatest(view.queryChangedIntent, selectedContacts, { query, selectedContacts ->
|
.combineLatest(view.queryChangedIntent, contacts, selectedContacts, { query, contacts, selectedContacts ->
|
||||||
contacts
|
contacts
|
||||||
.filterNot { contact -> selectedContacts.contains(contact) }
|
.filterNot { contact -> selectedContacts.contains(contact) }
|
||||||
.filter { contact -> contactFilter.filter(contact, query) }
|
.filter { contact -> contactFilter.filter(contact, query) }
|
||||||
|
|||||||
Reference in New Issue
Block a user