Loading data/build.gradle +0 −1 Original line number Diff line number Diff line Loading @@ -79,7 +79,6 @@ dependencies { // coroutines implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-rx2:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-reactive:$coroutines_version" Loading data/src/main/java/com/moez/QKSMS/mapper/CursorToContactImpl.kt +11 −8 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ class CursorToContactImpl @Inject constructor( companion object { val URI = Phone.CONTENT_URI val PROJECTION = arrayOf( Phone._ID, Phone.LOOKUP_KEY, Phone.ACCOUNT_TYPE_AND_DATA_SET, Phone.NUMBER, Loading @@ -44,20 +45,22 @@ class CursorToContactImpl @Inject constructor( Phone.CONTACT_LAST_UPDATED_TIMESTAMP ) const val COLUMN_LOOKUP_KEY = 0 const val COLUMN_ACCOUNT_TYPE = 1 const val COLUMN_NUMBER = 2 const val COLUMN_TYPE = 3 const val COLUMN_LABEL = 4 const val COLUMN_DISPLAY_NAME = 5 const val COLUMN_STARRED = 6 const val CONTACT_LAST_UPDATED = 7 const val COLUMN_ID = 0 const val COLUMN_LOOKUP_KEY = 1 const val COLUMN_ACCOUNT_TYPE = 2 const val COLUMN_NUMBER = 3 const val COLUMN_TYPE = 4 const val COLUMN_LABEL = 5 const val COLUMN_DISPLAY_NAME = 6 const val COLUMN_STARRED = 7 const val CONTACT_LAST_UPDATED = 8 } override fun map(from: Cursor) = Contact().apply { lookupKey = from.getString(COLUMN_LOOKUP_KEY) name = from.getString(COLUMN_DISPLAY_NAME) ?: "" numbers.add(PhoneNumber( id = from.getLong(COLUMN_ID), accountType = from.getString(COLUMN_ACCOUNT_TYPE), address = from.getString(COLUMN_NUMBER) ?: "", type = Phone.getTypeLabel(context.resources, from.getInt(COLUMN_TYPE), Loading data/src/main/java/com/moez/QKSMS/migration/QkRealmMigration.kt +2 −0 Original line number Diff line number Diff line Loading @@ -128,7 +128,9 @@ class QkRealmMigration : RealmMigration { ?.addField("starred", Boolean::class.java, FieldAttribute.REQUIRED) realm.schema.get("PhoneNumber") ?.addField("id", Long::class.java, FieldAttribute.PRIMARY_KEY, FieldAttribute.REQUIRED) ?.addField("accountType", String::class.java, FieldAttribute.REQUIRED) ?.addField("isDefault", Boolean::class.java, FieldAttribute.REQUIRED) version++ } Loading data/src/main/java/com/moez/QKSMS/repository/ContactRepositoryImpl.kt +16 −0 Original line number Diff line number Diff line Loading @@ -137,4 +137,20 @@ class ContactRepositoryImpl @Inject constructor( .observeOn(Schedulers.io()) } override fun setDefaultPhoneNumber(lookupKey: String, phoneNumberId: Long) { Realm.getDefaultInstance().use { realm -> realm.refresh() val contact = realm.where(Contact::class.java) .equalTo("lookupKey", lookupKey) .findFirst() ?: return realm.executeTransaction { contact.numbers.forEach { number -> number.isDefault = number.id == phoneNumberId } } } } } data/src/main/java/com/moez/QKSMS/repository/SyncRepositoryImpl.kt +10 −1 Original line number Diff line number Diff line Loading @@ -243,7 +243,7 @@ class SyncRepositoryImpl @Inject constructor( realm.delete(Contact::class.java) realm.delete(ContactGroup::class.java) contacts = realm.copyToRealm(contacts) contacts = realm.copyToRealmOrUpdate(contacts) realm.insertOrUpdate(getContactGroups(contacts)) // Update all the recipients with the new contacts Loading Loading @@ -286,6 +286,13 @@ class SyncRepositoryImpl @Inject constructor( } private fun getContacts(): List<Contact> { val defaultNumberIds = Realm.getDefaultInstance().use { realm -> realm.where(PhoneNumber::class.java) .equalTo("isDefault", true) .findAll() .map { number -> number.id } } return cursorToContact.getContactsCursor() ?.map { cursor -> cursorToContact.map(cursor) } ?.groupBy { contact -> contact.lookupKey } Loading @@ -297,10 +304,12 @@ class SyncRepositoryImpl @Inject constructor( .flatMap { it.numbers } .sortedBy { it.accountType } .forEach { number -> number.isDefault = defaultNumberIds.any { id -> id == number.id } val duplicate = uniqueNumbers.any { other -> number.accountType != other.accountType && phoneNumberUtils.compare(number.address, other.address) } if (!duplicate) { uniqueNumbers += number } Loading Loading
data/build.gradle +0 −1 Original line number Diff line number Diff line Loading @@ -79,7 +79,6 @@ dependencies { // coroutines implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-rx2:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-reactive:$coroutines_version" Loading
data/src/main/java/com/moez/QKSMS/mapper/CursorToContactImpl.kt +11 −8 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ class CursorToContactImpl @Inject constructor( companion object { val URI = Phone.CONTENT_URI val PROJECTION = arrayOf( Phone._ID, Phone.LOOKUP_KEY, Phone.ACCOUNT_TYPE_AND_DATA_SET, Phone.NUMBER, Loading @@ -44,20 +45,22 @@ class CursorToContactImpl @Inject constructor( Phone.CONTACT_LAST_UPDATED_TIMESTAMP ) const val COLUMN_LOOKUP_KEY = 0 const val COLUMN_ACCOUNT_TYPE = 1 const val COLUMN_NUMBER = 2 const val COLUMN_TYPE = 3 const val COLUMN_LABEL = 4 const val COLUMN_DISPLAY_NAME = 5 const val COLUMN_STARRED = 6 const val CONTACT_LAST_UPDATED = 7 const val COLUMN_ID = 0 const val COLUMN_LOOKUP_KEY = 1 const val COLUMN_ACCOUNT_TYPE = 2 const val COLUMN_NUMBER = 3 const val COLUMN_TYPE = 4 const val COLUMN_LABEL = 5 const val COLUMN_DISPLAY_NAME = 6 const val COLUMN_STARRED = 7 const val CONTACT_LAST_UPDATED = 8 } override fun map(from: Cursor) = Contact().apply { lookupKey = from.getString(COLUMN_LOOKUP_KEY) name = from.getString(COLUMN_DISPLAY_NAME) ?: "" numbers.add(PhoneNumber( id = from.getLong(COLUMN_ID), accountType = from.getString(COLUMN_ACCOUNT_TYPE), address = from.getString(COLUMN_NUMBER) ?: "", type = Phone.getTypeLabel(context.resources, from.getInt(COLUMN_TYPE), Loading
data/src/main/java/com/moez/QKSMS/migration/QkRealmMigration.kt +2 −0 Original line number Diff line number Diff line Loading @@ -128,7 +128,9 @@ class QkRealmMigration : RealmMigration { ?.addField("starred", Boolean::class.java, FieldAttribute.REQUIRED) realm.schema.get("PhoneNumber") ?.addField("id", Long::class.java, FieldAttribute.PRIMARY_KEY, FieldAttribute.REQUIRED) ?.addField("accountType", String::class.java, FieldAttribute.REQUIRED) ?.addField("isDefault", Boolean::class.java, FieldAttribute.REQUIRED) version++ } Loading
data/src/main/java/com/moez/QKSMS/repository/ContactRepositoryImpl.kt +16 −0 Original line number Diff line number Diff line Loading @@ -137,4 +137,20 @@ class ContactRepositoryImpl @Inject constructor( .observeOn(Schedulers.io()) } override fun setDefaultPhoneNumber(lookupKey: String, phoneNumberId: Long) { Realm.getDefaultInstance().use { realm -> realm.refresh() val contact = realm.where(Contact::class.java) .equalTo("lookupKey", lookupKey) .findFirst() ?: return realm.executeTransaction { contact.numbers.forEach { number -> number.isDefault = number.id == phoneNumberId } } } } }
data/src/main/java/com/moez/QKSMS/repository/SyncRepositoryImpl.kt +10 −1 Original line number Diff line number Diff line Loading @@ -243,7 +243,7 @@ class SyncRepositoryImpl @Inject constructor( realm.delete(Contact::class.java) realm.delete(ContactGroup::class.java) contacts = realm.copyToRealm(contacts) contacts = realm.copyToRealmOrUpdate(contacts) realm.insertOrUpdate(getContactGroups(contacts)) // Update all the recipients with the new contacts Loading Loading @@ -286,6 +286,13 @@ class SyncRepositoryImpl @Inject constructor( } private fun getContacts(): List<Contact> { val defaultNumberIds = Realm.getDefaultInstance().use { realm -> realm.where(PhoneNumber::class.java) .equalTo("isDefault", true) .findAll() .map { number -> number.id } } return cursorToContact.getContactsCursor() ?.map { cursor -> cursorToContact.map(cursor) } ?.groupBy { contact -> contact.lookupKey } Loading @@ -297,10 +304,12 @@ class SyncRepositoryImpl @Inject constructor( .flatMap { it.numbers } .sortedBy { it.accountType } .forEach { number -> number.isDefault = defaultNumberIds.any { id -> id == number.id } val duplicate = uniqueNumbers.any { other -> number.accountType != other.accountType && phoneNumberUtils.compare(number.address, other.address) } if (!duplicate) { uniqueNumbers += number } Loading