diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/databases/ContactsDatabase.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/databases/ContactsDatabase.kt index 530b1cde..042ab5c0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/databases/ContactsDatabase.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/databases/ContactsDatabase.kt @@ -5,6 +5,7 @@ import androidx.room.Database import androidx.room.Room import androidx.room.RoomDatabase import androidx.room.TypeConverters +import androidx.room.migration.Migration import androidx.sqlite.db.SupportSQLiteDatabase import com.simplemobiletools.contacts.pro.helpers.Converters import com.simplemobiletools.contacts.pro.helpers.FIRST_CONTACT_ID @@ -16,7 +17,7 @@ import com.simplemobiletools.contacts.pro.models.Group import com.simplemobiletools.contacts.pro.models.LocalContact import java.util.concurrent.Executors -@Database(entities = [LocalContact::class, Group::class], version = 1) +@Database(entities = [LocalContact::class, Group::class], version = 2) @TypeConverters(Converters::class) abstract class ContactsDatabase : RoomDatabase() { @@ -32,13 +33,14 @@ abstract class ContactsDatabase : RoomDatabase() { synchronized(ContactsDatabase::class) { if (db == null) { db = Room.databaseBuilder(context.applicationContext, ContactsDatabase::class.java, "local_contacts.db") - .addCallback(object : Callback() { - override fun onCreate(db: SupportSQLiteDatabase) { - super.onCreate(db) - increaseAutoIncrementIds() - } - }) - .build() + .addCallback(object : Callback() { + override fun onCreate(db: SupportSQLiteDatabase) { + super.onCreate(db) + increaseAutoIncrementIds() + } + }) + .addMigrations(MIGRATION_1_2) + .build() } } } @@ -67,5 +69,13 @@ abstract class ContactsDatabase : RoomDatabase() { } } } + + private val MIGRATION_1_2 = object : Migration(1, 2) { + override fun migrate(database: SupportSQLiteDatabase) { + database.apply { + execSQL("ALTER TABLE contacts ADD COLUMN photo_uri TEXT NOT NULL DEFAULT ''") + } + } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt index 81da9bd4..fa4d911b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt @@ -115,7 +115,7 @@ const val TELEGRAM_PACKAGE = "org.telegram.messenger" const val SIGNAL_PACKAGE = "org.thoughtcrime.securesms" const val WHATSAPP_PACKAGE = "com.whatsapp" -fun getEmptyLocalContact() = LocalContact(0, "", "", "", "", "", "", null, ArrayList(), ArrayList(), ArrayList(), 0, ArrayList(), "", ArrayList(), "", "", ArrayList(), ArrayList()) +fun getEmptyLocalContact() = LocalContact(0, "", "", "", "", "", "", null, "", ArrayList(), ArrayList(), ArrayList(), 0, ArrayList(), "", ArrayList(), "", "", ArrayList(), ArrayList()) fun getProperText(text: String, shouldNormalize: Boolean) = if (shouldNormalize) text.normalizeString() else text diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt index 0f74e15f..ce5007ea 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt @@ -114,6 +114,7 @@ class LocalContactsHelper(val context: Context) { contactId = localContact.id!! thumbnailUri = "" photo = contactPhoto + photoUri = localContact.photoUri notes = localContact.notes groups = storedGroups.filter { localContact.groups.contains(it.id) } as ArrayList organization = Organization(localContact.company, localContact.jobPosition) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/LocalContact.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/LocalContact.kt index a2947246..53f96fcd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/LocalContact.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/LocalContact.kt @@ -15,6 +15,7 @@ data class LocalContact( @ColumnInfo(name = "suffix") var suffix: String, @ColumnInfo(name = "nickname") var nickname: String, @ColumnInfo(name = "photo", typeAffinity = ColumnInfo.BLOB) var photo: ByteArray?, + @ColumnInfo(name = "photo_uri") var photoUri: String, @ColumnInfo(name = "phone_numbers") var phoneNumbers: ArrayList, @ColumnInfo(name = "emails") var emails: ArrayList, @ColumnInfo(name = "events") var events: ArrayList,