mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Fix app crash on habit deletion when sorted not manually. (#874)
This commit is contained in:
@@ -131,7 +131,6 @@ class SQLiteHabitList @Inject constructor(private val modelFactory: ModelFactory
|
||||
@Synchronized
|
||||
override fun remove(h: Habit) {
|
||||
loadRecords()
|
||||
reorder(h, list.getByPosition(size() - 1))
|
||||
list.remove(h)
|
||||
val record = repository.find(
|
||||
h.id!!
|
||||
@@ -140,6 +139,7 @@ class SQLiteHabitList @Inject constructor(private val modelFactory: ModelFactory
|
||||
h.originalEntries.clear()
|
||||
repository.remove(record)
|
||||
}
|
||||
rebuildOrder()
|
||||
observable.notifyListeners()
|
||||
}
|
||||
|
||||
|
||||
@@ -157,6 +157,20 @@ class SQLiteHabitListTest : BaseUnitTest() {
|
||||
val h = habitList.getById(2)
|
||||
habitList.remove(h!!)
|
||||
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)
|
||||
assertNull(rec)
|
||||
rec = repository.find(3L)!!
|
||||
|
||||
Reference in New Issue
Block a user