mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Remove calls to Repetition.add and Repetition.remove
This commit is contained in:
@@ -128,8 +128,7 @@ public class HabitFixtures
|
||||
Timestamp timestamp = DateUtils.getToday();
|
||||
for (int value : LONG_NUMERICAL_HABIT_CHECKS)
|
||||
{
|
||||
Repetition r = new Repetition(timestamp, value);
|
||||
habit.getRepetitions().add(r);
|
||||
habit.getRepetitions().setValue(timestamp, value);
|
||||
timestamp = timestamp.minus(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPi
|
||||
}
|
||||
|
||||
override fun onNumberPicked(newValue: Double) {
|
||||
behavior.setNumericValue(data.habit, data.timestamp, (newValue * 1000).toInt())
|
||||
behavior.setValue(data.habit, data.timestamp, (newValue * 1000).toInt())
|
||||
widgetUpdater.updateWidgets()
|
||||
finish()
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import androidx.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Command to toggle a repetition.
|
||||
*/
|
||||
@@ -31,20 +33,19 @@ public class CreateRepetitionCommand extends Command
|
||||
@NonNull
|
||||
final Habit habit;
|
||||
|
||||
private HabitList habitList;
|
||||
@NonNull
|
||||
final HabitList habitList;
|
||||
|
||||
@NonNull
|
||||
final Timestamp timestamp;
|
||||
|
||||
final int value;
|
||||
|
||||
@Nullable
|
||||
Repetition previousRep;
|
||||
|
||||
@Nullable
|
||||
Repetition newRep;
|
||||
int previousValue;
|
||||
|
||||
public CreateRepetitionCommand(@NonNull HabitList habitList,
|
||||
@NonNull Habit habit,
|
||||
Timestamp timestamp,
|
||||
@NonNull Timestamp timestamp,
|
||||
int value)
|
||||
{
|
||||
this.habitList = habitList;
|
||||
@@ -57,18 +58,8 @@ public class CreateRepetitionCommand extends Command
|
||||
public void execute()
|
||||
{
|
||||
RepetitionList reps = habit.getRepetitions();
|
||||
|
||||
previousRep = reps.getByTimestamp(timestamp);
|
||||
if (previousRep != null) reps.remove(previousRep);
|
||||
|
||||
if (value > 0)
|
||||
{
|
||||
newRep = new Repetition(timestamp, value);
|
||||
reps.add(newRep);
|
||||
}
|
||||
|
||||
habit.invalidateNewerThan(timestamp);
|
||||
habitList.update(habit);
|
||||
previousValue = reps.getValue(timestamp);
|
||||
reps.setValue(timestamp, value);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -87,9 +78,7 @@ public class CreateRepetitionCommand extends Command
|
||||
@Override
|
||||
public void undo()
|
||||
{
|
||||
if(newRep != null) habit.getRepetitions().remove(newRep);
|
||||
if (previousRep != null) habit.getRepetitions().add(previousRep);
|
||||
habit.invalidateNewerThan(timestamp);
|
||||
habit.getRepetitions().setValue(timestamp, previousValue);
|
||||
}
|
||||
|
||||
public static class Record
|
||||
@@ -129,4 +118,34 @@ public class CreateRepetitionCommand extends Command
|
||||
return command;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CreateRepetitionCommand that = (CreateRepetitionCommand) o;
|
||||
return value == that.value &&
|
||||
habit.equals(that.habit) &&
|
||||
habitList.equals(that.habitList) &&
|
||||
timestamp.equals(that.timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(habit, habitList, timestamp, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "CreateRepetitionCommand{" +
|
||||
"habit=" + habit +
|
||||
", habitList=" + habitList +
|
||||
", timestamp=" + timestamp +
|
||||
", value=" + value +
|
||||
", previousValue=" + previousValue +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public class HabitFixtures
|
||||
for (int i = 0; i < times.length; i++)
|
||||
{
|
||||
Timestamp timestamp = today.minus(times[i]);
|
||||
habit.getRepetitions().add(new Repetition(timestamp, values[i]));
|
||||
habit.getRepetitions().setValue(timestamp, values[i]);
|
||||
}
|
||||
|
||||
return habit;
|
||||
@@ -125,7 +125,7 @@ public class HabitFixtures
|
||||
for (int i = 0; i < times.length; i++)
|
||||
{
|
||||
Timestamp timestamp = reference.minus(times[i]);
|
||||
habit.getRepetitions().add(new Repetition(timestamp, values[i]));
|
||||
habit.getRepetitions().setValue(timestamp, values[i]);
|
||||
}
|
||||
|
||||
return habit;
|
||||
|
||||
@@ -114,7 +114,7 @@ public class ShowHabitMenuBehavior
|
||||
if (habit.isNumerical())
|
||||
value = (int) (1000 + 250 * random.nextGaussian() * strength / 100) * 1000;
|
||||
|
||||
habit.getRepetitions().add(new Repetition(DateUtils.getToday().minus(i), value));
|
||||
habit.getRepetitions().setValue(DateUtils.getToday().minus(i), value);
|
||||
}
|
||||
|
||||
habit.invalidateNewerThan(Timestamp.ZERO);
|
||||
|
||||
Reference in New Issue
Block a user