PeriodTaskFactory: refactor interfaces.

This commit is contained in:
Dennis Guse
2021-08-24 06:20:52 +02:00
parent 29a1daa177
commit b32e87e10b
7 changed files with 35 additions and 72 deletions
@@ -42,7 +42,7 @@ import de.dennisguse.opentracks.viewmodels.IntervalStatistics;
*
* @author Sandor Dornbush
*/
public class AnnouncementPeriodicTask implements PeriodicTask {
public class AnnouncementPeriodicTask implements PeriodicTaskFactory.Task {
private static final String TAG = AnnouncementPeriodicTask.class.getSimpleName();
@@ -209,7 +209,7 @@ public class AnnouncementPeriodicTask implements PeriodicTask {
@Override
@NonNull
public PeriodicTask create(Context context) {
public Task create(Context context) {
return new AnnouncementPeriodicTask(context);
}
}
@@ -1,46 +0,0 @@
/*
* Copyright 2009 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package de.dennisguse.opentracks.services.tasks;
import androidx.annotation.NonNull;
import de.dennisguse.opentracks.content.data.Track;
import de.dennisguse.opentracks.stats.TrackStatistics;
/**
* This is interface for a task that will be executed on some schedule.
*
* @author Sandor Dornbush
*/
public interface PeriodicTask {
/**
* Sets up this task for subsequent calls to the run method.
*/
void start();
/**
* This method will be called periodically.
*/
@Deprecated
void run(@NonNull Track.Id trackId, @NonNull TrackStatistics trackStatistics);
/**
* Shuts down this task and clean up resources.
*/
void shutdown();
}
@@ -49,7 +49,7 @@ public class PeriodicTaskExecutor {
*/
private int taskFrequency;
private PeriodicTask periodicTask;
private PeriodicTaskFactory.Task periodicTask;
// Time periodic task executor
private TimerTaskExecutor timerTaskExecutor = null;
@@ -20,18 +20,40 @@ import android.content.Context;
import androidx.annotation.NonNull;
import de.dennisguse.opentracks.content.data.Track;
import de.dennisguse.opentracks.stats.TrackStatistics;
/**
* An interface for classes that can create {@link PeriodicTask}.
* An interface for classes that can create {@link Task}.
*
* @author Sandor Dornbush
*/
interface PeriodicTaskFactory {
public interface PeriodicTaskFactory {
@NonNull
Task create(Context context);
/**
* Creates a {@link PeriodicTask}.
* This is interface for a task that will be executed on some schedule.
*
* @return the task, or null if the task is not supported
* @author Sandor Dornbush
*/
@NonNull
PeriodicTask create(Context context);
interface Task {
/**
* Sets up this task for subsequent calls to the run method.
*/
void start();
/**
* This method will be called periodically.
*/
@Deprecated
void run(@NonNull Track.Id trackId, @NonNull TrackStatistics trackStatistics);
/**
* Shuts down this task and clean up resources.
*/
void shutdown();
}
}
@@ -30,13 +30,13 @@ import de.dennisguse.opentracks.services.TrackRecordingService;
*/
class TimerTaskExecutor {
private final PeriodicTask periodicTask;
private final PeriodicTaskFactory.Task periodicTask;
private final TrackRecordingService trackRecordingService;
private TimerTask timerTask;
private Timer timer;
public TimerTaskExecutor(PeriodicTask periodicTask, TrackRecordingService trackRecordingService) {
public TimerTaskExecutor(PeriodicTaskFactory.Task periodicTask, TrackRecordingService trackRecordingService) {
this.periodicTask = periodicTask;
this.trackRecordingService = trackRecordingService;
}