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,8 +600,12 @@ class ViewContactActivity : ContactActivity() {
contact_ringtone.text = it?.title
ensureBackgroundThread {
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

@ -26,7 +26,8 @@ data class LocalContact(
@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 = "ims") var IMs: ArrayList<IM>,
@ColumnInfo(name = "ringtone") var ringtone: String?) {
override fun equals(other: Any?) = id == (other as? LocalContact?)?.id