Add reordering tests for SQLiteHabitList

This commit is contained in:
2017-06-23 09:29:19 -04:00
parent 5d9563b9d8
commit 33f7acc9ca
2 changed files with 46 additions and 13 deletions

View File

@@ -201,24 +201,21 @@ public class SQLiteHabitList extends HabitList
if (toRecord == null)
throw new RuntimeException("habit not in database");
Integer fromPos = fromRecord.position;
Integer toPos = toRecord.position;
if (toPos < fromPos)
if (toRecord.position < fromRecord.position)
{
repository.execSQL("update habits set position = position + 1 " +
"where position >= ? and position < ?",
toPos, fromPos);
toRecord.position, fromRecord.position);
}
else
{
repository.execSQL("update habits set position = position - 1 " +
"where position > ? and position <= ?",
fromPos, toPos);
fromRecord.position, toRecord.position);
}
fromRecord.position = toPos;
fromRecord.position = toRecord.position;
repository.save(fromRecord);
update(from);
getObservable().notifyListeners();
}