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

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

Loading…
Cancel
Save