From 9345b840111b7dfd4f2ba65ce6e6a5c113c3ee30 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Fri, 18 Oct 2013 19:40:51 +0200 Subject: [PATCH] Separated the RSS and torrents-related background notification settings. --- core/res/values/strings.xml | 5 ++-- core/res/xml/pref_notifications.xml | 21 +++++++++-------- .../app/settings/NotificationSettings.java | 12 ++++++++-- .../NotificationSettingsActivity.java | 23 +++++++++++++++---- .../transdroid/core/service/BootReceiver.java | 5 +++- .../core/service/RssCheckerService.java | 2 +- .../core/service/ServerCheckerService.java | 2 +- 7 files changed, 49 insertions(+), 21 deletions(-) diff --git a/core/res/values/strings.xml b/core/res/values/strings.xml index 6d9e7a67..85e77730 100644 --- a/core/res/values/strings.xml +++ b/core/res/values/strings.xml @@ -253,10 +253,11 @@ Allow all connections from any thumbprint Background notifications - Enable notifications + Enable RSS notifications + Enable torrent notifications Enables the background service Interval - How often to check the server + How often to check RSS or torrents Sound Vibrate LED colour diff --git a/core/res/xml/pref_notifications.xml b/core/res/xml/pref_notifications.xml index d98e29fb..42be74a3 100644 --- a/core/res/xml/pref_notifications.xml +++ b/core/res/xml/pref_notifications.xml @@ -17,9 +17,15 @@ --> + + @@ -29,36 +35,31 @@ android:summary="@string/pref_notifyinterval_info" android:entries="@array/pref_notifyinterval_types" android:entryValues="@array/pref_notifyinterval_values" - android:defaultValue="10800" - android:dependency="notifications_enabled" /> + android:defaultValue="10800" /> + android:showSilent="true" /> + android:defaultValue="false" /> + android:defaultValue="false" /> diff --git a/core/src/org/transdroid/core/app/settings/NotificationSettings.java b/core/src/org/transdroid/core/app/settings/NotificationSettings.java index 1559b835..2f2cfbbe 100644 --- a/core/src/org/transdroid/core/app/settings/NotificationSettings.java +++ b/core/src/org/transdroid/core/app/settings/NotificationSettings.java @@ -43,10 +43,18 @@ public class NotificationSettings { } /** - * Whether the background service is enabled, i.e. whether the user want to receive notifications + * Whether the background service is enabled and the user wants to receive RSS-related notifications + * @return True if the server should be checked for RSS feed updates + */ + public boolean isEnabledForRss() { + return prefs.getBoolean("notifications_enabledrss", true); + } + + /** + * Whether the background service is enabled and the user wants to receive torrent-related notifications * @return True if the server should be checked for torrent status updates */ - public boolean isEnabled() { + public boolean isEnabledForTorrents() { return prefs.getBoolean("notifications_enabled", true); } diff --git a/core/src/org/transdroid/core/gui/settings/NotificationSettingsActivity.java b/core/src/org/transdroid/core/gui/settings/NotificationSettingsActivity.java index 517dbe12..f7bc0d18 100644 --- a/core/src/org/transdroid/core/gui/settings/NotificationSettingsActivity.java +++ b/core/src/org/transdroid/core/gui/settings/NotificationSettingsActivity.java @@ -46,9 +46,11 @@ public class NotificationSettingsActivity extends SherlockPreferenceActivity imp getSupportActionBar().setDisplayHomeAsUpEnabled(true); - // Just load the notification-related preferences from XML + // Load the notification-related preferences from XML and update availability thereof addPreferencesFromResource(R.xml.pref_notifications); - + boolean disabled = !notificationSettings.isEnabledForRss() && !notificationSettings.isEnabledForTorrents(); + updatePrefsEnabled(disabled); + } @SuppressWarnings("deprecation") @@ -75,13 +77,26 @@ public class NotificationSettingsActivity extends SherlockPreferenceActivity imp @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (!notificationSettings.isEnabled()) { - // Disabled background notifications; disable the alarms that start the service + boolean disabled = !notificationSettings.isEnabledForRss() && !notificationSettings.isEnabledForTorrents(); + updatePrefsEnabled(disabled); + + if (disabled ) { + // Disabled all background notifications; disable the alarms that start the service BootReceiver.cancelBackgroundServices(getApplicationContext()); } // (Re-)enable the alarms for the background services + // Note that this still respects the user preference BootReceiver.startBackgroundServices(getApplicationContext(), true); } + @SuppressWarnings("deprecation") + private void updatePrefsEnabled(boolean disabled) { + findPreference("notifications_interval").setEnabled(!disabled); + findPreference("notifications_sound").setEnabled(!disabled); + findPreference("notifications_vibrate").setEnabled(!disabled); + findPreference("notifications_ledcolour").setEnabled(!disabled); + findPreference("notifications_adwnotify").setEnabled(!disabled); + } + } diff --git a/core/src/org/transdroid/core/service/BootReceiver.java b/core/src/org/transdroid/core/service/BootReceiver.java index 1cfa6b1e..770b4da7 100644 --- a/core/src/org/transdroid/core/service/BootReceiver.java +++ b/core/src/org/transdroid/core/service/BootReceiver.java @@ -50,7 +50,10 @@ public class BootReceiver extends BroadcastReceiver { public static void startBackgroundServices(Context context, boolean forceReload) { NotificationSettings notificationSettings = NotificationSettings_.getInstance_(context); AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - if (notificationSettings.isEnabled() && (forceReload || (piServerChecker == null && piRssChecker == null))) { + // Start the alarms if one of the notifications are enabled and we do not yet have the alarms running + // (or should reload it forcefully) + if ((notificationSettings.isEnabledForRss() || notificationSettings.isEnabledForTorrents()) && + (forceReload || (piServerChecker == null && piRssChecker == null))) { Log.d(context, "Boot signal received, starting server and rss checker background services"); // Schedule repeating alarms, with the first being (somewhat) in 1 second from now diff --git a/core/src/org/transdroid/core/service/RssCheckerService.java b/core/src/org/transdroid/core/service/RssCheckerService.java index f3098246..9c5d014a 100644 --- a/core/src/org/transdroid/core/service/RssCheckerService.java +++ b/core/src/org/transdroid/core/service/RssCheckerService.java @@ -62,7 +62,7 @@ public class RssCheckerService extends IntentService { @Override protected void onHandleIntent(Intent intent) { - if (!connectivityHelper.shouldPerformBackgroundActions() || !notificationSettings.isEnabled()) { + if (!connectivityHelper.shouldPerformBackgroundActions() || !notificationSettings.isEnabledForRss()) { Log.d(this, "Skip the RSS checker service, as background data is disabled, the service is disabled or we are not connected."); return; diff --git a/core/src/org/transdroid/core/service/ServerCheckerService.java b/core/src/org/transdroid/core/service/ServerCheckerService.java index 9de64625..e849bf42 100644 --- a/core/src/org/transdroid/core/service/ServerCheckerService.java +++ b/core/src/org/transdroid/core/service/ServerCheckerService.java @@ -69,7 +69,7 @@ public class ServerCheckerService extends IntentService { @Override protected void onHandleIntent(Intent intent) { - if (!connectivityHelper.shouldPerformBackgroundActions() || !notificationSettings.isEnabled()) { + if (!connectivityHelper.shouldPerformBackgroundActions() || !notificationSettings.isEnabledForTorrents()) { Log.d(this, "Skip the server checker service, as background data is disabled, the service is disabled or we are not connected."); return;