Bimba.git

commit d71c241c8d6d3defdadd1720c549fdff55deef85

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

show exact stop from map, all children from transitous search

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/api/transitousDepartures.kt b/app/src/main/java/xyz/apiote/bimba/czwek/api/transitousDepartures.kt
index fcf627e0871257a5435aafb88f8e5e2be49325f6..571253b1be94818ee2b5a9660e1b849e9ad608ab 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/api/transitousDepartures.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/api/transitousDepartures.kt
@@ -32,7 +32,8 @@ suspend fun getTransitousDepartures(
 	context: Context,
 	stop: String,
 	date: LocalDate?,
-	limit: Int?
+	limit: Int?,
+	exact: Boolean
 ): StopEvents {
 	if (!isNetworkAvailable(context)) {
 		throw TrafficResponseException(0, "", Error(0, R.string.error_offline, R.drawable.error_net))
@@ -47,9 +48,11 @@ 		val times = TimetableApi().stoptimes(stop, limit ?: 12, datetime)
 		var stopName = ""
 		var latitude: BigDecimal = BigDecimal(0)
 		var longitude: BigDecimal = BigDecimal(0)
-		val departures = times.stopTimes.map {
+		val departures = times.stopTimes.filter {
+			!exact || stop == it.place.stopId
+		}.map {
 			Log.i("stop", "stopID recvd: ${it.place.stopId}")
-			if (it.place.arrival == null) {
+			if ((it.place.departure ?: it.place.arrival) == null) {
 				null
 			} else {
 				latitude = it.place.lat
@@ -57,7 +60,7 @@ 				longitude = it.place.lon
 				stopName = it.place.name
 				Departure(
 					it.tripId + it.source,
-					Time.fromOffsetTime(it.place.arrival, ZoneId.systemDefault()),
+					Time.fromOffsetTime(it.place.departure ?: it.place.arrival!!, ZoneId.systemDefault()),
 					0u,
 					it.realTime,
 					Vehicle(
@@ -65,7 +68,11 @@ 						it.tripId,
 						Position(0.0, 0.0),
 						0u,
 						Mps(0),
-						LineStub(it.routeShortName, LineType.fromTransitous2(it.mode), Colour.fromHex(it.routeColor)),
+						LineStub(
+							it.routeShortName,
+							LineType.fromTransitous2(it.mode),
+							Colour.fromHex(it.routeColor)
+						),
 						it.headsign,
 						CongestionLevel.UNKNOWN,
 						OccupancyStatus.UNKNOWN




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeViewModel.kt b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeViewModel.kt
index def65cf9bf6e3e4d1f37c37e65d5121123a5824d..6a680cae533f9a7a5d7cd02238a13c691493768d 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeViewModel.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeViewModel.kt
@@ -86,7 +86,8 @@ 								favourite.feedID,
 								favourite.stopCode,
 								null,
 								context,
-								12  // XXX heuristics
+								12,  // XXX heuristics
+								false  // TODO save exact in favourite
 							)
 							stopDepartures?.let { sDs ->
 								if (sDs.events.isEmpty()) {




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapViewModel.kt b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapViewModel.kt
index a9ff0719d69c398d56d1f3e06ad2aa3cc8072187..ceeb223f0fc4e4f66c0e9c81fda2a79c08c586f0 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapViewModel.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapViewModel.kt
@@ -168,7 +168,7 @@ 	private fun showStop(content: View, stop: Stop) {
 		context?.let { ctx ->
 			content.findViewById<TextView>(R.id.stop_name).text = stop.name
 			content.findViewById<Button>(R.id.departures_button).setOnClickListener {
-				startActivity(DeparturesActivity.getIntent(requireContext(), stop.code, stop.name, stop.feedID!!))
+				startActivity(DeparturesActivity.getIntent(requireContext(), stop.code, stop.name, stop.feedID!!, true))
 			}
 			content.findViewById<Button>(R.id.navigation_button).setOnClickListener {
 				try {




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt b/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt
index 8ca35eb6214c46644d0d28ee8f635bd4054a37d5..99ec4bb97a1bba448ce9f1b7df2e0aad8214e898 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesActivity.kt
@@ -64,16 +64,19 @@ 		const val NAME_PARAM = "name"
 		const val FEED_PARAM = "feedID"
 		const val LINES_FILTER_PARAM = "linesFilter"
 		const val LINE_PARAM = "line"
+		const val EXACT_PARAM = "exact"
 
 		fun getIntent(
 			context: Context,
 			code: String,
 			name: String,
 			feedID: String,
-		) = Intent(context, DeparturesActivity::class.java).apply {
+			exact: Boolean = false,
+		)  = Intent(context, DeparturesActivity::class.java).apply {
 			putExtra(CODE_PARAM, code)
 			putExtra(NAME_PARAM, name)
 			putExtra(FEED_PARAM, feedID)
+			putExtra(EXACT_PARAM, exact)
 		}
 
 		fun getIntent(
@@ -466,6 +469,8 @@ 	}
 
 	private fun getCode() = intent?.extras?.getString(CODE_PARAM)
 
+	private fun getExact() = intent?.extras?.getBoolean(EXACT_PARAM) == true
+
 	fun getDepartures(force: Boolean = false) {
 		binding.departuresUpdatesProgress.isIndeterminate = true
 		if (force) {
@@ -474,7 +479,7 @@ 		} else {
 			adapter.refreshItems()
 			setupSnackbar()
 		}
-		viewModel.getDepartures(this, viewModel.date, force)
+		viewModel.getDepartures(this, viewModel.date, force, getExact())
 	}
 
 	private fun setupSnackbar() {




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesViewModel.kt b/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesViewModel.kt
index 21dbd04eefa862f93ad0f5ad95a0fc1ef48e80db..0e812fc1dbeee2644bcad37645add08d5deceddd 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesViewModel.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/departures/DeparturesViewModel.kt
@@ -46,7 +46,7 @@
 	// TODO observe in activity, refreshing is not enough
 	var date: LocalDate? = null
 
-	fun getDepartures(context: Context, date: LocalDate?, force: Boolean) {
+	fun getDepartures(context: Context, date: LocalDate?, force: Boolean, exact: Boolean) {
 		MainScope().launch {
 			try {
 				if (feed == null) {
@@ -61,7 +61,8 @@ 						feed!!.id,
 						code,
 						date,
 						context,
-						requestedItemsNumber
+						requestedItemsNumber,
+						exact
 					)
 				stopDepartures?.let {
 					if (stopDepartures.events.isEmpty()) {




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/Interfaces.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/Interfaces.kt
index e612503b10f270a49961d1482475da55fb3f47db..9b8b1da3afd0b34a1f9fb2d2812be70543d2c998 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/repo/Interfaces.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/repo/Interfaces.kt
@@ -35,7 +35,8 @@ 		feedID: String,
 		stop: String,
 		date: LocalDate?,
 		context: Context,
-		limit: Int?
+		limit: Int?,
+		exact: Boolean
 	): StopEvents?
 
 	suspend fun getLocatablesIn(




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/OfflineRepository.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/OfflineRepository.kt
index 309d6ec0f00248d543db51e92389dfddb1457a3d..04f964cc639a9facf25c760ed9ef487d06801c4e 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/repo/OfflineRepository.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/repo/OfflineRepository.kt
@@ -199,7 +199,8 @@ 		feedID: String,
 		stop: String,
 		date: LocalDate?,
 		context: Context,
-		limit: Int?
+		limit: Int?,
+		exact: Boolean
 	): StopEvents? {
 		TODO("Not yet implemented")
 	}




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/OnlineRepository.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/OnlineRepository.kt
index 95819178a6e46c81785a0ba505ce4fab752ac98d..3f078daac0a5c69f2679a0e00142d3172234aae9 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/repo/OnlineRepository.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/repo/OnlineRepository.kt
@@ -112,10 +112,11 @@ 		feedID: String,
 		stop: String,
 		date: LocalDate?,
 		context: Context,
-		limit: Int?
+		limit: Int?,
+		exact: Boolean
 	): StopEvents? {
 		return if (feedID == "transitous") {
-			getTransitousDepartures(context, stop, date, limit)
+			getTransitousDepartures(context, stop, date, limit, exact)
 		} else {
 			val result = xyz.apiote.bimba.czwek.api.getDepartures(
 				context,




diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 1f990cc3b25e064ea38ef5e14bc97f87aa2297e5..7bc3779f9823af620c497c26f8a3c661eb9a8d37 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -78,4 +78,4 @@
 	<style name="Preference.SwitchPreferenceCompat" parent="@style/Preference.SwitchPreferenceCompat.Material" tool:ignore="ResourceCycle">
 		<item name="widgetLayout">@layout/preferences_switch_material</item>
 	</style>
-</resources>
\ No newline at end of file
+</resources>