mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -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
|
@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)!!
|
||||||
|
|||||||
Reference in New Issue
Block a user