CreateRepetitionCommand: Run update() after executing

This commit is contained in:
2020-08-22 18:10:29 -05:00
parent 09eb8c9f4d
commit f368e43158
9 changed files with 23 additions and 13 deletions

View File

@@ -31,6 +31,7 @@ public class CreateRepetitionCommand extends Command
@NonNull
final Habit habit;
private HabitList habitList;
final Timestamp timestamp;
final int value;
@@ -41,10 +42,12 @@ public class CreateRepetitionCommand extends Command
@Nullable
Repetition newRep;
public CreateRepetitionCommand(@NonNull Habit habit,
public CreateRepetitionCommand(@NonNull HabitList habitList,
@NonNull Habit habit,
Timestamp timestamp,
int value)
{
this.habitList = habitList;
this.timestamp = timestamp;
this.habit = habit;
this.value = value;
@@ -65,6 +68,7 @@ public class CreateRepetitionCommand extends Command
}
habit.invalidateNewerThan(timestamp);
habitList.update(habit);
}
@NonNull
@@ -120,7 +124,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;
}

View File

@@ -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());
});
}
@@ -152,7 +152,7 @@ public class ListHabitsBehavior
public void onToggle(@NonNull Habit habit, Timestamp timestamp, int value)
{
commandRunner.execute(
new CreateRepetitionCommand(habit, timestamp, value),
new CreateRepetitionCommand(habitList, habit, timestamp, value),
habit.getId());
}

View File

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

View File

@@ -29,15 +29,19 @@ import javax.inject.*;
public class WidgetBehavior
{
private HabitList habitList;
@NonNull
private final CommandRunner commandRunner;
private NotificationTray notificationTray;
@Inject
public WidgetBehavior(@NonNull CommandRunner commandRunner,
public WidgetBehavior(@NonNull HabitList habitList,
@NonNull CommandRunner commandRunner,
@NonNull NotificationTray notificationTray)
{
this.habitList = habitList;
this.commandRunner = commandRunner;
this.notificationTray = notificationTray;
}
@@ -68,13 +72,13 @@ public class WidgetBehavior
private void performToggle(@NonNull Habit habit, Timestamp timestamp, int value)
{
commandRunner.execute(
new CreateRepetitionCommand(habit, timestamp, value),
new CreateRepetitionCommand(habitList, habit, timestamp, value),
habit.getId());
}
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());
}

View File

@@ -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()));

View File

@@ -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

View File

@@ -84,7 +84,7 @@ public class HabitCardListCacheTest extends BaseUnitTest
{
Habit h2 = habitList.getByPosition(2);
Timestamp today = DateUtils.getToday();
commandRunner.execute(new CreateRepetitionCommand(h2, today, Checkmark.UNCHECKED), h2.getId());
commandRunner.execute(new CreateRepetitionCommand(habitList, h2, today, Checkmark.UNCHECKED), h2.getId());
verify(listener).onItemChanged(2);
verify(listener).onRefreshFinished();
verifyNoMoreInteractions(listener);