diff --git a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/sqlite/SQLiteHabitList.kt b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/sqlite/SQLiteHabitList.kt index eb08ae3cf..87d05b9ca 100644 --- a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/sqlite/SQLiteHabitList.kt +++ b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/sqlite/SQLiteHabitList.kt @@ -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() } diff --git a/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/models/sqlite/SQLiteHabitListTest.kt b/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/models/sqlite/SQLiteHabitListTest.kt index 07ac72e02..59ee7a585 100644 --- a/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/models/sqlite/SQLiteHabitListTest.kt +++ b/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/models/sqlite/SQLiteHabitListTest.kt @@ -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)!!