Merge branch 'toggles-update_alarm' into develop

Conflicts:
	src/de/danoeh/antennapod/PodcastApp.java
This commit is contained in:
daniel oeh 2013-03-14 11:04:48 +01:00
commit fbb4772132
2 changed files with 30 additions and 17 deletions

View File

@ -52,5 +52,4 @@ public class PodcastApp extends Application {
|| (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE; || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
} }
} }

View File

@ -198,22 +198,11 @@ public class UserPreferences implements
followQueue = sp.getBoolean(PREF_FOLLOW_QUEUE, false); followQueue = sp.getBoolean(PREF_FOLLOW_QUEUE, false);
} else if (key.equals(PREF_UPDATE_INTERVAL)) { } else if (key.equals(PREF_UPDATE_INTERVAL)) {
AlarmManager alarmManager = (AlarmManager) context int hours = Integer.parseInt(sp
.getSystemService(Context.ALARM_SERVICE); .getString(PREF_UPDATE_INTERVAL, "0"));
updateInterval = readUpdateInterval(sp.getString( updateInterval = readUpdateInterval(sp
PREF_UPDATE_INTERVAL, "0")); .getString(PREF_UPDATE_INTERVAL, "0"));
PendingIntent updateIntent = PendingIntent.getBroadcast(context, 0, restartUpdateAlarm(hours);
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");
}
} else if (key.equals(PREF_AUTO_DELETE)) { } else if (key.equals(PREF_AUTO_DELETE)) {
autoDelete = sp.getBoolean(PREF_AUTO_DELETE, false); 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");
}
}
} }