Fixed AlarmViewHolder dismiss button action

This commit is contained in:
Phillip Hsu 2016-07-09 02:46:22 -07:00
parent d17f514bd3
commit 1843c7222a

View File

@ -68,10 +68,16 @@ public class AlarmViewHolder extends BaseViewHolder<Alarm> implements AlarmCount
@OnClick(R.id.dismiss) @OnClick(R.id.dismiss)
void dismiss() { void dismiss() {
// TODO: This is NOT correct for all alarms! This may be correct for single Alarm alarm = getAlarm();
// use alarms, but not so for recurring alarms! if (!alarm.hasRecurrence()) {
mSwitch.setPressed(true); // needed so the OnCheckedChange event calls through // This is a single-use alarm, so turn it off completely.
bindSwitch(false); // fires OnCheckedChange to do the binding for you mSwitch.setPressed(true); // needed so the OnCheckedChange event calls through
bindSwitch(false); // fires OnCheckedChange to turn off the alarm for us
} else {
// Dismisses the current upcoming alarm and handles scheduling the next alarm for us.
// Since changes are saved to the database, this prompts a UI refresh.
AlarmUtils.cancelAlarm(getContext(), alarm, true);
}
// TOneverDO: AlarmUtils.cancelAlarm() otherwise it will be called twice // TOneverDO: AlarmUtils.cancelAlarm() otherwise it will be called twice
/* /*
AlarmUtils.cancelAlarm(getContext(), getAlarm()); AlarmUtils.cancelAlarm(getContext(), getAlarm());
@ -122,17 +128,10 @@ public class AlarmViewHolder extends BaseViewHolder<Alarm> implements AlarmCount
if (alarm.isEnabled()) { if (alarm.isEnabled()) {
// TODO: On Moto X, upcoming notification doesn't post immediately // TODO: On Moto X, upcoming notification doesn't post immediately
AlarmUtils.scheduleAlarm(getContext(), alarm, true); AlarmUtils.scheduleAlarm(getContext(), alarm, true);
// TODO: We don't have to manually bind these if we update the alarm via the db, AlarmUtils.save(getContext(), alarm);
// because that would trigger the loader to reload the dataset and hence the
// corresponding VH is rebound.
bindCountdown(true, alarm.ringsIn());
bindDismissButton(alarm);
} else { } else {
AlarmUtils.cancelAlarm(getContext(), alarm, true); // saves repo AlarmUtils.cancelAlarm(getContext(), alarm, true);
// TODO: Remove these, cancelAlarm will prompt update call to the db, so all VHs will // cancelAlarm() already calls save() for you.
// be rebound.
bindCountdown(false, -1);
bindDismissButton(false, "");
} }
mSwitch.setPressed(false); // clear the pressed focus, esp. if setPressed(true) was called manually mSwitch.setPressed(false); // clear the pressed focus, esp. if setPressed(true) was called manually
} }