Move Message and Conversation queries to appropriate Repository

This commit is contained in:
Moez Bhatti
2017-09-22 11:35:49 -04:00
parent ba1b876ce7
commit f6063f9e37
6 changed files with 36 additions and 22 deletions
@@ -3,18 +3,28 @@ package com.moez.QKSMS.data.repository
import com.moez.QKSMS.data.model.Conversation
import io.realm.Realm
import io.realm.RealmResults
import io.realm.Sort
class ConversationRepository {
fun getConversation(threadId: Long): RealmResults<Conversation> {
fun getConversationAsync(threadId: Long): RealmResults<Conversation> {
return Realm.getDefaultInstance()
.where(Conversation::class.java)
.equalTo("id", threadId)
.findAllAsync()
}
fun getConversations(): RealmResults<Conversation> {
return Realm.getDefaultInstance().where(Conversation::class.java).findAllAsync()
fun getConversationsAsync(): RealmResults<Conversation> {
return Realm.getDefaultInstance()
.where(Conversation::class.java)
.findAllSortedAsync("date", Sort.DESCENDING)
}
fun getUnreadConversations(): RealmResults<Conversation> {
return Realm.getDefaultInstance()
.where(Conversation::class.java)
.equalTo("read", false)
.findAllSorted("date", Sort.DESCENDING)
}
}
@@ -13,13 +13,22 @@ import io.realm.RealmResults
class MessageRepository(val context: Context) {
fun getMessages(threadId: Long): RealmResults<Message> {
fun getMessagesAsync(threadId: Long): RealmResults<Message> {
return Realm.getDefaultInstance()
.where(Message::class.java)
.equalTo("threadId", threadId)
.findAllSortedAsync("date")
}
fun getUnreadUnseenMessages(threadId: Long): RealmResults<Message> {
return Realm.getDefaultInstance()
.where(Message::class.java)
.equalTo("threadId", threadId)
.equalTo("seen", false)
.equalTo("read", false)
.findAllSorted("date")
}
fun insertMessage(address: String, body: String, time: Long) {
val cv = ContentValues()