mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-18 03:48:52 +01:00
Compose contact selection (#7)
* Create empty compose activity * Display all contacts in compose activity * Remove unused method * Updated design in MessagesActivity * Show detailed contacts in compose suggestions * Add observable EditText to Compose Toolbar * Allow querying the list of contacts in Compose * Add remaining fields from mms-sms contentprovider * Update gradle build tools * Added support for contact selection chips
This commit is contained in:
@@ -9,6 +9,8 @@ open class Contact() : RealmObject() {
|
||||
var address: String = ""
|
||||
var name: String = ""
|
||||
|
||||
var inContactsTable: Boolean = false
|
||||
|
||||
constructor(id: Long, address: String) : this() {
|
||||
this.recipientId = id
|
||||
this.address = address
|
||||
|
||||
@@ -30,6 +30,17 @@ class ContactRepository @Inject constructor(val context: Context) {
|
||||
.map { id -> Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, id) }
|
||||
}
|
||||
|
||||
fun getContacts(): List<Contact> {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val results = realm.copyFromRealm(realm
|
||||
.where(Contact::class.java)
|
||||
.equalTo("inContactsTable", true)
|
||||
.findAllSorted("name"))
|
||||
realm.close()
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
fun getContact(recipientId: Long): Flowable<Contact> {
|
||||
return Flowable.fromPublisher<Contact> { emitter ->
|
||||
val contact = getContactFromRealm(recipientId) ?: getContactFromDb(recipientId)
|
||||
@@ -58,7 +69,8 @@ class ContactRepository @Inject constructor(val context: Context) {
|
||||
try {
|
||||
context.contentResolver.query(contactUri, projection, null, null, null).use { contactCursor ->
|
||||
if (contactCursor.moveToFirst()) {
|
||||
contact.name = contactCursor.getString(contactCursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)).orEmpty()
|
||||
contact.inContactsTable = true
|
||||
contact.name = contactCursor.getString(contactCursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME)).orEmpty()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
@@ -71,13 +83,4 @@ class ContactRepository @Inject constructor(val context: Context) {
|
||||
return null
|
||||
}
|
||||
|
||||
fun getContactFromCache(address: String): Contact? {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
val contact = realm.where(Contact::class.java)
|
||||
.equalTo("contactUri", address)
|
||||
.findFirst()
|
||||
realm.close()
|
||||
return contact
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user