First real try first correct schedule

This commit is contained in:
jacques 2020-12-28 19:34:34 +01:00
parent 2ce52907f0
commit 3ae3e56ba7

View file

@ -42,6 +42,7 @@ import za.co.riggaroo.materialhelptutorial.TutorialItem;
import za.co.riggaroo.materialhelptutorial.tutorial.MaterialTutorialActivity; import za.co.riggaroo.materialhelptutorial.tutorial.MaterialTutorialActivity;
import static net.foucry.pilldroid.UtilDate.date2String; import static net.foucry.pilldroid.UtilDate.date2String;
import static net.foucry.pilldroid.UtilDate.dateAtNoon;
import static net.foucry.pilldroid.Utils.intRandomExclusive; import static net.foucry.pilldroid.Utils.intRandomExclusive;
// Todo: - add launch tuto at first launch // Todo: - add launch tuto at first launch
@ -378,38 +379,38 @@ public class MedicamentListActivity extends AppCompatActivity {
public void scheduleJob() { public void scheduleJob() {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
Date today = calendar.getTime(); Date today = calendar.getTime();
calendar.add(Calendar.MINUTE, 5); calendar.add(Calendar.DAY_OF_YEAR, 1);
Date tomorrow = calendar.getTime(); Date tomorrow = calendar.getTime();
Date scheduleDate; Date scheduleDate;
JobInfo info; JobInfo info;
ComponentName componentName = new ComponentName(this, PillDroidJobService.class); ComponentName componentName = new ComponentName(this, PillDroidJobService.class);
info = new JobInfo.Builder(24560, componentName) /*info = new JobInfo.Builder(24560, componentName)
.setMinimumLatency(60 * 15 * 1000) .setMinimumLatency(60 * 15 * 1000)
.setOverrideDeadline(60 * 60 * 1000) .setOverrideDeadline(60 * 60 * 1000)
.build(); .build();*/
/*if (today.before(dateAtNoon(today))) { if (today.before(dateAtNoon(today))) {
info = new JobInfo.Builder(24560, componentName) info = new JobInfo.Builder(24560, componentName)
.setPersisted(true) .setPersisted(true)
//.setMinimumLatency(dateAtNoon(today).getTime()) .setMinimumLatency(dateAtNoon(today).getTime())
.setMinimumLatency(today.getTime()) //.setMinimumLatency(today.getTime())
.build(); .build();
scheduleDate = today; scheduleDate = today;
} else { } else {
info = new JobInfo.Builder(24560, componentName) info = new JobInfo.Builder(24560, componentName)
.setPersisted(true) .setPersisted(true)
//.setMinimumLatency(dateAtNoon(tomorrow).getTime()) .setMinimumLatency(dateAtNoon(tomorrow).getTime())
.setMinimumLatency(tomorrow.getTime()) //.setMinimumLatency(tomorrow.getTime())
.build(); .build();
scheduleDate = tomorrow; scheduleDate = tomorrow;
}*/ }
JobScheduler scheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE); JobScheduler scheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
int resultCode = scheduler.schedule(info); int resultCode = scheduler.schedule(info);
if (resultCode == JobScheduler.RESULT_SUCCESS) { if (resultCode == JobScheduler.RESULT_SUCCESS) {
//Log.d(TAG, "Job scheduled at " + dateAtNoon(scheduleDate)); Log.d(TAG, "Job scheduled at " + dateAtNoon(scheduleDate));
Log.d(TAG, "Job scheduled at "); Log.d(TAG, "Job scheduled at ");
} else { } else {
Log.d(TAG, "Job scheduling failed"); Log.d(TAG, "Job scheduling failed");
@ -418,7 +419,7 @@ public class MedicamentListActivity extends AppCompatActivity {
/** /**
* cancelJob in PillDroidJobService * cancelJob in PillDroidJobService
* @param v Riew * @param v View
*/ */
public void cancelJob(View v) { public void cancelJob(View v) {
JobScheduler scheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE); JobScheduler scheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);