ref: 009e40933320a46978bb4175a788e8a77e8390c9
app/src/main/java/xyz/apiote/bimba/czwek/repo/Vehicle.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
package xyz.apiote.bimba.czwek.repo import android.content.Context import android.graphics.drawable.Drawable import xyz.apiote.bimba.czwek.R import xyz.apiote.bimba.czwek.api.UnknownResourceVersion import xyz.apiote.bimba.czwek.api.VehicleV1 import xyz.apiote.bimba.czwek.api.VehicleV2 data class Vehicle( val ID: String, val Position: Position, val Capabilities: UShort, val Speed: Float, val Line: LineStub, val Headsign: String, val CongestionLevel: ULong, val OccupancyStatus: ULong ) : Locatable { constructor(v: VehicleV1):this(v.ID, Position(v.Position), v.Capabilities, v.Speed, LineStub(v.Line), v.Headsign, v.CongestionLevel, v.OccupancyStatus) constructor(v: VehicleV2):this(v.ID, Position(v.Position), v.Capabilities, v.Speed, LineStub(v.Line), v.Headsign, v.CongestionLevel, v.OccupancyStatus) enum class Capability(val bit: UShort) { RAMP(0b0001u), LOW_FLOOR(0b0010u), LOW_ENTRY(0b0001_0000_0000u), AC(0b0100u), BIKE(0b1000u), VOICE( 0b0001_0000u ), TICKET_MACHINE(0b0010_0000u), TICKET_DRIVER(0b0100_0000u), USB_CHARGING(0b1000_0000u) } override fun icon(context: Context, scale: Float): Drawable = Line.icon(context, scale) override fun location(): Position = Position override fun id(): String = ID fun congestion(context: Context): String { return when (val r = CongestionLevel.toUInt()) { // todo [3.1] enum 0u -> context.getString(R.string.congestion_unknown) 1u -> context.getString(R.string.congestion_smooth) 2u -> context.getString(R.string.congestion_stop_and_go) 3u -> context.getString(R.string.congestion_congestion) 4u -> context.getString(R.string.congestion_jams) else -> throw UnknownResourceVersion("Congestion/$r", 1u) } } fun occupancy(context: Context): String { return when (val r = OccupancyStatus.toUInt()) { // todo [3.1] enum 0u -> context.getString(R.string.occupancy_unknown) 1u -> context.getString(R.string.occupancy_empty) 2u -> context.getString(R.string.occupancy_many_seats) 3u -> context.getString(R.string.occupancy_few_seats) 4u -> context.getString(R.string.occupancy_standing_only) 5u -> context.getString(R.string.occupancy_crowded) 6u -> context.getString(R.string.occupancy_full) 7u -> context.getString(R.string.occupancy_wont_let) else -> throw UnknownResourceVersion("Occupancy/$r", 1u) } } fun getCapability(field: Capability): Boolean { return Capabilities.and(field.bit) != (0).toUShort() } } |