mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
CreateRepetitionCommand: Run update() after executing
This commit is contained in:
@@ -46,7 +46,9 @@ class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPi
|
||||
val component = app.component
|
||||
val parser = app.component.intentParser
|
||||
data = parser.parseCheckmarkIntent(intent)
|
||||
behavior = WidgetBehavior(component.commandRunner, component.notificationTray)
|
||||
behavior = WidgetBehavior(component.habitList,
|
||||
component.commandRunner,
|
||||
component.notificationTray)
|
||||
widgetUpdater = component.widgetUpdater
|
||||
showNumberSelector(this)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class WidgetControllerTest extends BaseAndroidJVMTest
|
||||
commandRunner = mock(CommandRunner.class);
|
||||
notificationTray = mock(NotificationTray.class);
|
||||
controller =
|
||||
new WidgetBehavior(commandRunner, notificationTray);
|
||||
new WidgetBehavior(habitList, commandRunner, notificationTray);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user