diff --git a/src/main/java/eu/siacs/conversations/AppSettings.java b/src/main/java/eu/siacs/conversations/AppSettings.java index be82ee5dd..80b5ceaa0 100644 --- a/src/main/java/eu/siacs/conversations/AppSettings.java +++ b/src/main/java/eu/siacs/conversations/AppSettings.java @@ -61,6 +61,21 @@ public class AppSettings { sharedPreferences.edit().putString(RINGTONE, uri == null ? null : uri.toString()).apply(); } + public Uri getNotificationTone() { + final SharedPreferences sharedPreferences = + PreferenceManager.getDefaultSharedPreferences(context); + final String incomingCallRingtone = + sharedPreferences.getString( + NOTIFICATION_RINGTONE, context.getString(R.string.notification_ringtone)); + return Strings.isNullOrEmpty(incomingCallRingtone) ? null : Uri.parse(incomingCallRingtone); + } + + public void setNotificationTone(final Uri uri) { + final SharedPreferences sharedPreferences = + PreferenceManager.getDefaultSharedPreferences(context); + sharedPreferences.edit().putString(NOTIFICATION_RINGTONE, uri == null ? null : uri.toString()).apply(); + } + public boolean isBTBVEnabled() { return getBooleanPreference(BTBV, R.bool.btbv); } 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 81df3da18..6bb25c2ad 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 @@ -1,6 +1,5 @@ package eu.siacs.conversations.ui.fragment.settings; -import android.content.SharedPreferences; import android.media.RingtoneManager; import android.net.Uri; import android.os.Bundle; @@ -9,9 +8,7 @@ import android.util.Log; import androidx.activity.result.ActivityResultLauncher; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.preference.ListPreference; import androidx.preference.Preference; -import androidx.preference.PreferenceFragmentCompat; import eu.siacs.conversations.AppSettings; import eu.siacs.conversations.Config; @@ -21,6 +18,18 @@ import eu.siacs.conversations.utils.Compatibility; public class NotificationsSettingsFragment extends XmppPreferenceFragment { + private final ActivityResultLauncher pickNotificationToneLauncher = + registerForActivityResult( + new PickRingtone(RingtoneManager.TYPE_NOTIFICATION), + result -> { + if (result == null) { + // do nothing. user aborted + return; + } + final Uri uri = PickRingtone.noneToNull(result); + appSettings().setNotificationTone(uri); + Log.i(Config.LOGTAG, "User set notification tone to " + uri); + }); private final ActivityResultLauncher pickRingtoneLauncher = registerForActivityResult( new PickRingtone(RingtoneManager.TYPE_RINGTONE), @@ -30,7 +39,7 @@ public class NotificationsSettingsFragment extends XmppPreferenceFragment { return; } final Uri uri = PickRingtone.noneToNull(result); - setRingtone(uri); + appSettings().setRingtone(uri); Log.i(Config.LOGTAG, "User set ringtone to " + uri); }); @@ -79,22 +88,30 @@ public class NotificationsSettingsFragment extends XmppPreferenceFragment { @Override public boolean onPreferenceTreeClick(final Preference preference) { - if (AppSettings.RINGTONE.equals(preference.getKey())) { + final var key = preference.getKey(); + if (AppSettings.RINGTONE.equals(key)) { pickRingtone(); return true; } + if (AppSettings.NOTIFICATION_RINGTONE.equals(key)) { + pickNotificationTone(); + return true; + } return super.onPreferenceTreeClick(preference); } + private void pickNotificationTone() { + final Uri uri = appSettings().getNotificationTone(); + Log.i(Config.LOGTAG, "current notification tone: " + uri); + this.pickNotificationToneLauncher.launch(uri); + } + private void pickRingtone() { final Uri uri = appSettings().getRingtone(); Log.i(Config.LOGTAG, "current ringtone: " + uri); this.pickRingtoneLauncher.launch(uri); } - private void setRingtone(final Uri uri) { - appSettings().setRingtone(uri); - } private AppSettings appSettings() { return new AppSettings(requireContext()); diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 290b54404..48be180d0 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1025,9 +1025,6 @@ Delete & Archive chat Start chat No client certificate selected! - - - Interface Theme, Colors, Screenshots, Input Security