diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-03-14 11:04:48 +0100 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-03-14 11:04:48 +0100 |
commit | fbb47721328c809784a0d992cbc37e1a1bd1164c (patch) | |
tree | fcabf8149e93f10d598cf217662ec5b90ab47a9f /src/de | |
parent | 9bd7c3108023c4a822c1e02bf3de9bc560c4abab (diff) | |
parent | edaca292dc88ff18f109a1b8f94d718c582a4489 (diff) | |
download | AntennaPod-fbb47721328c809784a0d992cbc37e1a1bd1164c.zip |
Merge branch 'toggles-update_alarm' into develop
Conflicts:
src/de/danoeh/antennapod/PodcastApp.java
Diffstat (limited to 'src/de')
-rw-r--r-- | src/de/danoeh/antennapod/PodcastApp.java | 1 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/preferences/UserPreferences.java | 46 |
2 files changed, 30 insertions, 17 deletions
diff --git a/src/de/danoeh/antennapod/PodcastApp.java b/src/de/danoeh/antennapod/PodcastApp.java index 9a3332788..e9f46256b 100644 --- a/src/de/danoeh/antennapod/PodcastApp.java +++ b/src/de/danoeh/antennapod/PodcastApp.java @@ -52,5 +52,4 @@ public class PodcastApp extends Application { || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE; } - } diff --git a/src/de/danoeh/antennapod/preferences/UserPreferences.java b/src/de/danoeh/antennapod/preferences/UserPreferences.java index 09fb49623..b938a86fe 100644 --- a/src/de/danoeh/antennapod/preferences/UserPreferences.java +++ b/src/de/danoeh/antennapod/preferences/UserPreferences.java @@ -198,22 +198,11 @@ public class UserPreferences implements followQueue = sp.getBoolean(PREF_FOLLOW_QUEUE, false); } else if (key.equals(PREF_UPDATE_INTERVAL)) { - AlarmManager alarmManager = (AlarmManager) context - .getSystemService(Context.ALARM_SERVICE); - updateInterval = readUpdateInterval(sp.getString( - PREF_UPDATE_INTERVAL, "0")); - PendingIntent updateIntent = PendingIntent.getBroadcast(context, 0, - new Intent(FeedUpdateReceiver.ACTION_REFRESH_FEEDS), 0); - alarmManager.cancel(updateIntent); - if (updateInterval != 0) { - alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, - updateInterval, updateInterval, updateIntent); - if (AppConfig.DEBUG) - Log.d(TAG, "Changed alarm to new intervall"); - } else { - if (AppConfig.DEBUG) - Log.d(TAG, "Automatic update was deactivated"); - } + int hours = Integer.parseInt(sp + .getString(PREF_UPDATE_INTERVAL, "0")); + updateInterval = readUpdateInterval(sp + .getString(PREF_UPDATE_INTERVAL, "0")); + restartUpdateAlarm(hours); } else if (key.equals(PREF_AUTO_DELETE)) { autoDelete = sp.getBoolean(PREF_AUTO_DELETE, false); @@ -355,4 +344,29 @@ public class UserPreferences implements } } + /** + * Updates alarm registered with the AlarmManager service or deactivates it. + * + * @param hours + * new value to register with AlarmManager. If hours is 0, the + * alarm is deactivated. + * */ + public void restartUpdateAlarm(int hours) { + AlarmManager alarmManager = (AlarmManager) context + .getSystemService(Context.ALARM_SERVICE); + PendingIntent updateIntent = PendingIntent.getBroadcast(context, 0, + new Intent(FeedUpdateReceiver.ACTION_REFRESH_FEEDS), 0); + alarmManager.cancel(updateIntent); + if (hours != 0) { + long newIntervall = TimeUnit.HOURS.toMillis(hours); + alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, newIntervall, + newIntervall, updateIntent); + if (AppConfig.DEBUG) + Log.d(TAG, "Changed alarm to new intervall"); + } else { + if (AppConfig.DEBUG) + Log.d(TAG, "Automatic update was deactivated"); + } + } + } |