Fix app crash on habit deletion when sorted not manually. (#874)

pull/884/head
engineering4good 5 years ago committed by GitHub
parent 419d2faa78
commit fe59565ded
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -131,7 +131,6 @@ 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))
list.remove(h) list.remove(h)
val record = repository.find( val record = repository.find(
h.id!! h.id!!
@ -140,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()
} }

@ -157,6 +157,20 @@ 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))
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
val h = habitList.getById(2)
habitList.remove(h!!)
assertThat(habitList.indexOf(h), equalTo(-1))
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