From e690e9bd698fd9725b557fbfaf8e9c9a78a4ae69 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Mon, 29 Nov 2021 15:21:01 -0400 Subject: [PATCH] Display an error if we cannot open picker instead of crashing. --- .../NotificationsSettingsFragment.kt | 17 +++++++++++++---- app/src/main/res/values/strings.xml | 3 +++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/NotificationsSettingsFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/NotificationsSettingsFragment.kt index 39595bd12..d755fbc31 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/NotificationsSettingsFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/notifications/NotificationsSettingsFragment.kt @@ -1,6 +1,7 @@ package org.thoughtcrime.securesms.components.settings.app.notifications import android.app.Activity +import android.content.ActivityNotFoundException import android.content.Intent import android.graphics.ColorFilter import android.graphics.PorterDuff @@ -10,6 +11,7 @@ import android.net.Uri import android.provider.Settings import android.text.TextUtils import android.view.View +import android.widget.Toast import androidx.annotation.RequiresApi import androidx.core.content.ContextCompat import androidx.lifecycle.ViewModelProvider @@ -241,7 +243,6 @@ class NotificationsSettingsFragment : DSLSettingsFragment(R.string.preferences__ } } - @Suppress("DEPRECATION") private fun launchMessageSoundSelectionIntent() { val current = SignalStore.settings().messageNotificationSound @@ -255,7 +256,7 @@ class NotificationsSettingsFragment : DSLSettingsFragment(R.string.preferences__ ) intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, current) - startActivityForResult(intent, MESSAGE_SOUND_SELECT) + openRingtonePicker(intent, MESSAGE_SOUND_SELECT) } @RequiresApi(26) @@ -269,7 +270,6 @@ class NotificationsSettingsFragment : DSLSettingsFragment(R.string.preferences__ startActivity(intent) } - @Suppress("DEPRECATION") private fun launchCallRingtoneSelectionIntent() { val current = SignalStore.settings().callRingtone @@ -283,7 +283,16 @@ class NotificationsSettingsFragment : DSLSettingsFragment(R.string.preferences__ ) intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, current) - startActivityForResult(intent, CALL_RINGTONE_SELECT) + openRingtonePicker(intent, CALL_RINGTONE_SELECT) + } + + @Suppress("DEPRECATION") + private fun openRingtonePicker(intent: Intent, requestCode: Int) { + try { + startActivityForResult(intent, requestCode) + } catch (e: ActivityNotFoundException) { + Toast.makeText(requireContext(), R.string.NotificationSettingsFragment__failed_to_open_picker, Toast.LENGTH_LONG).show() + } } private class LedColorPreference( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4fc0fa409..4b1612806 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4025,6 +4025,9 @@ Thank you for your donation. Your contribution helps fuel the mission of developing open source privacy technology that protects free expression and enables secure global communication for millions around the world. Signal Technology Foundation is a tax-exempt nonprofit organization in the United States under section 501c3 of the Internal Revenue Code. Our Federal Tax ID is 82-4506840. No goods or services were provided in exchange for this donation. Please retain this receipt for your tax records. + + Failed to open picker. +