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:
parent
d3edabce36
commit
74338d6dce
62 changed files with 121 additions and 23 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue