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 @Synchronized
override fun remove(h: Habit) { override fun remove(h: Habit) {
loadRecords() loadRecords()
reorder(h, list.getByPosition(size() - 1)) 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!!

@ -157,6 +157,14 @@ class SQLiteHabitListTest : BaseUnitTest() {
val h = habitList.getById(2) val h = habitList.getById(2)
habitList.remove(h!!) habitList.remove(h!!)
assertThat(habitList.indexOf(h), equalTo(-1)) 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) var rec = repository.find(2L)
assertNull(rec) assertNull(rec)
rec = repository.find(3L)!! rec = repository.find(3L)!!

Loading…
Cancel
Save