Rebuild the order after a habit deletion.

pull/874/head
engineering4good 5 years ago
parent 9f15c920be
commit 0daa9e8687

@ -131,9 +131,6 @@ class SQLiteHabitList @Inject constructor(private val modelFactory: ModelFactory
@Synchronized
override fun remove(h: Habit) {
loadRecords()
if (Order.BY_POSITION.equals(list.primaryOrder)) {
reorder(h, list.getByPosition(size() - 1))
}
list.remove(h)
val record = repository.find(
h.id!!
@ -142,6 +139,7 @@ class SQLiteHabitList @Inject constructor(private val modelFactory: ModelFactory
h.originalEntries.clear()
repository.remove(record)
}
rebuildOrder()
observable.notifyListeners()
}

@ -158,12 +158,18 @@ class SQLiteHabitListTest : BaseUnitTest() {
habitList.remove(h!!)
assertThat(habitList.indexOf(h), equalTo(-1))
habitList.add(h)
val primaryOrder = habitList.primaryOrder
var rec = repository.find(2L)
assertNull(rec)
rec = repository.find(3L)!!
assertThat(rec.position, equalTo(1))
}
@Test
fun testRemove_orderByName() {
habitList.primaryOrder = HabitList.Order.BY_NAME_DESC
habitList.remove(h)
val h = habitList.getById(2)
habitList.remove(h!!)
assertThat(habitList.indexOf(h), equalTo(-1))
habitList.primaryOrder = primaryOrder
var rec = repository.find(2L)
assertNull(rec)

Loading…
Cancel
Save