Prevent stopping TimerRingtoneService for successive Timers within the auto silence threshold

This commit is contained in:
Phillip Hsu
2016-09-18 21:07:54 -07:00
parent 8f1a42ef53
commit 8b73d87e3a
4 changed files with 18 additions and 4 deletions
@@ -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<Timer> {
@OnClick(R.id.stop)
void stop() {
mController.stop();
getContext().stopService(new Intent(getContext(), TimerRingtoneService.class));
}
@OnClick(R.id.label)
@@ -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<Timer> {
mNotificationManager.cancel(TAG, getRingingObject().getIntId());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
postExpiredTimerNote();
}
@Override
protected Class<? extends RingtoneService> getRingtoneServiceClass() {
return TimerRingtoneService.class;
@@ -100,10 +107,14 @@ public class TimesUpActivity extends RingtoneActivity<Timer> {
@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);
}