Add the function of the reset button in the settings menu

Change some of the code to follow the current standard.
pull/592/head
pkorove 5 years ago
parent 91678b83e1
commit 7b4976e990

@ -1,5 +1,6 @@
#Mon Jun 01 18:02:11 EEST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

@ -120,14 +120,15 @@ class ListHabitsScreen
}
private fun onSettingsResult(resultCode: Int) {
val liist = habitList.getFiltered(HabitMatcher(true,true,true))
//val liist = habitList.getFiltered(HabitMatcher(true,true,true))
when (resultCode) {
RESULT_IMPORT_DATA -> showImportScreen()
RESULT_EXPORT_CSV -> behavior.get().onExportCSV()
RESULT_EXPORT_DB -> onExportDB()
RESULT_BUG_REPORT -> behavior.get().onSendBugReport()
RESULT_REPAIR_DB -> behavior.get().onRepairDB()
RESET_HABITS -> ResetHabitsCommand(liist, liist.toList()).execute()
RESET_HABITS -> /*ResetHabitsCommand(liist, liist.toList()).execute()*/ behavior.get().onResetHabits()
}
}

@ -23,14 +23,28 @@ public class ResetHabitsCommand extends Command
this.selected = new LinkedList<>(selected);
}
public ResetHabitsCommand(@NonNull HabitList habitList) {
this.habitList = habitList;
selected = null;
}
@Override
public void execute()
{
for (Habit h : selected) {
RepetitionList repetitionList = h.getRepetitions();
repetitionList.removeAll();
if (selected != null) {
for (Habit h : selected) {
RepetitionList repetitionList = h.getRepetitions();
repetitionList.removeAll();
}
} else {
for (Habit h : habitList) {
RepetitionList repetitionList = h.getRepetitions();
repetitionList.removeAll();
}
}
}
public List<Habit> getSelected()
{
return Collections.unmodifiableList(selected);
@ -38,8 +52,37 @@ public class ResetHabitsCommand extends Command
@NonNull
@Override
public Object toRecord() { return null;}
public Object toRecord() {return new Record(this);}
public static class Record {
@NonNull
public String id;
@NonNull
public String event = "ResetHabit";
@NonNull
public List<Long> habits;
public Record(ResetHabitsCommand command) {
id = command.getId();
habits = new LinkedList<>();
for (Habit h : command.selected) {
if (!h.hasId()) throw new RuntimeException("Habit not saved");
habits.add(h.getId());
}
}
public ResetHabitsCommand toCommand(@NonNull HabitList habitList) {
List<Habit> selected = new LinkedList<>();
for (Long id : this.habits) selected.add(habitList.getById(id));
ResetHabitsCommand command;
command = new ResetHabitsCommand(habitList, selected);
command.setId(id);
return command;
}
}
@Override
public void undo() { throw new UnsupportedOperationException();}
}

@ -128,11 +128,11 @@ public class ListHabitsBehavior
}
public void onResetHabits()
{
taskRunner.execute(() ->
{
habitList.repair();
screen.showMessage(Message.DATABASE_REPAIRED);
});
//ResetHabitsCommand rst = new ResetHabitsCommand(habitList);
//rst.execute();
commandRunner.execute(new ResetHabitsCommand(habitList),
null);
habitList.repair();
}
public void onSendBugReport()
{

@ -109,6 +109,16 @@ public class ListHabitsSelectionMenuBehavior
});
}
public void onResetHabits()
{
//ResetHabitsCommand command = new ResetHabitsCommand(habitList, adapter.getSelected());
//command.execute();
List<Habit> selected = adapter.getSelected();
commandRunner.execute(new ResetHabitsCommand(habitList, selected),
null);
adapter.clearSelection();
}
public void onEditHabits()
{
screen.showEditHabitsScreen(adapter.getSelected());
@ -129,11 +139,6 @@ public class ListHabitsSelectionMenuBehavior
void performRemove(List<Habit> selected);
}
public void onResetHabits()
{
ResetHabitsCommand command = new ResetHabitsCommand(habitList, adapter.getSelected());
command.execute();
}
public interface Screen
{

Loading…
Cancel
Save