Fixed problems with ringtone selection (#756)

This commit is contained in:
Agnieszka C 2021-12-27 12:06:42 +01:00
parent 5bad2055cb
commit 5a124d31eb
4 changed files with 9 additions and 6 deletions

View file

@ -24,6 +24,7 @@ import com.bumptech.glide.request.target.Target
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.SILENT
import com.simplemobiletools.commons.helpers.letterBackgroundColors
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.contacts.pro.R
@ -241,12 +242,14 @@ abstract class ContactActivity : SimpleActivity() {
return bitmap
}
protected fun getDefaultRingtoneUri() = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE)
protected fun getDefaultRingtoneUri() = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)
protected fun getRingtonePickerIntent(): Intent {
val defaultRingtoneUri = getDefaultRingtoneUri()
val currentRingtoneUri = if (contact!!.ringtone != null) {
val currentRingtoneUri = if (contact!!.ringtone != null && contact!!.ringtone!!.isNotEmpty()) {
Uri.parse(contact!!.ringtone)
} else if (contact!!.ringtone?.isNotEmpty() == false) {
null
} else {
defaultRingtoneUri
}

View file

@ -1321,7 +1321,7 @@ class EditContactActivity : ContactActivity() {
}
override fun systemRingtoneSelected(uri: Uri?) {
contact!!.ringtone = uri?.toString()
contact!!.ringtone = uri?.toString() ?: ""
val contactRingtone = RingtoneManager.getRingtone(this, uri)
contact_ringtone.text = contactRingtone.getTitle(this)
}

View file

@ -615,7 +615,7 @@ class ViewContactActivity : ContactActivity() {
val ringtone = contact!!.ringtone
if (ringtone?.isEmpty() == true) {
contact_ringtone.text = getString(R.string.no_sound)
} else if (ringtone?.isNotEmpty() == true) {
} else if (ringtone?.isNotEmpty() == true && ringtone != getDefaultRingtoneUri().toString()) {
if (ringtone == SILENT) {
contact_ringtone.text = getString(R.string.no_sound)
} else {
@ -708,7 +708,7 @@ class ViewContactActivity : ContactActivity() {
override fun systemRingtoneSelected(uri: Uri?) {
val contactRingtone = RingtoneManager.getRingtone(this, uri)
contact_ringtone.text = contactRingtone.getTitle(this)
ringtoneUpdated(uri.toString())
ringtoneUpdated(uri?.toString() ?: "")
}
private fun ringtoneUpdated(path: String?) {

View file

@ -1097,7 +1097,7 @@ class ContactsHelper(val context: Context) {
val uri = Uri.withAppendedPath(Contacts.CONTENT_URI, contact.contactId.toString())
val contentValues = ContentValues(2)
contentValues.put(Contacts.STARRED, contact.starred)
contentValues.put(Contacts.CUSTOM_RINGTONE, contact.ringtone ?: "")
contentValues.put(Contacts.CUSTOM_RINGTONE, contact.ringtone)
context.contentResolver.update(uri, contentValues, null, null)
} catch (e: Exception) {
context.showErrorToast(e)