diff --git a/src/main/java/eu/siacs/conversations/ui/activity/result/PickRingtone.java b/src/main/java/eu/siacs/conversations/ui/activity/result/PickRingtone.java index b58a7f398..975ba9431 100644 --- a/src/main/java/eu/siacs/conversations/ui/activity/result/PickRingtone.java +++ b/src/main/java/eu/siacs/conversations/ui/activity/result/PickRingtone.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.media.RingtoneManager; import android.net.Uri; + import androidx.activity.result.contract.ActivityResultContract; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -26,7 +27,7 @@ public class PickRingtone extends ActivityResultContract { intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, ringToneType); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); - if (existing != null) { + if (noneToNull(existing) != null) { intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, existing); } return intent; @@ -37,11 +38,14 @@ public class PickRingtone extends ActivityResultContract { if (resultCode != Activity.RESULT_OK || data == null) { return null; } - final Uri pickedUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); - return pickedUri == null ? NONE : pickedUri; + return nullToNone(data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)); } public static Uri noneToNull(final Uri uri) { return uri == null || NONE.equals(uri) ? null : uri; } + + public static @NonNull Uri nullToNone(final Uri uri) { + return uri == null ? NONE : uri; + } } diff --git a/src/main/java/eu/siacs/conversations/ui/fragment/settings/NotificationsSettingsFragment.java b/src/main/java/eu/siacs/conversations/ui/fragment/settings/NotificationsSettingsFragment.java index 6f9c62ecb..885f94f99 100644 --- a/src/main/java/eu/siacs/conversations/ui/fragment/settings/NotificationsSettingsFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/fragment/settings/NotificationsSettingsFragment.java @@ -119,7 +119,7 @@ public class NotificationsSettingsFragment extends XmppPreferenceFragment { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { channelRingtone = NotificationService.getCurrentIncomingCallChannel(requireContext()) - .transform(NotificationChannel::getSound); + .transform(channel -> PickRingtone.nullToNone(channel.getSound())); } else { channelRingtone = Optional.absent(); }