Merge pull request #761 from Aga-C/fix-select-ringtone-issues

Fixed problems with ringtone selection (#756)
This commit is contained in:
Tibor Kaputa 2022-01-03 18:23:16 +01:00 committed by GitHub
commit 5d20e6b664
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 6 deletions

View file

@ -241,12 +241,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)