mirror of
https://github.com/M66B/FairEmail.git
synced 2025-12-27 08:01:50 +01:00
Added simple scheduling
This commit is contained in:
@@ -42,19 +42,22 @@ public class JobDaily extends JobService {
|
||||
private static final long CACHE_IMAGE_DURATION = 3 * 24 * 3600 * 1000L; // milliseconds
|
||||
private static final long KEEP_LOG_DURATION = 24 * 3600 * 1000L; // milliseconds
|
||||
|
||||
public static void schedule(Context context) {
|
||||
Log.i("Scheduling daily job");
|
||||
public static void schedule(Context context, boolean enabled) {
|
||||
JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
||||
|
||||
JobInfo.Builder job = new JobInfo.Builder(Helper.JOB_DAILY, new ComponentName(context, JobDaily.class))
|
||||
.setPeriodic(CLEANUP_INTERVAL)
|
||||
.setRequiresDeviceIdle(true);
|
||||
|
||||
JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
||||
scheduler.cancel(Helper.JOB_DAILY);
|
||||
if (scheduler.schedule(job.build()) == JobScheduler.RESULT_SUCCESS)
|
||||
Log.i("Scheduled daily job");
|
||||
else
|
||||
Log.e("Scheduling daily job failed");
|
||||
if (enabled)
|
||||
if (scheduler.schedule(job.build()) == JobScheduler.RESULT_SUCCESS)
|
||||
Log.i("Scheduled daily job");
|
||||
else
|
||||
Log.e("Scheduling daily job failed");
|
||||
else {
|
||||
Log.i("Cancelled daily job");
|
||||
scheduler.cancel(Helper.JOB_DAILY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user