mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Merge branch 'add-delete-button-to-stats' of git://github.com/derebaba/uhabits into pull/delete-button
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ShowHabitMenuBehaviorTest extends BaseUnitTest
|
||||
|
||||
habit = fixtures.createShortHabit();
|
||||
menu = new ShowHabitMenuBehavior(habitList, habit, taskRunner, screen,
|
||||
system);
|
||||
system, commandRunner);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user