package nl.waywayway.broodkruimels;

import android.os.*;
import com.firebase.jobdispatcher.*;
import nl.waywayway.broodkruimels.*;

public class ScheduledJobRunOnce
{
	private FirebaseJobDispatcher dispatcher;
	public static final String TAG_SCHEDULED_JOB_RUN_ONCE = "tag_scheduled_job_run_once";

	public ScheduledJobRunOnce(FirebaseJobDispatcher dispatcher)
	{
		this.dispatcher = dispatcher;
	}

	public void schedule()
	{
		/*
		 Bundle myExtrasBundle = new Bundle();
		 myExtrasBundle.putString("some_key", "some_value");
		 */

		Job myJob = dispatcher.newJobBuilder()
			// the JobService that will be called
			.setService(MyJobService.class)
			// uniquely identifies the job
			.setTag(TAG_SCHEDULED_JOB_RUN_ONCE)
			// one-off job
			.setRecurring(false)
			// don't persist past a device reboot
			.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
			// start between x and x seconds from now
			.setTrigger(Trigger.executionWindow(0, 20))
			// overwrite an existing job with the same tag
			.setReplaceCurrent(true)
			// retry with exponential backoff
			.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
			// constraints that need to be satisfied for the job to run
			/*
			.setConstraints(
			// only run on an unmetered network
			Constraint.ON_UNMETERED_NETWORK,
			// only run when the device is charging
			Constraint.DEVICE_CHARGING)
			// .setExtras(myExtrasBundle)
			*/
			.build();

		dispatcher.mustSchedule(myJob);
	}
}

@@ -528,16 +528,130 @@
 %0A%09%09 */%0A%0A
+%09%09RetryStrategy retryStrategy = dispatcher.newRetryStrategy(RetryStrategy.RETRY_POLICY_EXPONENTIAL, 20, 120);%0A%09%09 %0A
 %09%09Job my
@@ -1177,33 +1177,33 @@
 etRetryStrategy(
-R
+r
 etryStrategy.DEF
@@ -1202,28 +1202,8 @@
 tegy
-.DEFAULT_EXPONENTIAL
 )%0A%09%09
@@ -1267,14 +1267,8 @@
 run%0A
-%09%09%09/*%0A
 %09%09%09.
@@ -1282,24 +1282,25 @@
 traints(%0A%09%09%09
+%09
 // only run 
@@ -1322,24 +1322,25 @@
  network%0A%09%09%09
+%09
 Constraint.O
@@ -1345,25 +1345,19 @@
 .ON_
-UNMETERED
+ANY
 _NETWORK
 ,%0A%09%09
@@ -1356,122 +1356,13 @@
 WORK
-,
 %0A%09%09%09
-// only run when the device is charging%0A%09%09%09Constraint.DEVICE_CHARGING)%0A%09%09%09// .setExtras(myExtrasBundle)%0A%09%09%09*/
+)
 %0A%09%09%09

Fix ScheduledJob voorwaarden: met netwerk verbonden, custom retry policy