Added delete button to statistics screen

This commit is contained in:
derebaba
2017-11-02 14:21:27 +03:00
parent 7613e6e1cb
commit 1edd76ae8c
4 changed files with 55 additions and 3 deletions

View File

@@ -21,8 +21,11 @@ package org.isoron.uhabits.core.ui.screens.habits.show;
import android.support.annotation.*;
import org.isoron.uhabits.core.commands.CommandRunner;
import org.isoron.uhabits.core.commands.DeleteHabitsCommand;
import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.tasks.*;
import org.isoron.uhabits.core.ui.callbacks.OnConfirmedCallback;
import java.io.*;
import java.util.*;
@@ -45,18 +48,23 @@ public class ShowHabitMenuBehavior
@NonNull
private System system;
@NonNull
private CommandRunner commandRunner;
@Inject
public ShowHabitMenuBehavior(@NonNull HabitList habitList,
@NonNull Habit habit,
@NonNull TaskRunner taskRunner,
@NonNull Screen screen,
@NonNull System system)
@NonNull System system,
@NonNull CommandRunner commandRunner)
{
this.habitList = habitList;
this.habit = habit;
this.taskRunner = taskRunner;
this.screen = screen;
this.system = system;
this.commandRunner = commandRunner;
}
public void onEditHabit()
@@ -77,9 +85,21 @@ public class ShowHabitMenuBehavior
}));
}
public void onDeleteHabit()
{
List<Habit> selected = Collections.singletonList(habit);
screen.showDeleteConfirmationScreen(() -> {
commandRunner.execute(new DeleteHabitsCommand(habitList, selected),
null);
screen.showMessage(Message.HABIT_DELETED);
screen.endActivity();
});
}
public enum Message
{
COULD_NOT_EXPORT
COULD_NOT_EXPORT, HABIT_DELETED
}
public interface Screen
@@ -89,6 +109,11 @@ public class ShowHabitMenuBehavior
void showMessage(Message m);
void showSendFileScreen(String filename);
void showDeleteConfirmationScreen(
@NonNull OnConfirmedCallback callback);
void endActivity();
}
public interface System