Fixed habit list refresh problem

added a pop-app message when habit reser is executed and toggled off deleted repetitions
pull/592/head
Febon 5 years ago
parent 7b4976e990
commit 74e44e9843

@ -225,6 +225,7 @@ class ListHabitsScreen
is DeleteHabitsCommand -> return R.string.toast_habit_deleted is DeleteHabitsCommand -> return R.string.toast_habit_deleted
is EditHabitCommand -> return R.string.toast_habit_changed is EditHabitCommand -> return R.string.toast_habit_changed
is UnarchiveHabitsCommand -> return R.string.toast_habit_unarchived is UnarchiveHabitsCommand -> return R.string.toast_habit_unarchived
is ResetHabitsCommand -> return R.string.toast_habit_reset
else -> return null else -> return null
} }
} }

@ -39,6 +39,7 @@
<string name="toast_habit_changed_back">Habit changed back</string> <string name="toast_habit_changed_back">Habit changed back</string>
<string name="toast_habit_archived">Habits archived</string> <string name="toast_habit_archived">Habits archived</string>
<string name="toast_habit_unarchived">Habits unarchived</string> <string name="toast_habit_unarchived">Habits unarchived</string>
<string name="toast_habit_reset">Habits reset</string>
<string name="title_activity_show_habit" translatable="false"/> <string name="title_activity_show_habit" translatable="false"/>
<string name="overview">Overview</string> <string name="overview">Overview</string>

@ -79,6 +79,9 @@ public class CommandParser
if (event.equals("Unarchive")) return gson if (event.equals("Unarchive")) return gson
.fromJson(json, UnarchiveHabitsCommand.Record.class) .fromJson(json, UnarchiveHabitsCommand.Record.class)
.toCommand(habitList); .toCommand(habitList);
if(event.equals("HabitReset")) return gson
.fromJson(json, ResetHabitsCommand.Record.class)
.toCommand(habitList);
throw new IllegalStateException("Unknown command"); throw new IllegalStateException("Unknown command");
} }

@ -4,6 +4,7 @@ import androidx.annotation.NonNull;
import org.isoron.uhabits.core.models.Habit; import org.isoron.uhabits.core.models.Habit;
import org.isoron.uhabits.core.models.HabitList; import org.isoron.uhabits.core.models.HabitList;
import org.isoron.uhabits.core.models.Repetition;
import org.isoron.uhabits.core.models.RepetitionList; import org.isoron.uhabits.core.models.RepetitionList;
import java.util.Collections; import java.util.Collections;
@ -34,12 +35,18 @@ public class ResetHabitsCommand extends Command
if (selected != null) { if (selected != null) {
for (Habit h : selected) { for (Habit h : selected) {
RepetitionList repetitionList = h.getRepetitions(); RepetitionList repetitionList = h.getRepetitions();
repetitionList.removeAll(); Repetition rep;
while(repetitionList.getTotalCount() != 0) {
rep = repetitionList.getOldest();
repetitionList.toggle(rep.getTimestamp());
repetitionList.remove(rep);
} }
}
habitList.update(selected);
} else { } else {
for (Habit h : habitList) { for (Habit h : habitList) {
RepetitionList repetitionList = h.getRepetitions(); h.getRepetitions().removeAll();
repetitionList.removeAll(); habitList.update(h);
} }
} }
} }

@ -26,7 +26,6 @@ import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.preferences.*; import org.isoron.uhabits.core.preferences.*;
import org.isoron.uhabits.core.tasks.*; import org.isoron.uhabits.core.tasks.*;
import org.isoron.uhabits.core.utils.*; import org.isoron.uhabits.core.utils.*;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
@ -128,11 +127,12 @@ public class ListHabitsBehavior
} }
public void onResetHabits() public void onResetHabits()
{ {
//ResetHabitsCommand rst = new ResetHabitsCommand(habitList);
//rst.execute();
commandRunner.execute(new ResetHabitsCommand(habitList), commandRunner.execute(new ResetHabitsCommand(habitList),
null); null);
habitList.repair(); habitList.repair();
HabitCardListCache hclc = new HabitCardListCache(habitList, commandRunner, taskRunner);
hclc.refreshAllHabits();
} }
public void onSendBugReport() public void onSendBugReport()
{ {

Loading…
Cancel
Save