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 distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists 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) { private fun onSettingsResult(resultCode: Int) {
val liist = habitList.getFiltered(HabitMatcher(true,true,true)) //val liist = habitList.getFiltered(HabitMatcher(true,true,true))
when (resultCode) { when (resultCode) {
RESULT_IMPORT_DATA -> showImportScreen() RESULT_IMPORT_DATA -> showImportScreen()
RESULT_EXPORT_CSV -> behavior.get().onExportCSV() RESULT_EXPORT_CSV -> behavior.get().onExportCSV()
RESULT_EXPORT_DB -> onExportDB() RESULT_EXPORT_DB -> onExportDB()
RESULT_BUG_REPORT -> behavior.get().onSendBugReport() RESULT_BUG_REPORT -> behavior.get().onSendBugReport()
RESULT_REPAIR_DB -> behavior.get().onRepairDB() 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); this.selected = new LinkedList<>(selected);
} }
public ResetHabitsCommand(@NonNull HabitList habitList) {
this.habitList = habitList;
selected = null;
}
@Override @Override
public void execute() public void execute()
{ {
for (Habit h : selected) { if (selected != null) {
RepetitionList repetitionList = h.getRepetitions(); for (Habit h : selected) {
repetitionList.removeAll(); RepetitionList repetitionList = h.getRepetitions();
repetitionList.removeAll();
}
} else {
for (Habit h : habitList) {
RepetitionList repetitionList = h.getRepetitions();
repetitionList.removeAll();
}
} }
} }
public List<Habit> getSelected() public List<Habit> getSelected()
{ {
return Collections.unmodifiableList(selected); return Collections.unmodifiableList(selected);
@ -38,8 +52,37 @@ public class ResetHabitsCommand extends Command
@NonNull @NonNull
@Override @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 @Override
public void undo() { throw new UnsupportedOperationException();} public void undo() { throw new UnsupportedOperationException();}
} }

@ -128,11 +128,11 @@ public class ListHabitsBehavior
} }
public void onResetHabits() public void onResetHabits()
{ {
taskRunner.execute(() -> //ResetHabitsCommand rst = new ResetHabitsCommand(habitList);
{ //rst.execute();
habitList.repair(); commandRunner.execute(new ResetHabitsCommand(habitList),
screen.showMessage(Message.DATABASE_REPAIRED); null);
}); habitList.repair();
} }
public void onSendBugReport() 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() public void onEditHabits()
{ {
screen.showEditHabitsScreen(adapter.getSelected()); screen.showEditHabitsScreen(adapter.getSelected());
@ -129,11 +139,6 @@ public class ListHabitsSelectionMenuBehavior
void performRemove(List<Habit> selected); void performRemove(List<Habit> selected);
} }
public void onResetHabits()
{
ResetHabitsCommand command = new ResetHabitsCommand(habitList, adapter.getSelected());
command.execute();
}
public interface Screen public interface Screen
{ {

Loading…
Cancel
Save