Per-contact colours

Closes #1120
This commit is contained in:
Moez Bhatti
2019-12-15 20:46:33 -05:00
parent 5d62912508
commit 76e0f775d6
35 changed files with 315 additions and 153 deletions
@@ -18,6 +18,8 @@
*/
package com.moez.QKSMS.migration
import android.annotation.SuppressLint
import com.f2prateek.rx.preferences2.RxSharedPreferences
import com.moez.QKSMS.extensions.map
import com.moez.QKSMS.mapper.CursorToContactImpl
import io.realm.DynamicRealm
@@ -29,13 +31,15 @@ import io.realm.Sort
import javax.inject.Inject
class QkRealmMigration @Inject constructor(
private val cursorToContact: CursorToContactImpl
private val cursorToContact: CursorToContactImpl,
private val prefs: RxSharedPreferences
) : RealmMigration {
companion object {
const val SchemaVersion: Long = 9
}
@SuppressLint("ApplySharedPref")
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
var version = oldVersion
@@ -169,6 +173,23 @@ class QkRealmMigration @Inject constructor(
realmContact.setString("photoUri", photoUri)
}
// Migrate conversation themes
val recipients = mutableMapOf<Long, Int>() // Map of recipientId:theme
realm.where("Conversation").findAll().forEach { conversation ->
val pref = prefs.getInteger("theme_${conversation.getLong("id")}")
if (pref.isSet) {
conversation.getList("Recipient").forEach { recipient ->
recipients[recipient.getLong("id")] = pref.get()
}
pref.delete()
}
}
recipients.forEach { (recipientId, theme) ->
prefs.getInteger("theme_$recipientId").set(theme)
}
version++
}