update conversations on request instead of every time

This commit is contained in:
Moez Bhatti
2017-07-25 16:46:30 -04:00
parent 1eacd43f65
commit e120aa9ac0
5 changed files with 37 additions and 10 deletions
@@ -1,6 +1,7 @@
package com.moez.QKSMS.data.sync
import android.net.Uri
import android.util.Log
import com.moez.QKSMS.model.Conversation
import io.realm.Realm
@@ -31,9 +32,12 @@ internal object ConversationSyncManager {
fun copyToRealm(context: android.content.Context) {
val realm = Realm.getDefaultInstance()
val cursor = context.contentResolver.query(ConversationSyncManager.CONVERSATIONS_CONTENT_PROVIDER, ConversationSyncManager.ALL_THREADS_PROJECTION, null, null, "date desc")
Realm.getDefaultInstance().executeTransaction {
realm.executeTransaction {
it.delete(Conversation::class.java)
while (cursor.moveToNext())
it.insertOrUpdate(Conversation(
cursor.getLong(ID),
@@ -47,6 +51,7 @@ internal object ConversationSyncManager {
cursor.getInt(HAS_ATTACHMENT)))
}
Log.i(TAG, "Inserted ${cursor.count} conversations")
cursor.close()
}