HabitCardListAdapter: Return copy of list of selected items

Previously, HabitCardListAdapter returned a pointer to the list, instead of a
copy. By the time other parts of the application were reading the list, its
contents had already changed. This prevented the user from deleting or
archiving habits.
This commit is contained in:
2021-01-30 10:26:07 -06:00
parent 89bde4c9ae
commit 48c1adb3bb
3 changed files with 28 additions and 24 deletions

View File

@@ -53,7 +53,7 @@ class HabitCardListAdapter @Inject constructor(
ListHabitsSelectionMenuBehavior.Adapter {
val observable: ModelObservable = ModelObservable()
private var listView: HabitCardListView? = null
override val selected: LinkedList<Habit> = LinkedList()
val selected: LinkedList<Habit> = LinkedList()
override fun atMidnight() {
cache.refreshAllHabits()
}
@@ -71,6 +71,10 @@ class HabitCardListAdapter @Inject constructor(
observable.notifyListeners()
}
override fun getSelected(): List<Habit> {
return ArrayList(selected)
}
/**
* Returns the item that occupies a certain position on the list
*