use the new ringtone picker from the Edit screen too
This commit is contained in:
parent
6de5aaeb94
commit
49ec8965af
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.contacts.pro.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
|
@ -7,6 +8,7 @@ import android.graphics.Paint
|
|||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import android.provider.ContactsContract.CommonDataKinds.*
|
||||
import android.widget.ImageView
|
||||
|
@ -33,6 +35,8 @@ import java.util.*
|
|||
|
||||
abstract class ContactActivity : SimpleActivity() {
|
||||
protected val PICK_RINGTONE_INTENT_ID = 1500
|
||||
protected val INTENT_SELECT_RINGTONE = 600
|
||||
|
||||
protected var contact: Contact? = null
|
||||
protected var currentContactPhotoPath = ""
|
||||
|
||||
|
@ -40,11 +44,23 @@ abstract class ContactActivity : SimpleActivity() {
|
|||
super.onActivityResult(requestCode, resultCode, resultData)
|
||||
if (requestCode == PICK_RINGTONE_INTENT_ID && resultCode == RESULT_OK && resultData != null && resultData.dataString != null) {
|
||||
customRingtoneSelected(Uri.decode(resultData.dataString!!))
|
||||
} else if (requestCode == INTENT_SELECT_RINGTONE && resultCode == Activity.RESULT_OK && resultData != null) {
|
||||
val extras = resultData.extras
|
||||
if (extras?.containsKey(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) == true) {
|
||||
val uri = extras.getParcelable<Uri>(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) ?: return
|
||||
try {
|
||||
systemRingtoneSelected(uri)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun customRingtoneSelected(ringtonePath: String)
|
||||
|
||||
abstract fun systemRingtoneSelected(uri: Uri)
|
||||
|
||||
fun showPhotoPlaceholder(photoView: ImageView) {
|
||||
val placeholder = BitmapDrawable(resources, getBigLetterPlaceholder(contact?.getNameToDisplay() ?: "A"))
|
||||
photoView.setImageDrawable(placeholder)
|
||||
|
@ -211,4 +227,16 @@ abstract class ContactActivity : SimpleActivity() {
|
|||
view.draw(canvas)
|
||||
return bitmap
|
||||
}
|
||||
|
||||
protected fun getDefaultRingtoneUri() = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE)
|
||||
|
||||
protected fun getRingtonePickerIntent(): Intent {
|
||||
return Intent(RingtoneManager.ACTION_RINGTONE_PICKER).apply {
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true)
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true)
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE)
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, getDefaultRingtoneUri())
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(contact!!.ringtone))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -488,13 +488,18 @@ class EditContactActivity : ContactActivity() {
|
|||
|
||||
private fun setupRingtone() {
|
||||
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
|
||||
}, onAlarmSoundDeleted = {}
|
||||
)
|
||||
val ringtonePickerIntent = getRingtonePickerIntent()
|
||||
if (ringtonePickerIntent.resolveActivity(packageManager) != null) {
|
||||
startActivityForResult(ringtonePickerIntent, INTENT_SELECT_RINGTONE)
|
||||
} else {
|
||||
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
|
||||
}, onAlarmSoundDeleted = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val ringtone = contact!!.ringtone
|
||||
|
@ -502,8 +507,7 @@ class EditContactActivity : ContactActivity() {
|
|||
if (ringtone == SILENT) {
|
||||
contact_ringtone.text = getString(R.string.no_sound)
|
||||
} else {
|
||||
val contactRingtone = RingtoneManager.getRingtone(this, Uri.parse(ringtone))
|
||||
contact_ringtone.text = contactRingtone.getTitle(this)
|
||||
systemRingtoneSelected(Uri.parse(ringtone))
|
||||
}
|
||||
} else {
|
||||
val default = getDefaultAlarmSound(RingtoneManager.TYPE_RINGTONE)
|
||||
|
@ -1247,6 +1251,12 @@ class EditContactActivity : ContactActivity() {
|
|||
contact_ringtone.text = ringtonePath.getFilenameFromPath()
|
||||
}
|
||||
|
||||
override fun systemRingtoneSelected(uri: Uri) {
|
||||
contact!!.ringtone = uri.toString()
|
||||
val contactRingtone = RingtoneManager.getRingtone(this, uri)
|
||||
contact_ringtone.text = contactRingtone.getTitle(this)
|
||||
}
|
||||
|
||||
private fun getPhoneNumberTypeId(value: String) = when (value) {
|
||||
getString(R.string.mobile) -> Phone.TYPE_MOBILE
|
||||
getString(R.string.home) -> Phone.TYPE_HOME
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.simplemobiletools.contacts.pro.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ContentUris
|
||||
import android.content.Intent
|
||||
import android.media.AudioManager
|
||||
|
@ -40,7 +39,6 @@ class ViewContactActivity : ContactActivity() {
|
|||
private var fullContact: Contact? = null // contact with all fields filled from duplicates
|
||||
|
||||
private val COMPARABLE_PHONE_NUMBER_LENGTH = 9
|
||||
private val INTENT_SELECT_RINGTONE = 600
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
showTransparentTop = true
|
||||
|
@ -77,22 +75,6 @@ class ViewContactActivity : ContactActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, resultData)
|
||||
if (requestCode == INTENT_SELECT_RINGTONE && resultCode == Activity.RESULT_OK && resultData != null) {
|
||||
val extras = resultData.extras
|
||||
if (extras?.containsKey(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) == true) {
|
||||
val uri = extras.getParcelable<Uri>(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) ?: return
|
||||
try {
|
||||
updateRingtoneText(uri)
|
||||
ringtoneUpdated(uri.toString())
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupMenu() {
|
||||
(contact_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
|
||||
contact_toolbar.menu.apply {
|
||||
|
@ -601,7 +583,7 @@ class ViewContactActivity : ContactActivity() {
|
|||
if (ringtone == SILENT) {
|
||||
contact_ringtone.text = getString(R.string.no_sound)
|
||||
} else {
|
||||
updateRingtoneText(Uri.parse(ringtone))
|
||||
systemRingtoneSelected(Uri.parse(ringtone))
|
||||
}
|
||||
} else {
|
||||
contact_ringtone_image.beGone()
|
||||
|
@ -612,24 +594,17 @@ class ViewContactActivity : ContactActivity() {
|
|||
contact_ringtone.copyOnLongClick(contact_ringtone.text.toString())
|
||||
|
||||
contact_ringtone.setOnClickListener {
|
||||
Intent(RingtoneManager.ACTION_RINGTONE_PICKER).apply {
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true)
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true)
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE)
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, getDefaultRingtoneUri())
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(contact!!.ringtone))
|
||||
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
startActivityForResult(this, INTENT_SELECT_RINGTONE)
|
||||
} else {
|
||||
val currentRingtone = contact!!.ringtone ?: getDefaultAlarmSound(RingtoneManager.TYPE_RINGTONE).uri
|
||||
SelectAlarmSoundDialog(this@ViewContactActivity, currentRingtone, AudioManager.STREAM_RING, PICK_RINGTONE_INTENT_ID, RingtoneManager.TYPE_RINGTONE, true,
|
||||
onAlarmPicked = {
|
||||
contact_ringtone.text = it?.title
|
||||
ringtoneUpdated(it?.uri)
|
||||
}, onAlarmSoundDeleted = {}
|
||||
)
|
||||
}
|
||||
val ringtonePickerIntent = getRingtonePickerIntent()
|
||||
if (ringtonePickerIntent.resolveActivity(packageManager) != null) {
|
||||
startActivityForResult(ringtonePickerIntent, INTENT_SELECT_RINGTONE)
|
||||
} else {
|
||||
val currentRingtone = contact!!.ringtone ?: getDefaultAlarmSound(RingtoneManager.TYPE_RINGTONE).uri
|
||||
SelectAlarmSoundDialog(this@ViewContactActivity, currentRingtone, AudioManager.STREAM_RING, PICK_RINGTONE_INTENT_ID, RingtoneManager.TYPE_RINGTONE, true,
|
||||
onAlarmPicked = {
|
||||
contact_ringtone.text = it?.title
|
||||
ringtoneUpdated(it?.uri)
|
||||
}, onAlarmSoundDeleted = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -638,14 +613,6 @@ class ViewContactActivity : ContactActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getDefaultRingtoneUri() = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE)
|
||||
|
||||
private fun updateRingtoneText(uri: Uri) {
|
||||
val contactRingtone = RingtoneManager.getRingtone(this, uri)
|
||||
val ringtoneTitle = contactRingtone.getTitle(this)
|
||||
contact_ringtone.text = ringtoneTitle
|
||||
}
|
||||
|
||||
private fun setupOrganization() {
|
||||
val organization = contact!!.organization
|
||||
if (organization.isNotEmpty() && showFields and SHOW_ORGANIZATION_FIELD != 0) {
|
||||
|
@ -688,6 +655,12 @@ class ViewContactActivity : ContactActivity() {
|
|||
ringtoneUpdated(ringtonePath)
|
||||
}
|
||||
|
||||
override fun systemRingtoneSelected(uri: Uri) {
|
||||
val contactRingtone = RingtoneManager.getRingtone(this, uri)
|
||||
contact_ringtone.text = contactRingtone.getTitle(this)
|
||||
ringtoneUpdated(uri.toString())
|
||||
}
|
||||
|
||||
private fun ringtoneUpdated(path: String?) {
|
||||
contact!!.ringtone = path
|
||||
|
||||
|
|
Loading…
Reference in New Issue