forked from upstream-mirrors/quik
store recipient model instead of recipients string in conversation
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
package com.moez.QKSMS.data.sync
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
|
||||||
|
class RecipientColumns {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val URI = Uri.parse("content://mms-sms/canonical-address/")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -32,7 +32,7 @@ internal object SyncManager {
|
|||||||
.flatMap { cursor -> cursor.asFlowable() }
|
.flatMap { cursor -> cursor.asFlowable() }
|
||||||
.map { cursor -> Conversation(cursor) }
|
.map { cursor -> Conversation(cursor) }
|
||||||
.distinct { conversation -> conversation.id }
|
.distinct { conversation -> conversation.id }
|
||||||
.doOnNext { conversation -> realm?.insert(conversation) }
|
.doOnNext { conversation -> realm?.insertOrUpdate(conversation) }
|
||||||
.map { conversation -> conversation.id }
|
.map { conversation -> conversation.id }
|
||||||
.concatMap { threadId ->
|
.concatMap { threadId ->
|
||||||
val uri = Uri.withAppendedPath(MessageColumns.URI, threadId.toString())
|
val uri = Uri.withAppendedPath(MessageColumns.URI, threadId.toString())
|
||||||
@@ -42,7 +42,7 @@ internal object SyncManager {
|
|||||||
}
|
}
|
||||||
.filter { message -> message.type == "sms" || message.type == "mms" }
|
.filter { message -> message.type == "sms" || message.type == "mms" }
|
||||||
.distinct { message -> message.id }
|
.distinct { message -> message.id }
|
||||||
.doOnNext { message -> realm?.insert(message) }
|
.doOnNext { message -> realm?.insertOrUpdate(message) }
|
||||||
.count()
|
.count()
|
||||||
.toFlowable()
|
.toFlowable()
|
||||||
.doOnNext {
|
.doOnNext {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.moez.QKSMS.model
|
|||||||
|
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import com.moez.QKSMS.data.sync.ConversationColumns
|
import com.moez.QKSMS.data.sync.ConversationColumns
|
||||||
|
import io.reactivex.Flowable
|
||||||
|
import io.realm.RealmList
|
||||||
import io.realm.RealmObject
|
import io.realm.RealmObject
|
||||||
import io.realm.annotations.PrimaryKey
|
import io.realm.annotations.PrimaryKey
|
||||||
|
|
||||||
@@ -10,7 +12,7 @@ open class Conversation() : RealmObject() {
|
|||||||
@PrimaryKey var id: Long = 0
|
@PrimaryKey var id: Long = 0
|
||||||
var date: Long = 0
|
var date: Long = 0
|
||||||
var messageCount: Int = 0
|
var messageCount: Int = 0
|
||||||
var recipientIds: Int = 0
|
var recipients: RealmList<Recipient> = RealmList()
|
||||||
var snippet: String = ""
|
var snippet: String = ""
|
||||||
var snippetCs: String = ""
|
var snippetCs: String = ""
|
||||||
var read: Int = 0
|
var read: Int = 0
|
||||||
@@ -24,12 +26,16 @@ open class Conversation() : RealmObject() {
|
|||||||
id = cursor.getLong(ConversationColumns.ID)
|
id = cursor.getLong(ConversationColumns.ID)
|
||||||
date = cursor.getLong(ConversationColumns.DATE)
|
date = cursor.getLong(ConversationColumns.DATE)
|
||||||
messageCount = cursor.getInt(ConversationColumns.MESSAGE_COUNT)
|
messageCount = cursor.getInt(ConversationColumns.MESSAGE_COUNT)
|
||||||
recipientIds = cursor.getInt(ConversationColumns.RECIPIENT_IDS)
|
|
||||||
|
Flowable.fromIterable(cursor.getString(ConversationColumns.RECIPIENT_IDS).split(" "))
|
||||||
|
.map { id -> id.toLong() }
|
||||||
|
.map { id -> Recipient(id) }
|
||||||
|
.blockingSubscribe { recipient -> recipients.add(recipient) }
|
||||||
|
|
||||||
snippet = cursor.getString(ConversationColumns.SNIPPET) ?: ""
|
snippet = cursor.getString(ConversationColumns.SNIPPET) ?: ""
|
||||||
snippetCs = cursor.getString(ConversationColumns.SNIPPET_CS) ?: ""
|
snippetCs = cursor.getString(ConversationColumns.SNIPPET_CS) ?: ""
|
||||||
read = cursor.getInt(ConversationColumns.READ)
|
read = cursor.getInt(ConversationColumns.READ)
|
||||||
error = cursor.getInt(ConversationColumns.ERROR)
|
error = cursor.getInt(ConversationColumns.ERROR)
|
||||||
hasAttachment = cursor.getInt(ConversationColumns.HAS_ATTACHMENT)
|
hasAttachment = cursor.getInt(ConversationColumns.HAS_ATTACHMENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.moez.QKSMS.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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -30,7 +30,15 @@ class ConversationAdapter(context: Context, data: OrderedRealmCollection<Convers
|
|||||||
mContext.startActivity(intent)
|
mContext.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewHolder.title.text = conversation?.recipientIds.toString()
|
var title = ""
|
||||||
|
conversation?.recipients?.forEachIndexed { index, recipient ->
|
||||||
|
title += recipient.id
|
||||||
|
if (index < conversation.recipients.size - 1) {
|
||||||
|
title += ", "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
viewHolder.title.text = title
|
||||||
viewHolder.snippet.text = conversation?.snippet
|
viewHolder.snippet.text = conversation?.snippet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user