Bimba.git

commit 1c073767e9664ef01bd2a9322a6c9b570ef9c50e

Author: Adam Evyčędo <git@apiote.xyz>

fix show as time after separating departures and arrivals

 app/src/main/java/xyz/apiote/bimba/czwek/repo/Event.kt | 72 ++++++-----


diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/Event.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/Event.kt
index 7124878123c6fdac915f2f3f76e6b89a9d8f2819..5e70e8f0e8435eec878d87e43e5edcbde64ba262 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/repo/Event.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/repo/Event.kt
@@ -187,9 +187,9 @@ 		d.exact,
 		d.terminusArrival
 	)
 
-	fun timeZone() = (arrivalTime?:departureTime)!!.Zone
+	fun timeZone() = (arrivalTime ?: departureTime)!!.Zone
 
-	fun filterTime() = (arrivalTime?:departureTime)!!
+	fun filterTime() = (arrivalTime ?: departureTime)!!
 
 	fun statusText(
 		context: Context?,
@@ -197,10 +197,19 @@ 		showAsTime: Boolean,
 		at: ZonedDateTime? = null
 	): Pair<String?, String?> {
 		val now = at ?: Instant.now().atZone(ZoneId.systemDefault())
-		return Pair(statusText(context, showAsTime, now, arrivalTime, R.string.departure_arrived), statusText(context, showAsTime, now, departureTime, R.string.departure_departed))
+		return Pair(
+			statusText(context, showAsTime, now, arrivalTime, R.string.departure_arrived),
+			statusText(context, showAsTime, now, departureTime, R.string.departure_departed)
+		)
 	}
 
-	private fun statusText(context: Context?, showAsTime: Boolean, now: ZonedDateTime, time: Time?, pastString: Int): String? {
+	private fun statusText(
+		context: Context?,
+		showAsTime: Boolean,
+		now: ZonedDateTime,
+		time: Time?,
+		pastString: Int
+	): String? {
 		val r = status.toUInt()
 		return time?.let {
 			ZonedDateTime.of(
@@ -216,39 +225,38 @@ 					it.Zone
 				)
 			)
 				.plus(it.DayOffset.toLong(), ChronoUnit.DAYS)
-				.apply {
+				.let {
 					if (showAsTime) {
-						format(DateTimeFormatter.ofPattern("HH:mm"))
-					}
-				}.let {
-					when {
-						// TODO why this condition
-						r == 0u || (it.isBefore(now) && r < 3u) -> if (context != null && UnitSystem.getSelected(
-								context
-							) is TGM
-						) {
-							val us = UnitSystem.getSelected(context)
-							us.toString(
-								context,
-								us.timeUnit(Second((it.toEpochSecond() - now.toEpochSecond()).toInt()))
-							)
-						} else {
-							DateUtils.getRelativeTimeSpanString(
-								it.toEpochSecond() * 1000,
-								now.toEpochSecond() * 1000,
-								DateUtils.MINUTE_IN_MILLIS,
-								DateUtils.FORMAT_ABBREV_RELATIVE
-							).toString()
-						}
+						it.format(DateTimeFormatter.ofPattern("HH:mm"))
+					} else {
+						when {
+							// TODO why this condition
+							r == 0u || (it.isBefore(now) && r < 3u) -> if (context != null && UnitSystem.getSelected(
+									context
+								) is TGM
+							) {
+								val us = UnitSystem.getSelected(context)
+								us.toString(
+									context,
+									us.timeUnit(Second((it.toEpochSecond() - now.toEpochSecond()).toInt()))
+								)
+							} else {
+								DateUtils.getRelativeTimeSpanString(
+									it.toEpochSecond() * 1000,
+									now.toEpochSecond() * 1000,
+									DateUtils.MINUTE_IN_MILLIS,
+									DateUtils.FORMAT_ABBREV_RELATIVE
+								).toString()
+							}
 
-						r == 1u -> context?.getString(R.string.departure_momentarily) ?: "momentarily"
-						r == 2u -> context?.getString(R.string.departure_now) ?: "now"
-						r == 3u -> context?.getString(pastString) ?: "passed"
-						else -> throw UnknownResourceVersionException("VehicleStatus/$r", 1u)
+							r == 1u -> context?.getString(R.string.departure_momentarily) ?: "momentarily"
+							r == 2u -> context?.getString(R.string.departure_now) ?: "now"
+							r == 3u -> context?.getString(pastString) ?: "passed"
+							else -> throw UnknownResourceVersionException("VehicleStatus/$r", 1u)
+						}
 					}
 				}
 		}
-
 	}
 
 	fun departureTimeString(context: Context): String? = timeString(context, departureTime)