forked from upstream-mirrors/OpenTracks
Replace long time_ms with Instant and Duration, respectively.
Fixes #561.
This commit is contained in:
@@ -17,6 +17,8 @@ package de.dennisguse.opentracks.services.tasks;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.services.TrackRecordingService;
|
||||
import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||
@@ -92,7 +94,7 @@ public class PeriodicTaskExecutor {
|
||||
if (timerTaskExecutor == null) {
|
||||
timerTaskExecutor = new TimerTaskExecutor(periodicTask, trackRecordingService);
|
||||
}
|
||||
timerTaskExecutor.scheduleTask(taskFrequency * UnitConversions.ONE_MINUTE_MS);
|
||||
timerTaskExecutor.scheduleTask(Duration.ofSeconds(taskFrequency));
|
||||
} else {
|
||||
// For distance periodic task
|
||||
calculateNextTaskDistance();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package de.dennisguse.opentracks.services.tasks;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Date;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
@@ -42,15 +43,9 @@ class TimerTaskExecutor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the periodic task in milliseconds.
|
||||
*
|
||||
* @param interval_ms the interval_ms
|
||||
* Schedules the periodic task.
|
||||
*/
|
||||
void scheduleTask(long interval_ms) {
|
||||
if (interval_ms <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
void scheduleTask(Duration interval) {
|
||||
if (!trackRecordingService.isRecording() || trackRecordingService.isPaused()) {
|
||||
return;
|
||||
}
|
||||
@@ -69,8 +64,10 @@ class TimerTaskExecutor {
|
||||
}
|
||||
};
|
||||
timer = new Timer(TimerTaskExecutor.class.getSimpleName());
|
||||
long next = System.currentTimeMillis() + interval_ms - (trackStatistics.getTotalTime() % interval_ms);
|
||||
timer.scheduleAtFixedRate(timerTask, new Date(next), interval_ms);
|
||||
|
||||
//TODO Simplify: far too complicated for it's purpose
|
||||
long next = System.currentTimeMillis() + interval.toMillis() - (trackStatistics.getTotalTime().toMillis() % interval.toMillis());
|
||||
timer.scheduleAtFixedRate(timerTask, new Date(next), interval.toMillis());
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
|
||||
Reference in New Issue
Block a user