mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 04:35:57 +00:00
Set initial delay for polling
This commit is contained in:
parent
9d3eb2d270
commit
24529d8f77
1 changed files with 5 additions and 1 deletions
|
@ -31,6 +31,7 @@ import androidx.work.Worker;
|
||||||
import androidx.work.WorkerParameters;
|
import androidx.work.WorkerParameters;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -55,10 +56,13 @@ public class WorkerPoll extends Worker {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
int pollInterval = prefs.getInt("poll_interval", 0);
|
int pollInterval = prefs.getInt("poll_interval", 0);
|
||||||
if (enabled && pollInterval > 0) {
|
if (enabled && pollInterval > 0) {
|
||||||
Log.i("Queuing " + getName() + " every " + pollInterval + " minutes");
|
int min = (int) (new Date().getTime() / (60 * 1000L));
|
||||||
|
int delay = pollInterval - min % pollInterval;
|
||||||
|
Log.i("Queuing " + getName() + " every " + pollInterval + " minutes delay=" + delay);
|
||||||
|
|
||||||
PeriodicWorkRequest workRequest =
|
PeriodicWorkRequest workRequest =
|
||||||
new PeriodicWorkRequest.Builder(WorkerPoll.class, pollInterval, TimeUnit.MINUTES)
|
new PeriodicWorkRequest.Builder(WorkerPoll.class, pollInterval, TimeUnit.MINUTES)
|
||||||
|
.setInitialDelay(delay, TimeUnit.MINUTES)
|
||||||
.build();
|
.build();
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.enqueueUniquePeriodicWork(getName(), ExistingPeriodicWorkPolicy.REPLACE, workRequest);
|
.enqueueUniquePeriodicWork(getName(), ExistingPeriodicWorkPolicy.REPLACE, workRequest);
|
||||||
|
|
Loading…
Reference in a new issue