set up contactrepository to inflate phone number in contact

This commit is contained in:
Moez Bhatti
2017-08-28 15:13:27 -07:00
parent 7996048658
commit 22489af4c3
10 changed files with 80 additions and 33 deletions
@@ -0,0 +1,19 @@
package com.moez.QKSMS.data.model
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
open class Contact() : RealmObject() {
@PrimaryKey var id: Long = 0
var address: String = ""
/**
* For inflating the contact using the cursor
*/
constructor(id: Long, address: String) : this() {
this.id = id
this.address = address
}
}
@@ -1,6 +1,7 @@
package com.moez.QKSMS.data.model
import android.database.Cursor
import com.moez.QKSMS.data.repository.ContactRepository
import com.moez.QKSMS.data.sync.ConversationColumns
import io.reactivex.Flowable
import io.realm.RealmList
@@ -12,7 +13,7 @@ open class Conversation() : RealmObject() {
@PrimaryKey var id: Long = 0
var date: Long = 0
var messageCount: Int = 0
var recipients: RealmList<Recipient> = RealmList()
var contacts: RealmList<Contact> = RealmList()
var snippet: String = ""
var snippetCs: String = ""
var read: Int = 0
@@ -22,15 +23,16 @@ open class Conversation() : RealmObject() {
/**
* Instantiates a Conversation from the Android SMS ContentProvider
*/
constructor(cursor: Cursor) : this() {
constructor(cursor: Cursor, contacts: ContactRepository) : this() {
id = cursor.getLong(ConversationColumns.ID)
date = cursor.getLong(ConversationColumns.DATE)
messageCount = cursor.getInt(ConversationColumns.MESSAGE_COUNT)
Flowable.fromIterable(cursor.getString(ConversationColumns.RECIPIENT_IDS).split(" "))
.map { id -> id.toLong() }
.map { id -> Recipient(id) }
.blockingSubscribe { recipient -> recipients.add(recipient) }
.map { id -> contacts.getContactBlocking(id) }
.filter { contact -> contact.id != 0L }
.blockingSubscribe { contact -> this.contacts.add(contact) }
snippet = cursor.getString(ConversationColumns.SNIPPET) ?: ""
snippetCs = cursor.getString(ConversationColumns.SNIPPET_CS) ?: ""
@@ -1,17 +0,0 @@
package com.moez.QKSMS.data.model
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
open class Recipient() : RealmObject() {
@PrimaryKey var id: Long = 0
/**
* For inflating the recipient using just the id
*/
constructor(id: Long) : this() {
this.id = id
}
}