mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18: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 component = app.component
|
||||||
val parser = app.component.intentParser
|
val parser = app.component.intentParser
|
||||||
data = parser.parseCheckmarkIntent(intent)
|
data = parser.parseCheckmarkIntent(intent)
|
||||||
behavior = WidgetBehavior(component.commandRunner, component.notificationTray)
|
behavior = WidgetBehavior(component.habitList,
|
||||||
|
component.commandRunner,
|
||||||
|
component.notificationTray)
|
||||||
widgetUpdater = component.widgetUpdater
|
widgetUpdater = component.widgetUpdater
|
||||||
showNumberSelector(this)
|
showNumberSelector(this)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class WidgetControllerTest extends BaseAndroidJVMTest
|
|||||||
commandRunner = mock(CommandRunner.class);
|
commandRunner = mock(CommandRunner.class);
|
||||||
notificationTray = mock(NotificationTray.class);
|
notificationTray = mock(NotificationTray.class);
|
||||||
controller =
|
controller =
|
||||||
new WidgetBehavior(commandRunner, notificationTray);
|
new WidgetBehavior(habitList, commandRunner, notificationTray);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public class CreateRepetitionCommand extends Command
|
|||||||
@NonNull
|
@NonNull
|
||||||
final Habit habit;
|
final Habit habit;
|
||||||
|
|
||||||
|
private HabitList habitList;
|
||||||
final Timestamp timestamp;
|
final Timestamp timestamp;
|
||||||
|
|
||||||
final int value;
|
final int value;
|
||||||
@@ -41,10 +42,12 @@ public class CreateRepetitionCommand extends Command
|
|||||||
@Nullable
|
@Nullable
|
||||||
Repetition newRep;
|
Repetition newRep;
|
||||||
|
|
||||||
public CreateRepetitionCommand(@NonNull Habit habit,
|
public CreateRepetitionCommand(@NonNull HabitList habitList,
|
||||||
|
@NonNull Habit habit,
|
||||||
Timestamp timestamp,
|
Timestamp timestamp,
|
||||||
int value)
|
int value)
|
||||||
{
|
{
|
||||||
|
this.habitList = habitList;
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
this.habit = habit;
|
this.habit = habit;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
@@ -65,6 +68,7 @@ public class CreateRepetitionCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
habit.invalidateNewerThan(timestamp);
|
habit.invalidateNewerThan(timestamp);
|
||||||
|
habitList.update(habit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -120,7 +124,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());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -152,7 +152,7 @@ public class ListHabitsBehavior
|
|||||||
public void onToggle(@NonNull Habit habit, Timestamp timestamp, int value)
|
public void onToggle(@NonNull Habit habit, Timestamp timestamp, int value)
|
||||||
{
|
{
|
||||||
commandRunner.execute(
|
commandRunner.execute(
|
||||||
new CreateRepetitionCommand(habit, timestamp, value),
|
new CreateRepetitionCommand(habitList, habit, timestamp, value),
|
||||||
habit.getId());
|
habit.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class ShowHabitBehavior
|
|||||||
public void onToggleCheckmark(Timestamp timestamp, int value)
|
public void onToggleCheckmark(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
|
||||||
|
|||||||
@@ -29,15 +29,19 @@ import javax.inject.*;
|
|||||||
|
|
||||||
public class WidgetBehavior
|
public class WidgetBehavior
|
||||||
{
|
{
|
||||||
|
private HabitList habitList;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CommandRunner commandRunner;
|
private final CommandRunner commandRunner;
|
||||||
|
|
||||||
private NotificationTray notificationTray;
|
private NotificationTray notificationTray;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public WidgetBehavior(@NonNull CommandRunner commandRunner,
|
public WidgetBehavior(@NonNull HabitList habitList,
|
||||||
|
@NonNull CommandRunner commandRunner,
|
||||||
@NonNull NotificationTray notificationTray)
|
@NonNull NotificationTray notificationTray)
|
||||||
{
|
{
|
||||||
|
this.habitList = habitList;
|
||||||
this.commandRunner = commandRunner;
|
this.commandRunner = commandRunner;
|
||||||
this.notificationTray = notificationTray;
|
this.notificationTray = notificationTray;
|
||||||
}
|
}
|
||||||
@@ -68,13 +72,13 @@ public class WidgetBehavior
|
|||||||
private void performToggle(@NonNull Habit habit, Timestamp timestamp, int value)
|
private void performToggle(@NonNull Habit habit, Timestamp timestamp, int value)
|
||||||
{
|
{
|
||||||
commandRunner.execute(
|
commandRunner.execute(
|
||||||
new CreateRepetitionCommand(habit, timestamp, value),
|
new CreateRepetitionCommand(habitList, habit, timestamp, value),
|
||||||
habit.getId());
|
habit.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class HabitCardListCacheTest extends BaseUnitTest
|
|||||||
{
|
{
|
||||||
Habit h2 = habitList.getByPosition(2);
|
Habit h2 = habitList.getByPosition(2);
|
||||||
Timestamp today = DateUtils.getToday();
|
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).onItemChanged(2);
|
||||||
verify(listener).onRefreshFinished();
|
verify(listener).onRefreshFinished();
|
||||||
verifyNoMoreInteractions(listener);
|
verifyNoMoreInteractions(listener);
|
||||||
|
|||||||
Reference in New Issue
Block a user