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

View File

@ -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?
}
}

View File

@ -15,7 +15,7 @@ import com.philliphsu.clock2.util.AlarmController;
import com.philliphsu.clock2.util.DateFormatUtils;
public class AlarmActivity extends RingtoneActivity<Alarm> {
private static final String TAG = "TimesUpActivity";
private static final String TAG = "AlarmActivity";
private AlarmController mAlarmController;
private NotificationManager mNotificationManager;

View File

@ -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)

View File

@ -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);
}