refactor: split composeApp to client and ui

also renamed client.datasource to client.data, which made me realise
.gitignore was ignoring `data` and therefore some gtfsr source files
😭
This commit is contained in:
Cilly Leang 2026-03-02 00:09:33 +11:00
parent d3edabce36
commit 74338d6dce
Signed by: cilly
GPG key ID: 6500251E087653C9
62 changed files with 121 additions and 23 deletions

View file

@ -0,0 +1,12 @@
package moe.lava.banksia.data.gtfsr
import com.google.transit.realtime.FeedMessage
abstract class GtfsRealtime(protected val data: FeedMessage) {
companion object {
inline fun <T: GtfsRealtime> parse(ctor: (FeedMessage) -> T, data: ByteArray): T {
val message = FeedMessage.ADAPTER.decode(data)
return ctor(message)
}
}
}

View file

@ -0,0 +1,22 @@
package moe.lava.banksia.data.gtfsr
import com.google.transit.realtime.FeedMessage
import moe.lava.banksia.util.Point
class RealtimeVehiclePositions(data: FeedMessage) : GtfsRealtime(data) {
private val positions = mutableMapOf<String, Point>()
init {
data.entity
.mapNotNull { ent ->
if (ent.vehicle?.position == null) return@mapNotNull null
ent.id to ent.vehicle.position.run {
Point(latitude.toDouble(), longitude.toDouble())
}
}
.let { positions.putAll(it) }
}
fun getAll() = positions.toMap()
fun forTrip(tripId: String) = positions[tripId]
}