allow changing contact ringtones from the View screen too
This commit is contained in:
parent
43e8dd3303
commit
af7b46f1b7
|
@ -2,6 +2,7 @@ package com.simplemobiletools.contacts.pro.activities
|
|||
|
||||
import android.content.ContentUris
|
||||
import android.content.Intent
|
||||
import android.media.AudioManager
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
|
@ -10,6 +11,7 @@ import android.view.View
|
|||
import android.view.WindowManager
|
||||
import android.widget.RelativeLayout
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.SelectAlarmSoundDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
|
@ -589,6 +591,20 @@ class ViewContactActivity : ContactActivity() {
|
|||
}
|
||||
|
||||
contact_ringtone.copyOnLongClick(contact_ringtone.text.toString())
|
||||
|
||||
contact_ringtone.setOnClickListener {
|
||||
val currentRingtone = contact!!.ringtone ?: getDefaultAlarmSound(RingtoneManager.TYPE_RINGTONE).uri
|
||||
SelectAlarmSoundDialog(this, currentRingtone, AudioManager.STREAM_RING, PICK_RINGTONE_INTENT_ID, RingtoneManager.TYPE_RINGTONE, true,
|
||||
onAlarmPicked = {
|
||||
contact!!.ringtone = it?.uri
|
||||
contact_ringtone.text = it?.title
|
||||
|
||||
ensureBackgroundThread {
|
||||
ContactsHelper(this).updateRingtone(contact!!.contactId.toString(), it?.uri ?: "")
|
||||
}
|
||||
}, onAlarmSoundDeleted = {}
|
||||
)
|
||||
}
|
||||
} else {
|
||||
contact_ringtone_image.beGone()
|
||||
contact_ringtone.beGone()
|
||||
|
|
|
@ -1424,6 +1424,21 @@ class ContactsHelper(val context: Context) {
|
|||
LocalContactsHelper(context).toggleFavorites(localContacts, addToFavorites)
|
||||
}
|
||||
|
||||
fun updateRingtone(contactId: String, newUri: String) {
|
||||
try {
|
||||
val operations = ArrayList<ContentProviderOperation>()
|
||||
val uri = Uri.withAppendedPath(Contacts.CONTENT_URI, contactId)
|
||||
ContentProviderOperation.newUpdate(uri).apply {
|
||||
withValue(Contacts.CUSTOM_RINGTONE, newUri)
|
||||
operations.add(build())
|
||||
}
|
||||
|
||||
context.contentResolver.applyBatch(AUTHORITY, operations)
|
||||
} catch (e: Exception) {
|
||||
context.showErrorToast(e)
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteContact(originalContact: Contact, deleteClones: Boolean = false, callback: (success: Boolean) -> Unit) {
|
||||
ensureBackgroundThread {
|
||||
if (deleteClones) {
|
||||
|
|
Loading…
Reference in New Issue