mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
fix selecting custom files as ringtones
This commit is contained in:
@ -1,11 +1,13 @@
|
|||||||
package com.simplemobiletools.contacts.pro.activities
|
package com.simplemobiletools.contacts.pro.activities
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
import android.graphics.drawable.BitmapDrawable
|
import android.graphics.drawable.BitmapDrawable
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.net.Uri
|
||||||
import android.provider.ContactsContract.CommonDataKinds.*
|
import android.provider.ContactsContract.CommonDataKinds.*
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
@ -30,10 +32,19 @@ import com.simplemobiletools.contacts.pro.models.Contact
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
abstract class ContactActivity : SimpleActivity() {
|
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 contact: Contact? = null
|
||||||
protected var currentContactPhotoPath = ""
|
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) {
|
fun showPhotoPlaceholder(photoView: ImageView) {
|
||||||
val placeholder = BitmapDrawable(resources, getBigLetterPlaceholder(contact?.getNameToDisplay() ?: "A"))
|
val placeholder = BitmapDrawable(resources, getBigLetterPlaceholder(contact?.getNameToDisplay() ?: "A"))
|
||||||
photoView.setImageDrawable(placeholder)
|
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) {
|
private fun getPhoneNumberTypeId(value: String) = when (value) {
|
||||||
getString(R.string.mobile) -> Phone.TYPE_MOBILE
|
getString(R.string.mobile) -> Phone.TYPE_MOBILE
|
||||||
getString(R.string.home) -> Phone.TYPE_HOME
|
getString(R.string.home) -> Phone.TYPE_HOME
|
||||||
|
@ -596,16 +596,8 @@ class ViewContactActivity : ContactActivity() {
|
|||||||
val currentRingtone = contact!!.ringtone ?: getDefaultAlarmSound(RingtoneManager.TYPE_RINGTONE).uri
|
val currentRingtone = contact!!.ringtone ?: getDefaultAlarmSound(RingtoneManager.TYPE_RINGTONE).uri
|
||||||
SelectAlarmSoundDialog(this, currentRingtone, AudioManager.STREAM_RING, PICK_RINGTONE_INTENT_ID, RingtoneManager.TYPE_RINGTONE, true,
|
SelectAlarmSoundDialog(this, currentRingtone, AudioManager.STREAM_RING, PICK_RINGTONE_INTENT_ID, RingtoneManager.TYPE_RINGTONE, true,
|
||||||
onAlarmPicked = {
|
onAlarmPicked = {
|
||||||
contact!!.ringtone = it?.uri
|
|
||||||
contact_ringtone.text = it?.title
|
contact_ringtone.text = it?.title
|
||||||
|
ringtoneUpdated(it?.uri)
|
||||||
ensureBackgroundThread {
|
|
||||||
if (contact!!.isPrivate()) {
|
|
||||||
LocalContactsHelper(this).updateRingtone(contact!!.contactId, it?.uri ?: "")
|
|
||||||
} else {
|
|
||||||
ContactsHelper(this).updateRingtone(contact!!.contactId.toString(), it?.uri ?: "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, onAlarmSoundDeleted = {}
|
}, 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) {
|
private fun getDuplicateContacts(callback: () -> Unit) {
|
||||||
ContactsHelper(this).getDuplicatesOfContact(contact!!, false) { contacts ->
|
ContactsHelper(this).getDuplicatesOfContact(contact!!, false) { contacts ->
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
|
Reference in New Issue
Block a user