fix selecting custom files as ringtones
This commit is contained in:
parent
cb589b684f
commit
230b438134
3 changed files with 35 additions and 10 deletions
|
@ -1,11 +1,13 @@
|
|||
package com.simplemobiletools.contacts.pro.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.provider.ContactsContract.CommonDataKinds.*
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
|
@ -30,10 +32,19 @@ import com.simplemobiletools.contacts.pro.models.Contact
|
|||
import java.util.*
|
||||
|
||||
abstract class ContactActivity : SimpleActivity() {
|
||||
protected val PICK_RINGTONE_INTENT_ID = 1000
|
||||
protected val PICK_RINGTONE_INTENT_ID = 1500
|
||||
protected var contact: Contact? = null
|
||||
protected var currentContactPhotoPath = ""
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, resultData)
|
||||
if (requestCode == PICK_RINGTONE_INTENT_ID && resultCode == RESULT_OK && resultData != null && resultData.dataString != null) {
|
||||
customRingtoneSelected(Uri.decode(resultData.dataString!!))
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun customRingtoneSelected(ringtonePath: String)
|
||||
|
||||
fun showPhotoPlaceholder(photoView: ImageView) {
|
||||
val placeholder = BitmapDrawable(resources, getBigLetterPlaceholder(contact?.getNameToDisplay() ?: "A"))
|
||||
photoView.setImageDrawable(placeholder)
|
||||
|
|
|
@ -1242,6 +1242,11 @@ class EditContactActivity : ContactActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun customRingtoneSelected(ringtonePath: String) {
|
||||
contact!!.ringtone = ringtonePath
|
||||
contact_ringtone.text = ringtonePath.getFilenameFromPath()
|
||||
}
|
||||
|
||||
private fun getPhoneNumberTypeId(value: String) = when (value) {
|
||||
getString(R.string.mobile) -> Phone.TYPE_MOBILE
|
||||
getString(R.string.home) -> Phone.TYPE_HOME
|
||||
|
|
|
@ -596,16 +596,8 @@ class ViewContactActivity : ContactActivity() {
|
|||
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 {
|
||||
if (contact!!.isPrivate()) {
|
||||
LocalContactsHelper(this).updateRingtone(contact!!.contactId, it?.uri ?: "")
|
||||
} else {
|
||||
ContactsHelper(this).updateRingtone(contact!!.contactId.toString(), it?.uri ?: "")
|
||||
}
|
||||
}
|
||||
ringtoneUpdated(it?.uri)
|
||||
}, onAlarmSoundDeleted = {}
|
||||
)
|
||||
}
|
||||
|
@ -652,6 +644,23 @@ class ViewContactActivity : ContactActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun customRingtoneSelected(ringtonePath: String) {
|
||||
contact_ringtone.text = ringtonePath.getFilenameFromPath()
|
||||
ringtoneUpdated(ringtonePath)
|
||||
}
|
||||
|
||||
private fun ringtoneUpdated(path: String?) {
|
||||
contact!!.ringtone = path
|
||||
|
||||
ensureBackgroundThread {
|
||||
if (contact!!.isPrivate()) {
|
||||
LocalContactsHelper(this).updateRingtone(contact!!.contactId, path ?: "")
|
||||
} else {
|
||||
ContactsHelper(this).updateRingtone(contact!!.contactId.toString(), path ?: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDuplicateContacts(callback: () -> Unit) {
|
||||
ContactsHelper(this).getDuplicatesOfContact(contact!!, false) { contacts ->
|
||||
ensureBackgroundThread {
|
||||
|
|
Loading…
Reference in a new issue