Fix app crash on habit deletion when sorted not manually.

pull/874/head
engineering4good 5 years ago
parent 212cc4259b
commit 9f15c920be

@ -131,7 +131,9 @@ 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!!

@ -157,6 +157,14 @@ class SQLiteHabitListTest : BaseUnitTest() {
val h = habitList.getById(2)
habitList.remove(h!!)
assertThat(habitList.indexOf(h), equalTo(-1))
habitList.add(h)
val primaryOrder = habitList.primaryOrder
habitList.primaryOrder = HabitList.Order.BY_NAME_DESC
habitList.remove(h)
assertThat(habitList.indexOf(h), equalTo(-1))
habitList.primaryOrder = primaryOrder
var rec = repository.find(2L)
assertNull(rec)
rec = repository.find(3L)!!

Loading…
Cancel
Save