mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Make filtered MemoryHabitLists update automatically
This commit is contained in:
@@ -37,6 +37,8 @@ import java.util.*;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.core.IsEqual.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@SuppressWarnings("JavaDoc")
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@@ -52,6 +54,8 @@ public class SQLiteHabitListTest extends BaseAndroidTest
|
||||
|
||||
private SQLiteRepository<HabitRecord> repository;
|
||||
|
||||
private ModelObservable.Listener listener;
|
||||
|
||||
@Override
|
||||
public void setUp()
|
||||
{
|
||||
@@ -78,6 +82,16 @@ public class SQLiteHabitListTest extends BaseAndroidTest
|
||||
}
|
||||
|
||||
habitList.reload();
|
||||
|
||||
listener = mock(ModelObservable.Listener.class);
|
||||
habitList.getObservable().addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
habitList.getObservable().removeListener(listener);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,6 +99,8 @@ public class SQLiteHabitListTest extends BaseAndroidTest
|
||||
{
|
||||
Habit habit = modelFactory.buildHabit();
|
||||
habitList.add(habit);
|
||||
verify(listener).onModelChange();
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
habitList.add(habit);
|
||||
}
|
||||
|
||||
@@ -92,6 +92,8 @@ public class SQLiteHabitList extends HabitList
|
||||
record.copyFrom(habit);
|
||||
record.position = list.indexOf(habit);
|
||||
repository.save(record);
|
||||
|
||||
getObservable().notifyListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -177,20 +179,21 @@ public class SQLiteHabitList extends HabitList
|
||||
repository.remove(record);
|
||||
});
|
||||
rebuildOrder();
|
||||
getObservable().notifyListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeAll()
|
||||
{
|
||||
loadRecords();
|
||||
list.removeAll();
|
||||
SQLiteDatabase db = DatabaseUtils.openDatabase();
|
||||
db.execSQL("delete from habits");
|
||||
db.execSQL("delete from repetitions");
|
||||
getObservable().notifyListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void reorder(Habit from, Habit to)
|
||||
public synchronized void reorder(@NonNull Habit from, @NonNull Habit to)
|
||||
{
|
||||
loadRecords();
|
||||
list.reorder(from, to);
|
||||
@@ -222,6 +225,7 @@ public class SQLiteHabitList extends HabitList
|
||||
fromRecord.position = toPos;
|
||||
repository.save(fromRecord);
|
||||
update(from);
|
||||
|
||||
getObservable().notifyListeners();
|
||||
}
|
||||
|
||||
@@ -251,6 +255,8 @@ public class SQLiteHabitList extends HabitList
|
||||
record.copyFrom(h);
|
||||
repository.save(record);
|
||||
}
|
||||
|
||||
getObservable().notifyListeners();
|
||||
}
|
||||
|
||||
public void reload()
|
||||
|
||||
Reference in New Issue
Block a user