mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Remove ModelObservable from RepetitionList
This commit is contained in:
@@ -30,13 +30,9 @@ public abstract class RepetitionList
|
|||||||
@NonNull
|
@NonNull
|
||||||
protected final Habit habit;
|
protected final Habit habit;
|
||||||
|
|
||||||
@NonNull
|
|
||||||
protected final ModelObservable observable;
|
|
||||||
|
|
||||||
public RepetitionList(@NonNull Habit habit)
|
public RepetitionList(@NonNull Habit habit)
|
||||||
{
|
{
|
||||||
this.habit = habit;
|
this.habit = habit;
|
||||||
this.observable = new ModelObservable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,12 +82,6 @@ public abstract class RepetitionList
|
|||||||
return check.getValue();
|
return check.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public ModelObservable getObservable()
|
|
||||||
{
|
|
||||||
return observable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the oldest checkmark in the list.
|
* Returns the oldest checkmark in the list.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ public class MemoryRepetitionList extends RepetitionList
|
|||||||
public void add(Entry repetition)
|
public void add(Entry repetition)
|
||||||
{
|
{
|
||||||
list.add(repetition);
|
list.add(repetition);
|
||||||
observable.notifyListeners();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -115,7 +114,6 @@ public class MemoryRepetitionList extends RepetitionList
|
|||||||
public void remove(@NonNull Entry repetition)
|
public void remove(@NonNull Entry repetition)
|
||||||
{
|
{
|
||||||
list.remove(repetition);
|
list.remove(repetition);
|
||||||
observable.notifyListeners();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -132,6 +130,5 @@ public class MemoryRepetitionList extends RepetitionList
|
|||||||
public void removeAll()
|
public void removeAll()
|
||||||
{
|
{
|
||||||
list.clear();
|
list.clear();
|
||||||
getObservable().notifyListeners();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ public class SQLiteRepetitionList extends RepetitionList
|
|||||||
record.habit_id = habit.getId();
|
record.habit_id = habit.getId();
|
||||||
record.copyFrom(entry);
|
record.copyFrom(entry);
|
||||||
repository.save(record);
|
repository.save(record);
|
||||||
observable.notifyListeners();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -116,7 +115,6 @@ public class SQLiteRepetitionList extends RepetitionList
|
|||||||
repository.execSQL(
|
repository.execSQL(
|
||||||
"delete from repetitions where habit = ? and timestamp = ?",
|
"delete from repetitions where habit = ? and timestamp = ?",
|
||||||
habit.getId(), entry.getTimestamp().getUnixTime());
|
habit.getId(), entry.getTimestamp().getUnixTime());
|
||||||
observable.notifyListeners();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAll()
|
public void removeAll()
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import static java.util.Calendar.*;
|
|||||||
import static org.hamcrest.MatcherAssert.*;
|
import static org.hamcrest.MatcherAssert.*;
|
||||||
import static org.hamcrest.core.IsEqual.*;
|
import static org.hamcrest.core.IsEqual.*;
|
||||||
import static org.isoron.uhabits.core.models.Entry.*;
|
import static org.isoron.uhabits.core.models.Entry.*;
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
public class RepetitionListTest extends BaseUnitTest
|
public class RepetitionListTest extends BaseUnitTest
|
||||||
{
|
{
|
||||||
@@ -45,9 +44,6 @@ public class RepetitionListTest extends BaseUnitTest
|
|||||||
|
|
||||||
private long day;
|
private long day;
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private ModelObservable.Listener listener;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception
|
public void setUp() throws Exception
|
||||||
@@ -63,10 +59,6 @@ public class RepetitionListTest extends BaseUnitTest
|
|||||||
reps.setValue(today, YES_MANUAL);
|
reps.setValue(today, YES_MANUAL);
|
||||||
reps.setValue(today.minus(7), YES_MANUAL);
|
reps.setValue(today.minus(7), YES_MANUAL);
|
||||||
reps.setValue(today.minus(5), YES_MANUAL);
|
reps.setValue(today.minus(5), YES_MANUAL);
|
||||||
|
|
||||||
listener = mock(ModelObservable.Listener.class);
|
|
||||||
reps.getObservable().addListener(listener);
|
|
||||||
reset(listener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -147,18 +139,12 @@ public class RepetitionListTest extends BaseUnitTest
|
|||||||
assertThat(reps.getValue(today), equalTo(YES_MANUAL));
|
assertThat(reps.getValue(today), equalTo(YES_MANUAL));
|
||||||
reps.setValue(today, NO);
|
reps.setValue(today, NO);
|
||||||
assertThat(reps.getValue(today), equalTo(NO));
|
assertThat(reps.getValue(today), equalTo(NO));
|
||||||
verify(listener, times(2)).onModelChange();
|
|
||||||
reset(listener);
|
|
||||||
|
|
||||||
habit.setType(Habit.NUMBER_HABIT);
|
habit.setType(Habit.NUMBER_HABIT);
|
||||||
reps.setValue(today, 100);
|
reps.setValue(today, 100);
|
||||||
assertThat(reps.getValue(today), equalTo(100));
|
assertThat(reps.getValue(today), equalTo(100));
|
||||||
verify(listener, times(2)).onModelChange();
|
|
||||||
reset(listener);
|
|
||||||
|
|
||||||
reps.setValue(today, 500);
|
reps.setValue(today, 500);
|
||||||
assertThat(reps.getValue(today), equalTo(500));
|
assertThat(reps.getValue(today), equalTo(500));
|
||||||
verify(listener, times(2)).onModelChange();
|
|
||||||
reset(listener);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user