Skip to content

Commit a390aaf

Browse files
authored
Merge pull request #4218 from wordpress-mobile/issue/1176-ringtone-preference-for-notification-sound
issue/1176 allow user to use custom notification sound.
2 parents 2486e41 + 28596ff commit a390aaf

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

WordPress/src/main/java/org/wordpress/android/GCMMessageService.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public class GCMMessageService extends GcmListenerService {
6969
private static final String PUSH_TYPE_PUSH_AUTH = "push_auth";
7070

7171
// Add to the analytics properties map a subset of the push notification payload.
72-
private static String[] propertiesToCopyIntoAnalytics = { PUSH_ARG_NOTE_ID, PUSH_ARG_TYPE, "blog_id", "post_id",
73-
"comment_id" };
72+
private static String[] propertiesToCopyIntoAnalytics = {PUSH_ARG_NOTE_ID, PUSH_ARG_TYPE, "blog_id", "post_id",
73+
"comment_id"};
7474

7575
private void synchronizedHandleDefaultPush(String from, @NonNull Bundle data) {
7676
// sActiveNotificationsMap being static, we can't just synchronize the method
@@ -295,9 +295,16 @@ private void showNotificationForBuilder(NotificationCompat.Builder builder, Cont
295295
boolean shouldPlaySound = prefs.getBoolean("wp_pref_notification_sound", false);
296296
boolean shouldVibrate = prefs.getBoolean("wp_pref_notification_vibrate", false);
297297
boolean shouldBlinkLight = prefs.getBoolean("wp_pref_notification_light", false);
298-
if (shouldPlaySound) {
299-
builder.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification));
298+
String notificationSound = prefs.getString("wp_pref_custom_notification_sound", null); //"" if None is selected
299+
300+
301+
// use default sound if the legacy sound preference was ON but the custom sound was not selected (null)
302+
if (shouldPlaySound && notificationSound == null) {
303+
builder.setSound(Uri.parse("content://settings/system/notification_sound"));
304+
} else if (!TextUtils.isEmpty(notificationSound)) {
305+
builder.setSound(Uri.parse(notificationSound));
300306
}
307+
301308
if (shouldVibrate) {
302309
builder.setVibrate(new long[]{500, 500, 500});
303310
}
@@ -475,7 +482,7 @@ public static synchronized void bumpPushNotificationsTappedAllAnalytics() {
475482
}
476483

477484
private static void bumpPushNotificationsAnalytics(Stat stat, Bundle noteBundle,
478-
Map<String, Object> properties) {
485+
Map<String, Object> properties) {
479486
// Bump Analytics for PNs if "Show notifications" setting is checked (default). Skip otherwise.
480487
if (!NotificationsUtils.isNotificationsEnabled(WordPress.getContext())) {
481488
return;
@@ -486,9 +493,9 @@ private static void bumpPushNotificationsAnalytics(Stat stat, Bundle noteBundle,
486493

487494
String notificationID = noteBundle.getString(PUSH_ARG_NOTE_ID, "");
488495
if (!TextUtils.isEmpty(notificationID)) {
489-
for (String currentPropertyToCopy: propertiesToCopyIntoAnalytics) {
496+
for (String currentPropertyToCopy : propertiesToCopyIntoAnalytics) {
490497
if (noteBundle.containsKey(currentPropertyToCopy)) {
491-
properties.put("push_notification_" + currentPropertyToCopy, noteBundle.get(currentPropertyToCopy));
498+
properties.put("push_notification_" + currentPropertyToCopy, noteBundle.get(currentPropertyToCopy));
492499
}
493500
}
494501
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(WordPress.getContext());
-48.4 KB
Binary file not shown.

WordPress/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<string name="hide">Hide</string>
4747
<string name="select_all">Select all</string>
4848
<string name="deselect_all">Deselect all</string>
49-
<string name="notification_sound">Play notification sound</string>
49+
<string name="notification_sound">Notification sound</string>
5050
<string name="notification_vibrate">Vibrate</string>
5151
<string name="notification_blink">Blink notification light</string>
5252
<string name="sure_to_remove_account">Remove this site?</string>

WordPress/src/main/res/xml/notifications_settings.xml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
33
android:key="wp_pref_notifications_root">
44
<PreferenceCategory
5-
android:title="@string/your_sites"
6-
android:key="@string/pref_notification_blogs">
5+
android:key="@string/pref_notification_blogs"
6+
android:title="@string/your_sites">
77
</PreferenceCategory>
88
<PreferenceCategory
9-
android:title="@string/notifications_other"
10-
android:key="@string/pref_notification_other_category">
11-
<PreferenceScreen android:key="@string/pref_notification_other_blogs"
12-
android:title="@string/notifications_comments_other_blogs" />
9+
android:key="@string/pref_notification_other_category"
10+
android:title="@string/notifications_other">
11+
<PreferenceScreen
12+
android:key="@string/pref_notification_other_blogs"
13+
android:title="@string/notifications_comments_other_blogs"/>
1314
</PreferenceCategory>
14-
<PreferenceCategory android:title="@string/notifications_sights_and_sounds"
15-
android:key="@string/pref_notification_sights_sounds">
16-
<SwitchPreference
17-
android:defaultValue="false"
18-
android:key="wp_pref_notification_sound"
15+
<PreferenceCategory
16+
android:key="@string/pref_notification_sights_sounds"
17+
android:title="@string/notifications_sights_and_sounds">
18+
<RingtonePreference
19+
android:key="wp_pref_custom_notification_sound"
20+
android:ringtoneType="notification"
21+
android:showDefault="true"
1922
android:title="@string/notification_sound"/>
2023
<SwitchPreference
2124
android:defaultValue="false"

0 commit comments

Comments
 (0)