Start the update alarm on start of the app.
This commit is contained in:
parent
3692119bed
commit
93a65ba49e
|
@ -65,6 +65,10 @@ public class PodcastApp extends Application implements
|
||||||
currentlyPlayingMediaId = prefs.getLong(
|
currentlyPlayingMediaId = prefs.getLong(
|
||||||
PlaybackService.PREF_CURRENTLY_PLAYING_MEDIA,
|
PlaybackService.PREF_CURRENTLY_PLAYING_MEDIA,
|
||||||
PlaybackService.NO_MEDIA_PLAYING);
|
PlaybackService.NO_MEDIA_PLAYING);
|
||||||
|
// start the update alarm
|
||||||
|
int hours = Integer.parseInt(prefs.getString(
|
||||||
|
PREF_UPDATE_INTERVALL, "0"));
|
||||||
|
restartUpdateAlarm(hours);
|
||||||
readThemeValue();
|
readThemeValue();
|
||||||
createImportDirectory();
|
createImportDirectory();
|
||||||
createNoMediaFile();
|
createNoMediaFile();
|
||||||
|
@ -126,22 +130,9 @@ public class PodcastApp extends Application implements
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Registered change of application preferences");
|
Log.d(TAG, "Registered change of application preferences");
|
||||||
if (key.equals(PREF_UPDATE_INTERVALL)) {
|
if (key.equals(PREF_UPDATE_INTERVALL)) {
|
||||||
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
|
||||||
int hours = Integer.parseInt(sharedPreferences.getString(
|
int hours = Integer.parseInt(sharedPreferences.getString(
|
||||||
PREF_UPDATE_INTERVALL, "0"));
|
PREF_UPDATE_INTERVALL, "0"));
|
||||||
PendingIntent updateIntent = PendingIntent.getBroadcast(this, 0,
|
restartUpdateAlarm(hours);
|
||||||
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");
|
|
||||||
}
|
|
||||||
} else if (key.equals(PREF_DISPLAY_ONLY_EPISODES)) {
|
} else if (key.equals(PREF_DISPLAY_ONLY_EPISODES)) {
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "PREF_DISPLAY_ONLY_EPISODES changed");
|
Log.d(TAG, "PREF_DISPLAY_ONLY_EPISODES changed");
|
||||||
|
@ -208,4 +199,22 @@ public class PodcastApp extends Application implements
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void restartUpdateAlarm(int hours) {
|
||||||
|
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||||
|
PendingIntent updateIntent = PendingIntent.getBroadcast(this, 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue