mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
adding a PhotoUri field at LocalContact too
This commit is contained in:
@ -5,6 +5,7 @@ import androidx.room.Database
|
|||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import androidx.room.TypeConverters
|
import androidx.room.TypeConverters
|
||||||
|
import androidx.room.migration.Migration
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
import com.simplemobiletools.contacts.pro.helpers.Converters
|
import com.simplemobiletools.contacts.pro.helpers.Converters
|
||||||
import com.simplemobiletools.contacts.pro.helpers.FIRST_CONTACT_ID
|
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 com.simplemobiletools.contacts.pro.models.LocalContact
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
@Database(entities = [LocalContact::class, Group::class], version = 1)
|
@Database(entities = [LocalContact::class, Group::class], version = 2)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class ContactsDatabase : RoomDatabase() {
|
abstract class ContactsDatabase : RoomDatabase() {
|
||||||
|
|
||||||
@ -32,13 +33,14 @@ abstract class ContactsDatabase : RoomDatabase() {
|
|||||||
synchronized(ContactsDatabase::class) {
|
synchronized(ContactsDatabase::class) {
|
||||||
if (db == null) {
|
if (db == null) {
|
||||||
db = Room.databaseBuilder(context.applicationContext, ContactsDatabase::class.java, "local_contacts.db")
|
db = Room.databaseBuilder(context.applicationContext, ContactsDatabase::class.java, "local_contacts.db")
|
||||||
.addCallback(object : Callback() {
|
.addCallback(object : Callback() {
|
||||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||||
super.onCreate(db)
|
super.onCreate(db)
|
||||||
increaseAutoIncrementIds()
|
increaseAutoIncrementIds()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.build()
|
.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 ''")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ const val TELEGRAM_PACKAGE = "org.telegram.messenger"
|
|||||||
const val SIGNAL_PACKAGE = "org.thoughtcrime.securesms"
|
const val SIGNAL_PACKAGE = "org.thoughtcrime.securesms"
|
||||||
const val WHATSAPP_PACKAGE = "com.whatsapp"
|
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
|
fun getProperText(text: String, shouldNormalize: Boolean) = if (shouldNormalize) text.normalizeString() else text
|
||||||
|
|
||||||
|
@ -114,6 +114,7 @@ class LocalContactsHelper(val context: Context) {
|
|||||||
contactId = localContact.id!!
|
contactId = localContact.id!!
|
||||||
thumbnailUri = ""
|
thumbnailUri = ""
|
||||||
photo = contactPhoto
|
photo = contactPhoto
|
||||||
|
photoUri = localContact.photoUri
|
||||||
notes = localContact.notes
|
notes = localContact.notes
|
||||||
groups = storedGroups.filter { localContact.groups.contains(it.id) } as ArrayList<Group>
|
groups = storedGroups.filter { localContact.groups.contains(it.id) } as ArrayList<Group>
|
||||||
organization = Organization(localContact.company, localContact.jobPosition)
|
organization = Organization(localContact.company, localContact.jobPosition)
|
||||||
|
@ -15,6 +15,7 @@ data class LocalContact(
|
|||||||
@ColumnInfo(name = "suffix") var suffix: String,
|
@ColumnInfo(name = "suffix") var suffix: String,
|
||||||
@ColumnInfo(name = "nickname") var nickname: String,
|
@ColumnInfo(name = "nickname") var nickname: String,
|
||||||
@ColumnInfo(name = "photo", typeAffinity = ColumnInfo.BLOB) var photo: ByteArray?,
|
@ColumnInfo(name = "photo", typeAffinity = ColumnInfo.BLOB) var photo: ByteArray?,
|
||||||
|
@ColumnInfo(name = "photo_uri") var photoUri: String,
|
||||||
@ColumnInfo(name = "phone_numbers") var phoneNumbers: ArrayList<PhoneNumber>,
|
@ColumnInfo(name = "phone_numbers") var phoneNumbers: ArrayList<PhoneNumber>,
|
||||||
@ColumnInfo(name = "emails") var emails: ArrayList<Email>,
|
@ColumnInfo(name = "emails") var emails: ArrayList<Email>,
|
||||||
@ColumnInfo(name = "events") var events: ArrayList<Event>,
|
@ColumnInfo(name = "events") var events: ArrayList<Event>,
|
||||||
|
Reference in New Issue
Block a user