mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Added delete button to statistics screen
This commit is contained in:
@@ -27,6 +27,7 @@ import org.isoron.uhabits.activities.common.dialogs.*;
|
||||
import org.isoron.uhabits.activities.habits.edit.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.ui.screens.habits.show.*;
|
||||
import org.isoron.uhabits.core.ui.callbacks.OnConfirmedCallback;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@@ -45,6 +46,9 @@ public class ShowHabitScreen extends BaseScreen
|
||||
@NonNull
|
||||
private final EditHabitDialogFactory editHabitDialogFactory;
|
||||
|
||||
@NonNull
|
||||
private final ConfirmDeleteDialogFactory confirmDeleteDialogFactory;
|
||||
|
||||
private final Lazy<ShowHabitBehavior> behavior;
|
||||
|
||||
@Inject
|
||||
@@ -53,10 +57,12 @@ public class ShowHabitScreen extends BaseScreen
|
||||
@NonNull ShowHabitRootView view,
|
||||
@NonNull ShowHabitsMenu menu,
|
||||
@NonNull
|
||||
EditHabitDialogFactory editHabitDialogFactory,
|
||||
EditHabitDialogFactory editHabitDialogFactory,
|
||||
@NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory,
|
||||
@NonNull Lazy<ShowHabitBehavior> behavior)
|
||||
{
|
||||
super(activity);
|
||||
this.confirmDeleteDialogFactory = confirmDeleteDialogFactory;
|
||||
setMenu(menu);
|
||||
setRootView(view);
|
||||
|
||||
@@ -116,6 +122,18 @@ public class ShowHabitScreen extends BaseScreen
|
||||
{
|
||||
case COULD_NOT_EXPORT:
|
||||
showMessage(R.string.could_not_export);
|
||||
case HABIT_DELETED:
|
||||
showMessage(R.string.delete_habits_message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showDeleteConfirmationScreen(OnConfirmedCallback callback) {
|
||||
activity.showDialog(confirmDeleteDialogFactory.create(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endActivity() {
|
||||
activity.finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,10 @@ public class ShowHabitsMenu extends BaseMenu
|
||||
behavior.get().onExportCSV();
|
||||
return true;
|
||||
|
||||
case R.id.action_delete:
|
||||
behavior.get().onDeleteHabit();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,11 @@
|
||||
android:title="@string/export"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_delete"
|
||||
android:title="@string/delete"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_edit_habit"
|
||||
android:icon="?iconEdit"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user