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
{
@NonNull
final HabitList list;
@NonNull
final Habit habit;
@ -41,10 +44,12 @@ public class CreateRepetitionCommand extends Command
@Nullable
Repetition newRep;
public CreateRepetitionCommand(@NonNull Habit habit,
public CreateRepetitionCommand(@NonNull HabitList list,
@NonNull Habit habit,
Timestamp timestamp,
int value)
{
this.list = list;
this.timestamp = timestamp;
this.habit = habit;
this.value = value;
@ -65,6 +70,7 @@ public class CreateRepetitionCommand extends Command
}
habit.invalidateNewerThan(timestamp);
list.update(habit);
}
@NonNull
@ -88,6 +94,7 @@ public class CreateRepetitionCommand extends Command
if (previousRep != null) habit.getRepetitions().add(previousRep);
habit.invalidateNewerThan(timestamp);
list.update(habit);
}
public static class Record
@ -122,7 +129,7 @@ public class CreateRepetitionCommand extends Command
CreateRepetitionCommand command;
command = new CreateRepetitionCommand(
h, new Timestamp(repTimestamp), value);
habitList, h, new Timestamp(repTimestamp), value);
command.setId(id);
return command;
}

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

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

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

@ -96,7 +96,7 @@ public class CommandParserTest extends BaseUnitTest
public void testDecodeCreateRepCommand() throws JSONException
{
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());
MatcherAssert.assertThat(decoded.getId(), equalTo(original.getId()));

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

Loading…
Cancel
Save