mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
allow customizing the ringtone of locally stored contacts too
This commit is contained in:
@ -600,8 +600,12 @@ class ViewContactActivity : ContactActivity() {
|
|||||||
contact_ringtone.text = it?.title
|
contact_ringtone.text = it?.title
|
||||||
|
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
|
if (contact!!.isPrivate()) {
|
||||||
|
LocalContactsHelper(this).updateRingtone(contact!!.contactId, it?.uri ?: "")
|
||||||
|
} else {
|
||||||
ContactsHelper(this).updateRingtone(contact!!.contactId.toString(), it?.uri ?: "")
|
ContactsHelper(this).updateRingtone(contact!!.contactId.toString(), it?.uri ?: "")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, onAlarmSoundDeleted = {}
|
}, onAlarmSoundDeleted = {}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -17,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 = 2)
|
@Database(entities = [LocalContact::class, Group::class], version = 3)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class ContactsDatabase : RoomDatabase() {
|
abstract class ContactsDatabase : RoomDatabase() {
|
||||||
|
|
||||||
@ -40,6 +40,7 @@ abstract class ContactsDatabase : RoomDatabase() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.addMigrations(MIGRATION_1_2)
|
.addMigrations(MIGRATION_1_2)
|
||||||
|
.addMigrations(MIGRATION_2_3)
|
||||||
.build()
|
.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 ''")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,6 @@ const val SOCIAL_VOICE_CALL = 0
|
|||||||
const val SOCIAL_VIDEO_CALL = 1
|
const val SOCIAL_VIDEO_CALL = 1
|
||||||
const val SOCIAL_MESSAGE = 2
|
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
|
fun getProperText(text: String, shouldNormalize: Boolean) = if (shouldNormalize) text.normalizeString() else text
|
||||||
|
@ -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 {
|
private fun getPhotoByteArray(uri: String): ByteArray {
|
||||||
if (uri.isEmpty()) {
|
if (uri.isEmpty()) {
|
||||||
return ByteArray(0)
|
return ByteArray(0)
|
||||||
@ -82,7 +86,7 @@ class LocalContactsHelper(val context: Context) {
|
|||||||
return scaledSizePhotoData
|
return scaledSizePhotoData
|
||||||
}
|
}
|
||||||
|
|
||||||
fun convertLocalContactToContact(localContact: LocalContact?, storedGroups: ArrayList<Group>): Contact? {
|
private fun convertLocalContactToContact(localContact: LocalContact?, storedGroups: ArrayList<Group>): Contact? {
|
||||||
if (localContact == null) {
|
if (localContact == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -120,6 +124,7 @@ class LocalContactsHelper(val context: Context) {
|
|||||||
organization = Organization(localContact.company, localContact.jobPosition)
|
organization = Organization(localContact.company, localContact.jobPosition)
|
||||||
websites = localContact.websites
|
websites = localContact.websites
|
||||||
IMs = localContact.IMs
|
IMs = localContact.IMs
|
||||||
|
ringtone = localContact.ringtone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,6 +155,7 @@ class LocalContactsHelper(val context: Context) {
|
|||||||
jobPosition = contact.organization.jobPosition
|
jobPosition = contact.organization.jobPosition
|
||||||
websites = contact.websites
|
websites = contact.websites
|
||||||
IMs = contact.IMs
|
IMs = contact.IMs
|
||||||
|
ringtone = contact.ringtone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@ interface ContactsDao {
|
|||||||
@Query("UPDATE contacts SET starred = :isStarred WHERE id = :id")
|
@Query("UPDATE contacts SET starred = :isStarred WHERE id = :id")
|
||||||
fun updateStarred(isStarred: Int, id: Int)
|
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)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun insertOrUpdate(contact: LocalContact): Long
|
fun insertOrUpdate(contact: LocalContact): Long
|
||||||
|
|
||||||
|
@ -26,7 +26,8 @@ data class LocalContact(
|
|||||||
@ColumnInfo(name = "company") var company: String,
|
@ColumnInfo(name = "company") var company: String,
|
||||||
@ColumnInfo(name = "job_position") var jobPosition: String,
|
@ColumnInfo(name = "job_position") var jobPosition: String,
|
||||||
@ColumnInfo(name = "websites") var websites: ArrayList<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
|
override fun equals(other: Any?) = id == (other as? LocalContact?)?.id
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user