Adds preferences for receiving notifications by type.

This commit is contained in:
Vavassor 2017-03-28 15:39:29 -04:00
parent 49ef88751e
commit 251602fb2c
3 changed files with 92 additions and 36 deletions

View File

@ -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);
}
}

View File

@ -101,13 +101,15 @@
<string name="visibility_private">Only followers and mentions can see</string>
<string name="pref_title_notification_settings">Notifications</string>
<string name="pref_title_pull_notifications">Enable pull notifications</string>
<string name="pref_summary_pull_notifications">Check for notifications periodically</string>
<string name="pref_title_pull_notification_check_interval">Check interval</string>
<string name="pref_summary_pull_notification_check_interval">How often to pull</string>
<string name="pref_title_notification_alerts">Alerts</string>
<string name="pref_title_notification_alert_sound">Notify with a sound</string>
<string name="pref_title_notification_style_vibrate">Notify with vibration</string>
<string name="pref_title_notification_style_light">Notify with light</string>
<string name="pref_title_notification_alert_vibrate">Notify with vibration</string>
<string name="pref_title_notification_alert_light">Notify with light</string>
<string name="pref_title_notification_filters">Notify me when</string>
<string name="pref_title_notification_filter_mentions">mentioned</string>
<string name="pref_title_notification_filter_follows">followed</string>
<string name="pref_title_notification_filter_reblogs">my posts are boosted</string>
<string name="pref_title_notification_filter_favourites">my posts are favourited</string>
<string name="pref_title_appearance_settings">Appearance</string>
<string name="pref_title_light_theme">Use the Light Theme</string>
<string name="action_submit">Submit</string>

View File

@ -2,33 +2,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="@string/preferences_file_key">
<PreferenceCategory android:title="@string/pref_title_notification_settings">
<CheckBoxPreference
android:key="notificationsEnabled"
android:title="@string/pref_title_notifications_enabled"
android:defaultValue="true" />
<CheckBoxPreference
android:dependency="notificationsEnabled"
android:key="notificationAlertSound"
android:title="@string/pref_title_notification_alert_sound"
android:defaultValue="true" />
<CheckBoxPreference
android:dependency="notificationsEnabled"
android:key="notificationStyleVibrate"
android:title="@string/pref_title_notification_style_vibrate"
android:defaultValue="true" />
<CheckBoxPreference
android:dependency="notificationsEnabled"
android:key="notificationStyleLight"
android:title="@string/pref_title_notification_style_light"
android:defaultValue="true" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_title_appearance_settings">
<CheckBoxPreference
@ -38,4 +11,60 @@
</PreferenceCategory>
<PreferenceScreen android:title="@string/pref_title_notification_settings">
<CheckBoxPreference
android:key="notificationsEnabled"
android:title="@string/pref_title_notifications_enabled"
android:defaultValue="true" />
<PreferenceCategory
android:dependency="notificationsEnabled"
android:title="@string/pref_title_notification_filters">
<CheckBoxPreference
android:key="notificationFilterMentions"
android:title="@string/pref_title_notification_filter_mentions"
android:defaultValue="true" />
<CheckBoxPreference
android:key="notificationFilterFollows"
android:title="@string/pref_title_notification_filter_follows"
android:defaultValue="true" />
<CheckBoxPreference
android:key="notificationFilterReblogs"
android:title="@string/pref_title_notification_filter_reblogs"
android:defaultValue="true" />
<CheckBoxPreference
android:key="notificationFilterFavourites"
android:title="@string/pref_title_notification_filter_favourites"
android:defaultValue="true" />
</PreferenceCategory>
<PreferenceCategory
android:dependency="notificationsEnabled"
android:title="@string/pref_title_notification_alerts">
<CheckBoxPreference
android:key="notificationAlertSound"
android:title="@string/pref_title_notification_alert_sound"
android:defaultValue="true" />
<CheckBoxPreference
android:key="notificationAlertVibrate"
android:title="@string/pref_title_notification_alert_vibrate"
android:defaultValue="true" />
<CheckBoxPreference
android:key="notificationAlertLight"
android:title="@string/pref_title_notification_alert_light"
android:defaultValue="true" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>