Skip to content

Commit

Permalink
✨ Added plane support (and fallback) (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
jheubuch authored Jun 28, 2024
1 parent 7fa5a69 commit 8800946
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ abstract class AbstractStatistics(
}

data class CategoryStatistics(
@SerializedName("name") val productType: ProductType,
@SerializedName("name") val productType: ProductType?,
@SerializedName("count") override val checkInCount: Int,
@SerializedName("duration") override val duration: Int
) : AbstractStatistics() {
override fun getLabel(context: Context) = context.getString(productType.getString())
private val safeProductType get() = productType ?: ProductType.UNKNOWN
override fun getLabel(context: Context) = context.getString(safeProductType.getString())
}

data class OperatorStatistics(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.time.ZonedDateTime
data class Journey(
@SerializedName("trip") val tripId: Int,
@SerializedName("hafasId") val hafasTripId: String,
val category: ProductType,
val category: ProductType?,
@SerializedName("lineName") val line: String,
val journeyNumber: Int?,
val distance: Int,
Expand All @@ -21,4 +21,6 @@ data class Journey(
@SerializedName("manualArrival") val arrivalManual: ZonedDateTime?,
val operator: HafasOperator?,
@SerializedName("number") val lineId: String
)
) {
val safeProductType get() = category ?: ProductType.UNKNOWN
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ data class HafasLine(
@SerializedName("id") val id: String,
@SerializedName("fahrtNr") val journeyNumber: Int,
@SerializedName("name") val name: String?,
@SerializedName("product") val product: ProductType,
@SerializedName("product") val product: ProductType?,
@SerializedName("operator") val operator: HafasOperator?
)
) {
val safeProductType get() = product ?: ProductType.UNKNOWN
}

@Suppress("unused")
enum class ProductType {
Expand All @@ -32,7 +34,6 @@ enum class ProductType {
},
@SerializedName("suburban")
SUBURBAN {
override val isTrain = true
override fun getIcon() = R.drawable.ic_suburban
override fun getString() = R.string.product_type_suburban
},
Expand All @@ -49,33 +50,35 @@ enum class ProductType {
// RE, RB, RS
@SerializedName("regional")
REGIONAL {
override val isTrain = true
override fun getString() = R.string.product_type_regional
},
// IRE, IR
@SerializedName("regionalExp")
REGIONAL_EXPRESS {
override val isTrain = true
override fun getString() = R.string.product_type_regional_express
},
// ICE, ECE
@SerializedName("nationalExpress")
NATIONAL_EXPRESS {
override val isTrain = true
override fun getString() = R.string.product_type_national_express
},
// IC, EC
@SerializedName("national")
NATIONAL {
override val isTrain = true
override fun getString() = R.string.product_type_national
},
@SerializedName("plane")
PLANE {
override fun getIcon() = R.drawable.ic_plane
},
LONG_DISTANCE {
override val isTrain = true
override fun getString() = R.string.product_type_national_express
},
UNKNOWN {
override fun getIcon() = R.drawable.ic_unknown
override fun getString() = R.string.unknown
};

open val isTrain = false
open fun getIcon() = R.drawable.ic_train
open fun getString() = R.string.product_type_bus
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import de.hbch.traewelling.api.models.station.Station

data class HafasTrainTrip(
@SerializedName("id") val id: Int,
@SerializedName("category") val category: ProductType,
@SerializedName("category") val category: ProductType?,
@SerializedName("lineName") val lineName: String,
@SerializedName("origin") val origin: Station,
@SerializedName("destination") val destination: Station,
@SerializedName("stopovers") var stopovers: List<HafasTrainTripStation>,
@SerializedName("number") val lineId: String
)
) {
val safeProductType get() = category ?: ProductType.UNKNOWN
}
4 changes: 2 additions & 2 deletions app/src/main/kotlin/de/hbch/traewelling/navigation/NavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fun TraewelldroidNavHost(
checkInViewModel.startStationId = it.journey.origin.id
checkInViewModel.tripId = it.journey.hafasTripId
checkInViewModel.editStatusId = it.id
checkInViewModel.category = it.journey.category
checkInViewModel.category = it.journey.safeProductType

navController.navigate(
"check-in/?editMode=true"
Expand Down Expand Up @@ -327,7 +327,7 @@ fun TraewelldroidNavHost(
checkInViewModel.departureTime = status.journey.origin.departurePlanned
checkInViewModel.destinationStationId = status.journey.destination.id
checkInViewModel.arrivalTime = status.journey.destination.arrivalPlanned
checkInViewModel.category = status.journey.category
checkInViewModel.category = status.journey.safeProductType
checkInViewModel.destination = status.journey.destination.name

navController.navigate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private fun SuccessfulCheckInResult(
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
StatusDetailsRow(
productType = journey.category,
productType = journey.safeProductType,
line = journey.line,
journeyNumber = journey.journeyNumber,
kilometers = journey.distance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fun CheckInCard(
end.linkTo(stationRowTop.end)
width = Dimension.fillToConstraints
},
productType = status.journey.category,
productType = status.journey.safeProductType,
line = status.journey.line,
kilometers = status.journey.distance,
duration = status.journey.duration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fun SearchConnection(
checkInViewModel.tripId = trip.tripId
checkInViewModel.startStationId = trip.station?.id ?: -1
checkInViewModel.departureTime = trip.plannedDeparture
checkInViewModel.category = trip.line?.product ?: ProductType.ALL
checkInViewModel.category = trip.line?.safeProductType ?: ProductType.UNKNOWN
checkInViewModel.origin = trip.station?.name ?: ""

onTripSelected()
Expand Down Expand Up @@ -349,7 +349,7 @@ fun SearchConnection(
}
}
.padding(vertical = 8.dp),
productType = trip.line?.product ?: ProductType.BUS,
productType = trip.line?.safeProductType ?: ProductType.UNKNOWN,
departurePlanned = trip.plannedDeparture ?: ZonedDateTime.now(),
departureReal = trip.departure ?: trip.plannedDeparture,
isCancelled = trip.isCancelled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fun SelectDestination(
DataLoading()
} else {
FromToTextRow(
category = trip!!.category,
category = trip!!.safeProductType,
lineName = trip!!.lineName,
lineId = checkInViewModel.lineId,
operatorCode = checkInViewModel.operatorCode,
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_plane.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="?attr/colorControlNormal" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="#000000" android:pathData="M22,16v-2l-8.5,-5V3.5C13.5,2.67 12.83,2 12,2s-1.5,0.67 -1.5,1.5V9L2,14v2l8.5,-2.5V19L8,20.5L8,22l4,-1l4,1l0,-1.5L13.5,19v-5.5L22,16z"/>

</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values-de-rDE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<string name="product_type_regional_express">Interregio</string>
<string name="product_type_national_express">Fernverkehr (ICE/ECE)</string>
<string name="product_type_national">Fernverkehr (IC/EC)</string>
<string name="product_type_plane">Flugzeug</string>
<string name="data_loading" tools:ignore="TypographyEllipsis">Daten werden geladen…</string>
<string name="status_details">Statusdetails</string>
<string name="title_statistics">Statistik</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<string name="product_type_regional_express">Regional express</string>
<string name="product_type_national_express">National express</string>
<string name="product_type_national">Regional express</string>
<string name="product_type_plane">Plane</string>
<string name="data_loading" tools:ignore="TypographyEllipsis">Loading data…</string>
<string name="status_details">Status details</string>
<string name="title_statistics">Statistics</string>
Expand Down

0 comments on commit 8800946

Please sign in to comment.