Java Code Examples for androidx.work.WorkManager#enqueue()

The following examples show how to use androidx.work.WorkManager#enqueue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComposeRepository.java    From lttrs-android with Apache License 2.0 6 votes vote down vote up
public void sendEmail(IdentifiableIdentity identity, ComposeViewModel.Draft draft, final Collection<String> inReplyTo) {
    final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(SendEmailWorker.class)
            .setConstraints(CONNECTED_CONSTRAINT)
            .setInputData(SendEmailWorker.data(
                    requireAccount().id,
                    identity.getId(),
                    inReplyTo,
                    draft.getTo(),
                    draft.getCc(),
                    draft.getSubject(),
                    draft.getBody()
            ))
            .build();
    final WorkManager workManager = WorkManager.getInstance(application);
    workManager.enqueue(workRequest);
}
 
Example 2
Source File: ComposeRepository.java    From lttrs-android with Apache License 2.0 6 votes vote down vote up
public boolean discard(EditableEmail editableEmail) {
    final OneTimeWorkRequest discardDraft = new OneTimeWorkRequest.Builder(DiscardDraftWorker.class)
            .setConstraints(CONNECTED_CONSTRAINT)
            .setInputData(DiscardDraftWorker.data(requireAccount().id, editableEmail.id))
            .build();
    final WorkManager workManager = WorkManager.getInstance(application);
    final boolean isOnlyEmailInThread = editableEmail.isOnlyEmailInThread();
    if (isOnlyEmailInThread) {
        insertQueryItemOverwrite(editableEmail.threadId);
    }
    workManager.enqueue(discardDraft);
    return isOnlyEmailInThread;
}
 
Example 3
Source File: JobProxyWorkManager.java    From android-job with Apache License 2.0 6 votes vote down vote up
@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(), TimeUnit.MILLISECONDS) // don't use the average here, WorkManager will do the right thing
            .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);
}
 
Example 4
Source File: CandyBarArtWorker.java    From candybar with Apache License 2.0 5 votes vote down vote up
public static void enqueueLoad(Context context) {
    WorkManager manager = WorkManager.getInstance(context);
    Constraints constraints = new Constraints.Builder()
            .setRequiredNetworkType(NetworkType.CONNECTED)
            .build();
    WorkRequest request = new OneTimeWorkRequest.Builder(CandyBarArtWorker.class)
            .setConstraints(constraints)
            .build();
    manager.enqueue(request);
}
 
Example 5
Source File: ComposeRepository.java    From lttrs-android with Apache License 2.0 5 votes vote down vote up
public void submitEmail(IdentityWithNameAndEmail identity, EditableEmail editableEmail) {
    final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(SubmitEmailWorker.class)
            .setConstraints(CONNECTED_CONSTRAINT)
            .setInputData(SubmitEmailWorker.data(
                    requireAccount().id,
                    identity.getId(),
                    editableEmail.id
            ))
            .build();
    final WorkManager workManager = WorkManager.getInstance(application);
    workManager.enqueue(workRequest);
}
 
Example 6
Source File: JobProxyWorkManager.java    From android-job with Apache License 2.0 5 votes vote down vote up
@Override
public void plantPeriodic(JobRequest request) {
    PeriodicWorkRequest workRequest = new PeriodicWorkRequest.Builder(PlatformWorker.class, request.getIntervalMs(), TimeUnit.MILLISECONDS,
            request.getFlexMs(), TimeUnit.MILLISECONDS)
            .setConstraints(buildConstraints(request))
            .addTag(createTag(request.getJobId()))
            .build();

    WorkManager workManager = getWorkManager();
    if (workManager == null) {
        throw new JobProxyIllegalStateException("WorkManager is null");
    }

    workManager.enqueue(workRequest);
}