From 8b73d87e3ac2f0601089d72eefb7e52093c13759 Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Sun, 18 Sep 2016 21:07:54 -0700 Subject: [PATCH] Prevent stopping TimerRingtoneService for successive Timers within the auto silence threshold --- .../clock2/AsyncTimersTableUpdateHandler.java | 5 +++-- .../com/philliphsu/clock2/alarms/AlarmActivity.java | 2 +- .../philliphsu/clock2/timers/TimerViewHolder.java | 2 ++ .../philliphsu/clock2/timers/TimesUpActivity.java | 13 ++++++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/philliphsu/clock2/AsyncTimersTableUpdateHandler.java b/app/src/main/java/com/philliphsu/clock2/AsyncTimersTableUpdateHandler.java index 8ef2a12..c7a0077 100644 --- a/app/src/main/java/com/philliphsu/clock2/AsyncTimersTableUpdateHandler.java +++ b/app/src/main/java/com/philliphsu/clock2/AsyncTimersTableUpdateHandler.java @@ -9,7 +9,6 @@ import android.util.Log; import com.philliphsu.clock2.alarms.ScrollHandler; import com.philliphsu.clock2.model.TimersTableManager; import com.philliphsu.clock2.timers.TimerNotificationService; -import com.philliphsu.clock2.timers.TimerRingtoneService; import com.philliphsu.clock2.timers.TimesUpActivity; /** @@ -86,7 +85,9 @@ public final class AsyncTimersTableUpdateHandler extends AsyncDatabaseTableUpdat TimerNotificationService.cancelNotification(getContext(), timer.getId()); } // Won't do anything if not actually started - getContext().stopService(new Intent(getContext(), TimerRingtoneService.class)); + // This was actually a problem for successive Timers. We actually don't need to + // manually stop the service in many cases. See usages of TimerController.stop(). +// getContext().stopService(new Intent(getContext(), TimerRingtoneService.class)); // TODO: Do we need to finish TimesUpActivity? } } diff --git a/app/src/main/java/com/philliphsu/clock2/alarms/AlarmActivity.java b/app/src/main/java/com/philliphsu/clock2/alarms/AlarmActivity.java index bd1b5e6..ee1bd48 100644 --- a/app/src/main/java/com/philliphsu/clock2/alarms/AlarmActivity.java +++ b/app/src/main/java/com/philliphsu/clock2/alarms/AlarmActivity.java @@ -15,7 +15,7 @@ import com.philliphsu.clock2.util.AlarmController; import com.philliphsu.clock2.util.DateFormatUtils; public class AlarmActivity extends RingtoneActivity { - private static final String TAG = "TimesUpActivity"; + private static final String TAG = "AlarmActivity"; private AlarmController mAlarmController; private NotificationManager mNotificationManager; diff --git a/app/src/main/java/com/philliphsu/clock2/timers/TimerViewHolder.java b/app/src/main/java/com/philliphsu/clock2/timers/TimerViewHolder.java index 7795fcf..d78b070 100644 --- a/app/src/main/java/com/philliphsu/clock2/timers/TimerViewHolder.java +++ b/app/src/main/java/com/philliphsu/clock2/timers/TimerViewHolder.java @@ -1,6 +1,7 @@ package com.philliphsu.clock2.timers; import android.animation.ObjectAnimator; +import android.content.Intent; import android.graphics.drawable.Drawable; import android.support.annotation.IdRes; import android.support.v4.content.ContextCompat; @@ -115,6 +116,7 @@ public class TimerViewHolder extends BaseViewHolder { @OnClick(R.id.stop) void stop() { mController.stop(); + getContext().stopService(new Intent(getContext(), TimerRingtoneService.class)); } @OnClick(R.id.label) diff --git a/app/src/main/java/com/philliphsu/clock2/timers/TimesUpActivity.java b/app/src/main/java/com/philliphsu/clock2/timers/TimesUpActivity.java index f4d200c..258daa8 100644 --- a/app/src/main/java/com/philliphsu/clock2/timers/TimesUpActivity.java +++ b/app/src/main/java/com/philliphsu/clock2/timers/TimesUpActivity.java @@ -2,6 +2,7 @@ package com.philliphsu.clock2.timers; import android.app.Notification; import android.app.NotificationManager; +import android.content.Intent; import android.os.Bundle; import android.os.SystemClock; import android.support.v4.app.NotificationCompat; @@ -34,6 +35,12 @@ public class TimesUpActivity extends RingtoneActivity { mNotificationManager.cancel(TAG, getRingingObject().getIntId()); } + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + postExpiredTimerNote(); + } + @Override protected Class getRingtoneServiceClass() { return TimerRingtoneService.class; @@ -100,10 +107,14 @@ public class TimesUpActivity extends RingtoneActivity { @Override protected void showAutoSilenced() { super.showAutoSilenced(); + postExpiredTimerNote(); + } + + private void postExpiredTimerNote() { Notification note = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.timer_expired)) .setContentText(getRingingObject().label()) - .setSmallIcon(R.mipmap.ic_launcher) // TODO: correct icon + .setSmallIcon(R.drawable.ic_timer_24dp) .build(); mNotificationManager.notify(TAG, getRingingObject().getIntId(), note); }