Fix CreateRepetitionCommand not updating habit list

pull/610/head
KristianTashkov 5 years ago
parent 9284fc76d0
commit 2de0c0be47

@ -28,6 +28,9 @@ import org.isoron.uhabits.core.models.*;
*/ */
public class CreateRepetitionCommand extends Command public class CreateRepetitionCommand extends Command
{ {
@NonNull
final HabitList list;
@NonNull @NonNull
final Habit habit; final Habit habit;
@ -41,10 +44,12 @@ public class CreateRepetitionCommand extends Command
@Nullable @Nullable
Repetition newRep; Repetition newRep;
public CreateRepetitionCommand(@NonNull Habit habit, public CreateRepetitionCommand(@NonNull HabitList list,
@NonNull Habit habit,
Timestamp timestamp, Timestamp timestamp,
int value) int value)
{ {
this.list = list;
this.timestamp = timestamp; this.timestamp = timestamp;
this.habit = habit; this.habit = habit;
this.value = value; this.value = value;
@ -65,6 +70,7 @@ public class CreateRepetitionCommand extends Command
} }
habit.invalidateNewerThan(timestamp); habit.invalidateNewerThan(timestamp);
list.update(habit);
} }
@NonNull @NonNull
@ -88,6 +94,7 @@ public class CreateRepetitionCommand extends Command
if (previousRep != null) habit.getRepetitions().add(previousRep); if (previousRep != null) habit.getRepetitions().add(previousRep);
habit.invalidateNewerThan(timestamp); habit.invalidateNewerThan(timestamp);
list.update(habit);
} }
public static class Record public static class Record
@ -122,7 +129,7 @@ public class CreateRepetitionCommand extends Command
CreateRepetitionCommand command; CreateRepetitionCommand command;
command = new CreateRepetitionCommand( command = new CreateRepetitionCommand(
h, new Timestamp(repTimestamp), value); habitList, h, new Timestamp(repTimestamp), value);
command.setId(id); command.setId(id);
return command; return command;
} }

@ -87,7 +87,7 @@ public class ListHabitsBehavior
{ {
newValue = Math.round(newValue * 1000); newValue = Math.round(newValue * 1000);
commandRunner.execute( commandRunner.execute(
new CreateRepetitionCommand(habit, timestamp, (int) newValue), new CreateRepetitionCommand(habitList, habit, timestamp, (int) newValue),
habit.getId()); habit.getId());
}); });
} }
@ -163,7 +163,7 @@ public class ListHabitsBehavior
screen.showCheckmarkOptions(habit.getName(), timestamp, oldValue, newValue -> screen.showCheckmarkOptions(habit.getName(), timestamp, oldValue, newValue ->
{ {
commandRunner.execute( commandRunner.execute(
new CreateRepetitionCommand(habit, timestamp, newValue), new CreateRepetitionCommand(habitList, habit, timestamp, newValue),
habit.getId()); habit.getId());
}); });
} }

@ -65,7 +65,7 @@ public class ShowHabitBehavior
public void onCreateRepetition(Timestamp timestamp, int value) public void onCreateRepetition(Timestamp timestamp, int value)
{ {
commandRunner.execute( commandRunner.execute(
new CreateRepetitionCommand(habit, timestamp, value), null); new CreateRepetitionCommand(habitList, habit, timestamp, value), null);
} }
public interface Screen public interface Screen

@ -76,7 +76,7 @@ public class WidgetBehavior
public void setNumericValue(@NonNull Habit habit, Timestamp timestamp, int newValue) { public void setNumericValue(@NonNull Habit habit, Timestamp timestamp, int newValue) {
commandRunner.execute( commandRunner.execute(
new CreateRepetitionCommand(habit, timestamp, newValue), new CreateRepetitionCommand(habitList, habit, timestamp, newValue),
habit.getId()); habit.getId());
} }

@ -96,7 +96,7 @@ public class CommandParserTest extends BaseUnitTest
public void testDecodeCreateRepCommand() throws JSONException public void testDecodeCreateRepCommand() throws JSONException
{ {
CreateRepetitionCommand original, decoded; CreateRepetitionCommand original, decoded;
original = new CreateRepetitionCommand(habit, Timestamp.ZERO.plus(100), 5); original = new CreateRepetitionCommand(habitList, habit, Timestamp.ZERO.plus(100), 5);
decoded = (CreateRepetitionCommand) parser.parse(original.toJson()); decoded = (CreateRepetitionCommand) parser.parse(original.toJson());
MatcherAssert.assertThat(decoded.getId(), equalTo(original.getId())); MatcherAssert.assertThat(decoded.getId(), equalTo(original.getId()));

@ -47,7 +47,7 @@ public class CreateRepetitionCommandTest extends BaseUnitTest
habitList.add(habit); habitList.add(habit);
today = DateUtils.getToday(); today = DateUtils.getToday();
command = new CreateRepetitionCommand(habit, today, 100); command = new CreateRepetitionCommand(habitList, habit, today, 100);
} }
@Test @Test

Loading…
Cancel
Save