mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2024-12-25 00:14:00 +01:00
setRepeating is setInexactRepeating on API 19+,
that means we can go as long as interval*2 before updates. Switched to use 'set()' instead to get behavior that matches what users expect.
This commit is contained in:
parent
0d2f99a1a7
commit
0314d0f95d
@ -343,23 +343,25 @@ public class UserPreferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the update interval value. Should only be used for testing purposes!
|
* Sets the update interval value.
|
||||||
*/
|
*/
|
||||||
public static void setUpdateInterval(long hours) {
|
public static void setUpdateInterval(long hours) {
|
||||||
prefs.edit()
|
prefs.edit()
|
||||||
.putString(PREF_UPDATE_INTERVAL, String.valueOf(hours))
|
.putString(PREF_UPDATE_INTERVAL, String.valueOf(hours))
|
||||||
.apply();
|
.apply();
|
||||||
restartUpdateAlarm();
|
// when updating with an interval, we assume the user wants
|
||||||
|
// to update *now* and then every 'hours' interval thereafter.
|
||||||
|
restartUpdateAlarm(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the update interval value. Should only be used for testing purposes!
|
* Sets the update interval value.
|
||||||
*/
|
*/
|
||||||
public static void setUpdateTimeOfDay(int hourOfDay, int minute) {
|
public static void setUpdateTimeOfDay(int hourOfDay, int minute) {
|
||||||
prefs.edit()
|
prefs.edit()
|
||||||
.putString(PREF_UPDATE_INTERVAL, hourOfDay + ":" + minute)
|
.putString(PREF_UPDATE_INTERVAL, hourOfDay + ":" + minute)
|
||||||
.apply();
|
.apply();
|
||||||
restartUpdateAlarm();
|
restartUpdateAlarm(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -538,13 +540,18 @@ public class UserPreferences {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void restartUpdateAlarm() {
|
public static void restartUpdateAlarm(boolean now) {
|
||||||
int[] timeOfDay = getUpdateTimeOfDay();
|
int[] timeOfDay = getUpdateTimeOfDay();
|
||||||
|
Log.d(TAG, "timeOfDay: " + Arrays.toString(timeOfDay));
|
||||||
if (timeOfDay.length == 2) {
|
if (timeOfDay.length == 2) {
|
||||||
restartUpdateTimeOfDayAlarm(timeOfDay[0], timeOfDay[1]);
|
restartUpdateTimeOfDayAlarm(timeOfDay[0], timeOfDay[1]);
|
||||||
} else {
|
} else {
|
||||||
long hours = getUpdateInterval();
|
long hours = getUpdateInterval();
|
||||||
restartUpdateIntervalAlarm(TimeUnit.SECONDS.toMillis(10), hours);
|
long startTrigger = hours;
|
||||||
|
if (now) {
|
||||||
|
startTrigger = TimeUnit.SECONDS.toMillis(10);
|
||||||
|
}
|
||||||
|
restartUpdateIntervalAlarm(startTrigger, hours);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,9 +565,8 @@ public class UserPreferences {
|
|||||||
new Intent(ClientConfig.applicationCallbacks.getApplicationInstance(), FeedUpdateReceiver.class), 0);
|
new Intent(ClientConfig.applicationCallbacks.getApplicationInstance(), FeedUpdateReceiver.class), 0);
|
||||||
alarmManager.cancel(updateIntent);
|
alarmManager.cancel(updateIntent);
|
||||||
if (intervalMillis > 0) {
|
if (intervalMillis > 0) {
|
||||||
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
||||||
SystemClock.elapsedRealtime() + triggerAtMillis,
|
SystemClock.elapsedRealtime() + triggerAtMillis,
|
||||||
intervalMillis,
|
|
||||||
updateIntent);
|
updateIntent);
|
||||||
Log.d(TAG, "Changed alarm to new interval " + TimeUnit.MILLISECONDS.toHours(intervalMillis) + " h");
|
Log.d(TAG, "Changed alarm to new interval " + TimeUnit.MILLISECONDS.toHours(intervalMillis) + " h");
|
||||||
} else {
|
} else {
|
||||||
@ -585,10 +591,9 @@ public class UserPreferences {
|
|||||||
if(alarm.before(now)) {
|
if(alarm.before(now)) {
|
||||||
alarm.add(Calendar.DATE, 1);
|
alarm.add(Calendar.DATE, 1);
|
||||||
}
|
}
|
||||||
|
Log.d(TAG, "Alarm set for: " + alarm.toString() + " : " + alarm.getTimeInMillis());
|
||||||
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
|
alarmManager.set(AlarmManager.RTC_WAKEUP,
|
||||||
alarm.getTimeInMillis(),
|
alarm.getTimeInMillis(),
|
||||||
AlarmManager.INTERVAL_DAY,
|
|
||||||
updateIntent);
|
updateIntent);
|
||||||
Log.d(TAG, "Changed alarm to new time of day " + hoursOfDay + ":" + minute);
|
Log.d(TAG, "Changed alarm to new time of day " + hoursOfDay + ":" + minute);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class AlarmUpdateReceiver extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
PlaybackPreferences.init(context);
|
PlaybackPreferences.init(context);
|
||||||
UserPreferences.init(context);
|
UserPreferences.init(context);
|
||||||
UserPreferences.restartUpdateAlarm();
|
UserPreferences.restartUpdateAlarm(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ public class FeedUpdateReceiver extends BroadcastReceiver {
|
|||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed");
|
Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed");
|
||||||
}
|
}
|
||||||
|
UserPreferences.restartUpdateAlarm(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user