Browse Source

Separated the RSS and torrents-related background notification settings.

pull/82/head
Eric Kok 11 years ago
parent
commit
9345b84011
  1. 5
      core/res/values/strings.xml
  2. 21
      core/res/xml/pref_notifications.xml
  3. 12
      core/src/org/transdroid/core/app/settings/NotificationSettings.java
  4. 23
      core/src/org/transdroid/core/gui/settings/NotificationSettingsActivity.java
  5. 5
      core/src/org/transdroid/core/service/BootReceiver.java
  6. 2
      core/src/org/transdroid/core/service/RssCheckerService.java
  7. 2
      core/src/org/transdroid/core/service/ServerCheckerService.java

5
core/res/values/strings.xml

@ -253,10 +253,11 @@ @@ -253,10 +253,11 @@
<string name="pref_sslacceptall_info">Allow all connections from any thumbprint</string>
<string name="pref_background">Background notifications</string>
<string name="pref_notifications">Enable notifications</string>
<string name="pref_notifications_rss">Enable RSS notifications</string>
<string name="pref_notifications_torrent">Enable torrent notifications</string>
<string name="pref_notifications_info">Enables the background service</string>
<string name="pref_notifyinterval">Interval</string>
<string name="pref_notifyinterval_info">How often to check the server</string>
<string name="pref_notifyinterval_info">How often to check RSS or torrents</string>
<string name="pref_notifysound">Sound</string>
<string name="pref_notifyvibrate">Vibrate</string>
<string name="pref_notifyled">LED colour</string>

21
core/res/xml/pref_notifications.xml

@ -17,9 +17,15 @@ @@ -17,9 +17,15 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:key="notifications_enabledrss"
android:title="@string/pref_notifications_rss"
android:summary="@string/pref_notifications_info"
android:defaultValue="true" />
<CheckBoxPreference
android:key="notifications_enabled"
android:title="@string/pref_notifications"
android:title="@string/pref_notifications_torrent"
android:summary="@string/pref_notifications_info"
android:defaultValue="true" />
@ -29,36 +35,31 @@ @@ -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" />
<RingtonePreference
android:key="notifications_sound"
android:title="@string/pref_notifysound"
android:ringtoneType="notification"
android:showDefault="true"
android:showSilent="true"
android:dependency="notifications_enabled" />
android:showSilent="true" />
<CheckBoxPreference
android:key="notifications_vibrate"
android:title="@string/pref_notifyvibrate"
android:defaultValue="false"
android:dependency="notifications_enabled" />
android:defaultValue="false" />
<net.margaritov.preference.colorpicker.ColorPickerPreference
android:key="notifications_ledcolour"
android:title="@string/pref_notifyled"
android:summary="@string/pref_notifyled_info"
android:defaultValue="@color/ledgreen"
android:dependency="notifications_enabled"
alphaSlider="false" />
<CheckBoxPreference
android:key="notifications_adwnotify"
android:title="@string/pref_adw"
android:summary="@string/pref_adw_info"
android:defaultValue="false"
android:dependency="notifications_enabled" />
android:defaultValue="false" />
</PreferenceScreen>

12
core/src/org/transdroid/core/app/settings/NotificationSettings.java

@ -43,10 +43,18 @@ public class NotificationSettings { @@ -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);
}

23
core/src/org/transdroid/core/gui/settings/NotificationSettingsActivity.java

@ -46,9 +46,11 @@ public class NotificationSettingsActivity extends SherlockPreferenceActivity imp @@ -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 @@ -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);
}
}

5
core/src/org/transdroid/core/service/BootReceiver.java

@ -50,7 +50,10 @@ public class BootReceiver extends BroadcastReceiver { @@ -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

2
core/src/org/transdroid/core/service/RssCheckerService.java

@ -62,7 +62,7 @@ public class RssCheckerService extends IntentService { @@ -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;

2
core/src/org/transdroid/core/service/ServerCheckerService.java

@ -69,7 +69,7 @@ public class ServerCheckerService extends IntentService { @@ -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;

Loading…
Cancel
Save