Remove notification when habit is deleted

pull/174/head
Alinson S. Xavier 9 years ago
parent 1a89bb02be
commit a998a62cdb

@ -42,20 +42,19 @@ public class DeleteHabitsCommand extends Command
@Override @Override
public void execute() public void execute()
{ {
for(Habit h : habits) for (Habit h : habits)
habitList.remove(h); habitList.remove(h);
} }
@Override @Override
public void undo() public Integer getExecuteStringId()
{ {
throw new UnsupportedOperationException(); return R.string.toast_habit_deleted;
} }
@Override public List<Habit> getHabits()
public Integer getExecuteStringId()
{ {
return R.string.toast_habit_deleted; return new LinkedList<>(habits);
} }
@Override @Override
@ -63,4 +62,10 @@ public class DeleteHabitsCommand extends Command
{ {
return R.string.toast_habit_restored; return R.string.toast_habit_restored;
} }
@Override
public void undo()
{
throw new UnsupportedOperationException();
}
} }

@ -88,14 +88,23 @@ public class NotificationTray
public void onCommandExecuted(@NonNull Command command, public void onCommandExecuted(@NonNull Command command,
@Nullable Long refreshKey) @Nullable Long refreshKey)
{ {
if (!(command instanceof ToggleRepetitionCommand)) return; if (command instanceof ToggleRepetitionCommand)
{
ToggleRepetitionCommand toggleCmd =
(ToggleRepetitionCommand) command;
ToggleRepetitionCommand toggleCommand = Habit habit = toggleCmd.getHabit();
(ToggleRepetitionCommand) command; if (habit.getCheckmarks().getTodayValue() != Checkmark.UNCHECKED)
cancel(habit);
}
Habit habit = toggleCommand.getHabit(); if (command instanceof DeleteHabitsCommand)
if (habit.getCheckmarks().getTodayValue() != Checkmark.UNCHECKED) {
cancel(habit); DeleteHabitsCommand deleteCommand = (DeleteHabitsCommand) command;
List<Habit> deleted = deleteCommand.getHabits();
for(Habit habit : deleted)
cancel(habit);
}
} }
@Override @Override

Loading…
Cancel
Save