Author: Adam Pioterek <adam.pioterek@protonmail.ch>
fix: favourites in main activity show all lines
app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt | 12 ++++++--
diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt b/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt index da24710bb4eb92c79f3cdb3c77e10394ffe2bf23..94610b4ae43957c92dc947112ddca7a11a6b9d1c 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt @@ -16,7 +16,7 @@ private set var segments: HashSet<StopSegment> private set private var fullDepartures: Map<String, List<Departure>> = HashMap() - private var cache: List<Departure> = ArrayList() + private val cache = HashMap<Plate.ID, List<Departure>>() private var listenerId = "" val size @@ -121,7 +121,7 @@ fun nextDeparture() = if (cache.isEmpty()) null else - cache.sortedBy { it.time }[0] + cache.flatMap { it.value }.sortedBy { it.time }[0] fun fullTimetable(): Map<String, List<Departure>> { @@ -146,7 +146,13 @@ return listenerId } override fun onDeparturesReady(departures: List<Departure>, plateId: Plate.ID?, code: Int) { - cache = departures + if (plateId == null) { + cache.clear() + cache[Plate.ID.dummy] = departures + } else { + cache.remove(Plate.ID.dummy) + cache[plateId] = departures + } listener.onDeparturesReady(departures, plateId, code) }