Prevent stopping TimerRingtoneService for successive Timers within the auto silence threshold
This commit is contained in:
parent
8f1a42ef53
commit
8b73d87e3a
@ -9,7 +9,6 @@ import android.util.Log;
|
|||||||
import com.philliphsu.clock2.alarms.ScrollHandler;
|
import com.philliphsu.clock2.alarms.ScrollHandler;
|
||||||
import com.philliphsu.clock2.model.TimersTableManager;
|
import com.philliphsu.clock2.model.TimersTableManager;
|
||||||
import com.philliphsu.clock2.timers.TimerNotificationService;
|
import com.philliphsu.clock2.timers.TimerNotificationService;
|
||||||
import com.philliphsu.clock2.timers.TimerRingtoneService;
|
|
||||||
import com.philliphsu.clock2.timers.TimesUpActivity;
|
import com.philliphsu.clock2.timers.TimesUpActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,7 +85,9 @@ public final class AsyncTimersTableUpdateHandler extends AsyncDatabaseTableUpdat
|
|||||||
TimerNotificationService.cancelNotification(getContext(), timer.getId());
|
TimerNotificationService.cancelNotification(getContext(), timer.getId());
|
||||||
}
|
}
|
||||||
// Won't do anything if not actually started
|
// 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?
|
// TODO: Do we need to finish TimesUpActivity?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ import com.philliphsu.clock2.util.AlarmController;
|
|||||||
import com.philliphsu.clock2.util.DateFormatUtils;
|
import com.philliphsu.clock2.util.DateFormatUtils;
|
||||||
|
|
||||||
public class AlarmActivity extends RingtoneActivity<Alarm> {
|
public class AlarmActivity extends RingtoneActivity<Alarm> {
|
||||||
private static final String TAG = "TimesUpActivity";
|
private static final String TAG = "AlarmActivity";
|
||||||
|
|
||||||
private AlarmController mAlarmController;
|
private AlarmController mAlarmController;
|
||||||
private NotificationManager mNotificationManager;
|
private NotificationManager mNotificationManager;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.philliphsu.clock2.timers;
|
package com.philliphsu.clock2.timers;
|
||||||
|
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.support.annotation.IdRes;
|
import android.support.annotation.IdRes;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
@ -115,6 +116,7 @@ public class TimerViewHolder extends BaseViewHolder<Timer> {
|
|||||||
@OnClick(R.id.stop)
|
@OnClick(R.id.stop)
|
||||||
void stop() {
|
void stop() {
|
||||||
mController.stop();
|
mController.stop();
|
||||||
|
getContext().stopService(new Intent(getContext(), TimerRingtoneService.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.label)
|
@OnClick(R.id.label)
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.philliphsu.clock2.timers;
|
|||||||
|
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
@ -34,6 +35,12 @@ public class TimesUpActivity extends RingtoneActivity<Timer> {
|
|||||||
mNotificationManager.cancel(TAG, getRingingObject().getIntId());
|
mNotificationManager.cancel(TAG, getRingingObject().getIntId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNewIntent(Intent intent) {
|
||||||
|
super.onNewIntent(intent);
|
||||||
|
postExpiredTimerNote();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<? extends RingtoneService> getRingtoneServiceClass() {
|
protected Class<? extends RingtoneService> getRingtoneServiceClass() {
|
||||||
return TimerRingtoneService.class;
|
return TimerRingtoneService.class;
|
||||||
@ -100,10 +107,14 @@ public class TimesUpActivity extends RingtoneActivity<Timer> {
|
|||||||
@Override
|
@Override
|
||||||
protected void showAutoSilenced() {
|
protected void showAutoSilenced() {
|
||||||
super.showAutoSilenced();
|
super.showAutoSilenced();
|
||||||
|
postExpiredTimerNote();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void postExpiredTimerNote() {
|
||||||
Notification note = new NotificationCompat.Builder(this)
|
Notification note = new NotificationCompat.Builder(this)
|
||||||
.setContentTitle(getString(R.string.timer_expired))
|
.setContentTitle(getString(R.string.timer_expired))
|
||||||
.setContentText(getRingingObject().label())
|
.setContentText(getRingingObject().label())
|
||||||
.setSmallIcon(R.mipmap.ic_launcher) // TODO: correct icon
|
.setSmallIcon(R.drawable.ic_timer_24dp)
|
||||||
.build();
|
.build();
|
||||||
mNotificationManager.notify(TAG, getRingingObject().getIntId(), note);
|
mNotificationManager.notify(TAG, getRingingObject().getIntId(), note);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user