Search in sources :

Example 6 with OneTimeWorkRequest

use of androidx.work.OneTimeWorkRequest in project AntennaPod by AntennaPod.

the class SyncService method syncImmediately.

public static void syncImmediately(Context context) {
    OneTimeWorkRequest workRequest = getWorkRequest().setInitialDelay(0L, TimeUnit.SECONDS).build();
    WorkManager.getInstance(context).enqueueUniqueWork(WORK_ID_SYNC, ExistingWorkPolicy.REPLACE, workRequest);
}
Also used : OneTimeWorkRequest(androidx.work.OneTimeWorkRequest)

Example 7 with OneTimeWorkRequest

use of androidx.work.OneTimeWorkRequest in project AntennaPod by AntennaPod.

the class SyncService method fullSync.

public static void fullSync(Context context) {
    LockingAsyncExecutor.executeLockedAsync(() -> {
        SynchronizationSettings.resetTimestamps();
        OneTimeWorkRequest workRequest = getWorkRequest().setInitialDelay(0L, TimeUnit.SECONDS).build();
        WorkManager.getInstance(context).enqueueUniqueWork(WORK_ID_SYNC, ExistingWorkPolicy.REPLACE, workRequest);
    });
}
Also used : OneTimeWorkRequest(androidx.work.OneTimeWorkRequest)

Example 8 with OneTimeWorkRequest

use of androidx.work.OneTimeWorkRequest in project AntennaPod by AntennaPod.

the class AutoUpdateManager method restartUpdateTimeOfDayAlarm.

/**
 * Sets time of day the feeds are refreshed automatically
 */
private static void restartUpdateTimeOfDayAlarm(int hoursOfDay, int minute, Context context) {
    Log.d(TAG, "Restarting update alarm.");
    Calendar now = Calendar.getInstance();
    Calendar alarm = (Calendar) now.clone();
    alarm.set(Calendar.HOUR_OF_DAY, hoursOfDay);
    alarm.set(Calendar.MINUTE, minute);
    if (alarm.before(now) || alarm.equals(now)) {
        alarm.add(Calendar.DATE, 1);
    }
    long triggerAtMillis = alarm.getTimeInMillis() - now.getTimeInMillis();
    OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(FeedUpdateWorker.class).setConstraints(getConstraints()).setInitialDelay(triggerAtMillis, TimeUnit.MILLISECONDS).build();
    WorkManager.getInstance(context).enqueueUniqueWork(WORK_ID_FEED_UPDATE, ExistingWorkPolicy.REPLACE, workRequest);
}
Also used : Calendar(java.util.Calendar) FeedUpdateWorker(de.danoeh.antennapod.core.service.FeedUpdateWorker) OneTimeWorkRequest(androidx.work.OneTimeWorkRequest)

Example 9 with OneTimeWorkRequest

use of androidx.work.OneTimeWorkRequest in project quickstart-android by firebase.

the class MyFirebaseMessagingService method scheduleJob.

// [END on_new_token]
/**
 * Schedule async work using WorkManager.
 */
private void scheduleJob() {
    // [START dispatch_job]
    OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(MyWorker.class).build();
    WorkManager.getInstance(this).beginWith(work).enqueue();
// [END dispatch_job]
}
Also used : OneTimeWorkRequest(androidx.work.OneTimeWorkRequest)

Example 10 with OneTimeWorkRequest

use of androidx.work.OneTimeWorkRequest in project android-job by evernote.

the class JobProxyWorkManager method plantOneOff.

@Override
public void plantOneOff(JobRequest request) {
    if (request.isTransient()) {
        TransientBundleHolder.putBundle(request.getJobId(), request.getTransientExtras());
    }
    OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(PlatformWorker.class).setInitialDelay(request.getStartMs(), // don't use the average here, WorkManager will do the right thing
    TimeUnit.MILLISECONDS).setConstraints(buildConstraints(request)).addTag(createTag(request.getJobId())).build();
    // don't set the back-off criteria, android-job is handling this
    WorkManager workManager = getWorkManager();
    if (workManager == null) {
        throw new JobProxyIllegalStateException("WorkManager is null");
    }
    workManager.enqueue(workRequest);
}
Also used : WorkManager(androidx.work.WorkManager) JobProxyIllegalStateException(com.evernote.android.job.JobProxyIllegalStateException) OneTimeWorkRequest(androidx.work.OneTimeWorkRequest)

Aggregations

OneTimeWorkRequest (androidx.work.OneTimeWorkRequest)14 Data (androidx.work.Data)3 LargeTest (androidx.test.filters.LargeTest)2 Constraints (androidx.work.Constraints)2 WorkInfo (androidx.work.WorkInfo)2 WorkManager (androidx.work.WorkManager)2 Test (org.junit.Test)2 JobProxyIllegalStateException (com.evernote.android.job.JobProxyIllegalStateException)1 FeedUpdateWorker (de.danoeh.antennapod.core.service.FeedUpdateWorker)1 Calendar (java.util.Calendar)1 FileCompatTest (org.fdroid.fdroid.compat.FileCompatTest)1