allow customizing the ringtone of locally stored contacts too

This commit is contained in:
tibbi 2021-02-14 19:31:23 +01:00
parent af7b46f1b7
commit 763dfe3757
6 changed files with 47 additions and 24 deletions

View file

@ -600,7 +600,11 @@ class ViewContactActivity : ContactActivity() {
contact_ringtone.text = it?.title
ensureBackgroundThread {
ContactsHelper(this).updateRingtone(contact!!.contactId.toString(), it?.uri ?: "")
if (contact!!.isPrivate()) {
LocalContactsHelper(this).updateRingtone(contact!!.contactId, it?.uri ?: "")
} else {
ContactsHelper(this).updateRingtone(contact!!.contactId.toString(), it?.uri ?: "")
}
}
}, onAlarmSoundDeleted = {}
)

View file

@ -17,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 = 2)
@Database(entities = [LocalContact::class, Group::class], version = 3)
@TypeConverters(Converters::class)
abstract class ContactsDatabase : RoomDatabase() {
@ -40,6 +40,7 @@ abstract class ContactsDatabase : RoomDatabase() {
}
})
.addMigrations(MIGRATION_1_2)
.addMigrations(MIGRATION_2_3)
.build()
}
}
@ -77,5 +78,13 @@ abstract class ContactsDatabase : RoomDatabase() {
}
}
}
private val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(database: SupportSQLiteDatabase) {
database.apply {
execSQL("ALTER TABLE contacts ADD COLUMN ringtone TEXT DEFAULT ''")
}
}
}
}
}

View file

@ -121,6 +121,6 @@ const val SOCIAL_VOICE_CALL = 0
const val SOCIAL_VIDEO_CALL = 1
const val SOCIAL_MESSAGE = 2
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(), null)
fun getProperText(text: String, shouldNormalize: Boolean) = if (shouldNormalize) text.normalizeString() else text

View file

@ -67,6 +67,10 @@ class LocalContactsHelper(val context: Context) {
}
}
fun updateRingtone(id: Int, ringtone: String) {
context.contactsDB.updateRingtone(ringtone, id)
}
private fun getPhotoByteArray(uri: String): ByteArray {
if (uri.isEmpty()) {
return ByteArray(0)
@ -82,7 +86,7 @@ class LocalContactsHelper(val context: Context) {
return scaledSizePhotoData
}
fun convertLocalContactToContact(localContact: LocalContact?, storedGroups: ArrayList<Group>): Contact? {
private fun convertLocalContactToContact(localContact: LocalContact?, storedGroups: ArrayList<Group>): Contact? {
if (localContact == null) {
return null
}
@ -120,6 +124,7 @@ class LocalContactsHelper(val context: Context) {
organization = Organization(localContact.company, localContact.jobPosition)
websites = localContact.websites
IMs = localContact.IMs
ringtone = localContact.ringtone
}
}
@ -150,6 +155,7 @@ class LocalContactsHelper(val context: Context) {
jobPosition = contact.organization.jobPosition
websites = contact.websites
IMs = contact.IMs
ringtone = contact.ringtone
}
}

View file

@ -23,6 +23,9 @@ interface ContactsDao {
@Query("UPDATE contacts SET starred = :isStarred WHERE id = :id")
fun updateStarred(isStarred: Int, id: Int)
@Query("UPDATE contacts SET ringtone = :ringtone WHERE id = :id")
fun updateRingtone(ringtone: String, id: Int)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertOrUpdate(contact: LocalContact): Long

View file

@ -7,26 +7,27 @@ import androidx.room.PrimaryKey
@Entity(tableName = "contacts", indices = [(Index(value = ["id"], unique = true))])
data class LocalContact(
@PrimaryKey(autoGenerate = true) var id: Int?,
@ColumnInfo(name = "prefix") var prefix: String,
@ColumnInfo(name = "first_name") var firstName: String,
@ColumnInfo(name = "middle_name") var middleName: String,
@ColumnInfo(name = "surname") var surname: String,
@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<PhoneNumber>,
@ColumnInfo(name = "emails") var emails: ArrayList<Email>,
@ColumnInfo(name = "events") var events: ArrayList<Event>,
@ColumnInfo(name = "starred") var starred: Int,
@ColumnInfo(name = "addresses") var addresses: ArrayList<Address>,
@ColumnInfo(name = "notes") var notes: String,
@ColumnInfo(name = "groups") var groups: ArrayList<Long>,
@ColumnInfo(name = "company") var company: String,
@ColumnInfo(name = "job_position") var jobPosition: String,
@ColumnInfo(name = "websites") var websites: ArrayList<String>,
@ColumnInfo(name = "ims") var IMs: ArrayList<IM>) {
@PrimaryKey(autoGenerate = true) var id: Int?,
@ColumnInfo(name = "prefix") var prefix: String,
@ColumnInfo(name = "first_name") var firstName: String,
@ColumnInfo(name = "middle_name") var middleName: String,
@ColumnInfo(name = "surname") var surname: String,
@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<PhoneNumber>,
@ColumnInfo(name = "emails") var emails: ArrayList<Email>,
@ColumnInfo(name = "events") var events: ArrayList<Event>,
@ColumnInfo(name = "starred") var starred: Int,
@ColumnInfo(name = "addresses") var addresses: ArrayList<Address>,
@ColumnInfo(name = "notes") var notes: String,
@ColumnInfo(name = "groups") var groups: ArrayList<Long>,
@ColumnInfo(name = "company") var company: String,
@ColumnInfo(name = "job_position") var jobPosition: String,
@ColumnInfo(name = "websites") var websites: ArrayList<String>,
@ColumnInfo(name = "ims") var IMs: ArrayList<IM>,
@ColumnInfo(name = "ringtone") var ringtone: String?) {
override fun equals(other: Any?) = id == (other as? LocalContact?)?.id