From 8f1a42ef53181ab0c522b1c793ed5e19c6fbb94a Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Sun, 18 Sep 2016 17:48:17 -0700 Subject: [PATCH] When changes made via TimerVH, do not modify notification chronometer unless new Timer's end time is different from previous Timer --- .../timers/TimerNotificationService.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/philliphsu/clock2/timers/TimerNotificationService.java b/app/src/main/java/com/philliphsu/clock2/timers/TimerNotificationService.java index 107568f..edaad82 100644 --- a/app/src/main/java/com/philliphsu/clock2/timers/TimerNotificationService.java +++ b/app/src/main/java/com/philliphsu/clock2/timers/TimerNotificationService.java @@ -163,15 +163,17 @@ public class TimerNotificationService extends ChronometerNotificationService { @Override protected void handleDefaultAction(Intent intent, int flags, int startId) { - Timer timer = intent.getParcelableExtra(EXTRA_TIMER); + final Timer timer = intent.getParcelableExtra(EXTRA_TIMER); if (timer == null) { throw new IllegalStateException("Cannot start TimerNotificationService without a Timer"); } final long id = timer.getId(); - final boolean isUpdate = mTimers.containsKey(id); // could use either map - mTimers.put(id, timer); + boolean updateChronometer = false; + Timer oldTimer = mTimers.put(id, timer); + if (oldTimer != null) { + updateChronometer = oldTimer.endTime() != timer.endTime(); + } mControllers.put(id, new TimerController(timer, mUpdateHandler)); - mMostRecentTimerId = id; // If isUpdate == true, this won't call through because the id already exists in the // internal mappings as well. @@ -182,12 +184,14 @@ public class TimerNotificationService extends ChronometerNotificationService { title = getString(R.string.timer); } setContentTitle(id, title); - if (isUpdate) { - // Immediately push any updates, or else there will be a noticeable delay. - // If there were any duration changes, this will reflect them. + if (updateChronometer) { + // Immediately push any duration updates, or else there will be a noticeable delay. setBase(id, timer.endTime()); updateNotification(id, true); } + // This handles any other notification updates like the title or actions, even if + // the timer is not running because the current thread will update the notification + // (besides the content text) before quitting. syncNotificationWithTimerState(id, timer.isRunning()); }