diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-03-14 11:47:40 +0100 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-03-14 11:47:40 +0100 |
commit | d0bfd7c02df10aa0015d78b1d3e0a1d8fc1b490a (patch) | |
tree | 31e0e54c860f32f9b194999354f27efeee6df2bf /src | |
parent | fbb47721328c809784a0d992cbc37e1a1bd1164c (diff) | |
download | AntennaPod-d0bfd7c02df10aa0015d78b1d3e0a1d8fc1b490a.zip |
Reset alarm on reboot and app upgrade
Diffstat (limited to 'src')
-rw-r--r-- | src/de/danoeh/antennapod/preferences/UserPreferences.java | 31 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/receiver/AlarmUpdateReceiver.java | 30 |
2 files changed, 46 insertions, 15 deletions
diff --git a/src/de/danoeh/antennapod/preferences/UserPreferences.java b/src/de/danoeh/antennapod/preferences/UserPreferences.java index b938a86fe..5b7c9d84f 100644 --- a/src/de/danoeh/antennapod/preferences/UserPreferences.java +++ b/src/de/danoeh/antennapod/preferences/UserPreferences.java @@ -198,11 +198,9 @@ public class UserPreferences implements followQueue = sp.getBoolean(PREF_FOLLOW_QUEUE, false); } else if (key.equals(PREF_UPDATE_INTERVAL)) { - int hours = Integer.parseInt(sp - .getString(PREF_UPDATE_INTERVAL, "0")); - updateInterval = readUpdateInterval(sp - .getString(PREF_UPDATE_INTERVAL, "0")); - restartUpdateAlarm(hours); + updateInterval = readUpdateInterval(sp.getString( + PREF_UPDATE_INTERVAL, "0")); + restartUpdateAlarm(updateInterval); } else if (key.equals(PREF_AUTO_DELETE)) { autoDelete = sp.getBoolean(PREF_AUTO_DELETE, false); @@ -347,20 +345,23 @@ 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 + * @param millis + * new value to register with AlarmManager. If millis is 0, the * alarm is deactivated. * */ - public void restartUpdateAlarm(int hours) { - AlarmManager alarmManager = (AlarmManager) context + public static void restartUpdateAlarm(long millis) { + instanceAvailable(); + if (AppConfig.DEBUG) + Log.d(TAG, "Restarting update alarm. New value: " + millis); + AlarmManager alarmManager = (AlarmManager) instance.context .getSystemService(Context.ALARM_SERVICE); - PendingIntent updateIntent = PendingIntent.getBroadcast(context, 0, - new Intent(FeedUpdateReceiver.ACTION_REFRESH_FEEDS), 0); + PendingIntent updateIntent = PendingIntent.getBroadcast( + instance.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 (millis != 0) { + alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, millis, millis, + updateIntent); if (AppConfig.DEBUG) Log.d(TAG, "Changed alarm to new intervall"); } else { diff --git a/src/de/danoeh/antennapod/receiver/AlarmUpdateReceiver.java b/src/de/danoeh/antennapod/receiver/AlarmUpdateReceiver.java new file mode 100644 index 000000000..05914a0e1 --- /dev/null +++ b/src/de/danoeh/antennapod/receiver/AlarmUpdateReceiver.java @@ -0,0 +1,30 @@ +package de.danoeh.antennapod.receiver; + +import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.preferences.UserPreferences; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +/** Listens for events that make it necessary to reset the update alarm. */ +public class AlarmUpdateReceiver extends BroadcastReceiver { + private static final String TAG = "AlarmUpdateReceiver"; + + @Override + public void onReceive(Context context, Intent intent) { + if (AppConfig.DEBUG) + Log.d(TAG, "Received intent"); + if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { + if (AppConfig.DEBUG) + Log.d(TAG, "Resetting update alarm after reboot"); + } else if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) { + if (AppConfig.DEBUG) + Log.d(TAG, "Resetting update alarm after app upgrade"); + } + + UserPreferences.restartUpdateAlarm(UserPreferences.getUpdateInterval()); + + } + +} |