From 61262f751061ba44f5790ef2643bce38a53ecead Mon Sep 17 00:00:00 2001 From: Ben Moran Date: Sat, 23 Feb 2019 12:09:36 +0000 Subject: [PATCH] Show pending job state at end of command, state if no pending jobs --- .../java/com/termux/api/JobSchedulerAPI.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/termux/api/JobSchedulerAPI.java b/app/src/main/java/com/termux/api/JobSchedulerAPI.java index 8db1568..3aa9c42 100644 --- a/app/src/main/java/com/termux/api/JobSchedulerAPI.java +++ b/app/src/main/java/com/termux/api/JobSchedulerAPI.java @@ -140,9 +140,6 @@ public class JobSchedulerAPI { PersistableBundle extras = new PersistableBundle(); extras.putString(SchedulerJobService.SCRIPT_FILE_PATH, file.getAbsolutePath()); - - displayPendingJobs(apiReceiver, intent, jobScheduler); - ComponentName serviceComponent = new ComponentName(context, SchedulerJobService.class); JobInfo.Builder builder = new JobInfo.Builder(jobId, serviceComponent) .setExtras(extras) @@ -167,13 +164,20 @@ public class JobSchedulerAPI { Log.i(LOG_TAG, message); ResultReturner.returnData(apiReceiver, intent, out -> out.println(message)); + + displayPendingJobs(apiReceiver, intent, jobScheduler); + } private static void displayPendingJobs(TermuxApiReceiver apiReceiver, Intent intent, JobScheduler jobScheduler) { // Display pending jobs - for (JobInfo job : jobScheduler.getAllPendingJobs()) { - final JobInfo j = job; - ResultReturner.returnData(apiReceiver, intent, out -> out.println(String.format(Locale.ENGLISH, "Pending %s", formatJobInfo(j)))); + final List jobs = jobScheduler.getAllPendingJobs(); + if (jobs.isEmpty()) { + ResultReturner.returnData(apiReceiver, intent, out -> out.println("No pending jobs")); + return; + } + for (JobInfo job : jobs) { + ResultReturner.returnData(apiReceiver, intent, out -> out.println(String.format(Locale.ENGLISH, "Pending %s", formatJobInfo(job)))); } }