Remove notification when habit is deleted

This commit is contained in:
2016-09-11 11:35:32 -04:00
parent 1a89bb02be
commit a998a62cdb
2 changed files with 27 additions and 13 deletions

View File

@@ -42,25 +42,30 @@ 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
public void undo()
{
throw new UnsupportedOperationException();
}
@Override @Override
public Integer getExecuteStringId() public Integer getExecuteStringId()
{ {
return R.string.toast_habit_deleted; return R.string.toast_habit_deleted;
} }
public List<Habit> getHabits()
{
return new LinkedList<>(habits);
}
@Override @Override
public Integer getUndoStringId() public Integer getUndoStringId()
{ {
return R.string.toast_habit_restored; return R.string.toast_habit_restored;
} }
@Override
public void undo()
{
throw new UnsupportedOperationException();
}
} }

View File

@@ -88,16 +88,25 @@ 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 toggleCommand = ToggleRepetitionCommand toggleCmd =
(ToggleRepetitionCommand) command; (ToggleRepetitionCommand) command;
Habit habit = toggleCommand.getHabit(); Habit habit = toggleCmd.getHabit();
if (habit.getCheckmarks().getTodayValue() != Checkmark.UNCHECKED) if (habit.getCheckmarks().getTodayValue() != Checkmark.UNCHECKED)
cancel(habit); cancel(habit);
} }
if (command instanceof DeleteHabitsCommand)
{
DeleteHabitsCommand deleteCommand = (DeleteHabitsCommand) command;
List<Habit> deleted = deleteCommand.getHabits();
for(Habit habit : deleted)
cancel(habit);
}
}
@Override @Override
public void onNotificationsChanged() public void onNotificationsChanged()
{ {