From 251602fb2cd399c087a2fcdc76a41c9d79aebf40 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Tue, 28 Mar 2017 15:39:29 -0400 Subject: [PATCH] Adds preferences for receiving notifications by type. --- .../tusky/MyFirebaseMessagingService.java | 31 ++++++- app/src/main/res/values/strings.xml | 14 ++-- app/src/main/res/xml/preferences.xml | 83 +++++++++++++------ 3 files changed, 92 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java b/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java index b54fc056..0031080c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java +++ b/app/src/main/java/com/keylesspalace/tusky/MyFirebaseMessagingService.java @@ -121,10 +121,33 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService { } } + private static boolean filterNotification(SharedPreferences preferences, + Notification notification) { + switch (notification.type) { + default: + case MENTION: { + return preferences.getBoolean("notificationFilterMentions", true); + } + case FOLLOW: { + return preferences.getBoolean("notificationFilterFollows", true); + } + case REBLOG: { + return preferences.getBoolean("notificationFilterReblogs", true); + } + case FAVOURITE: { + return preferences.getBoolean("notificationFilterFavourites", true); + } + } + } + private void buildNotification(Notification body) { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences notificationPreferences = getApplicationContext().getSharedPreferences("Notifications", MODE_PRIVATE); + if (!filterNotification(preferences, body)) { + return; + } + String rawCurrentNotifications = notificationPreferences.getString("current", "[]"); JSONArray currentNotifications; @@ -146,7 +169,9 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService { } } - if (!alreadyContains) currentNotifications.put(body.account.displayName); + if (!alreadyContains) { + currentNotifications.put(body.account.displayName); + } SharedPreferences.Editor editor = notificationPreferences.edit(); editor.putString("current", currentNotifications.toString()); @@ -222,11 +247,11 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService { builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); } - if (preferences.getBoolean("notificationStyleVibrate", false)) { + if (preferences.getBoolean("notificationAlertVibrate", false)) { builder.setVibrate(new long[] { 500, 500 }); } - if (preferences.getBoolean("notificationStyleLight", false)) { + if (preferences.getBoolean("notificationAlertLight", false)) { builder.setLights(0xFF00FF8F, 300, 1000); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 54d69113..b66585dc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -101,13 +101,15 @@ Only followers and mentions can see Notifications - Enable pull notifications - Check for notifications periodically - Check interval - How often to pull + Alerts Notify with a sound - Notify with vibration - Notify with light + Notify with vibration + Notify with light + Notify me when + mentioned + followed + my posts are boosted + my posts are favourited Appearance Use the Light Theme Submit diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index b1bd2917..f1771636 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -2,33 +2,6 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + +