Author: Adam <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 15e36932c42b5c8aa8b6ab8fbdbe3062b5fd5ed0..178ec86d7ea6f9bb3ef5053c4426f348f0f3fbdf 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 ): StopDepartures { 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 ba6da66f9308e7dc91bd81aca46cff37c3dffee1..e9477b9aca8dd0640acb7524d763247499dced78 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.departures.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 6aa86b0cb2362798e410558411e5229ae8ba873e..3d7fadefb4ebbd67752718a9ba94414d48f79458 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 0b725721dcfca87b8b52eaa06e4407b36784c410..9aac58bae9a6bbafb1a8a8bc5a0e130a40a3bc45 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 @@ -63,16 +63,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( @@ -464,6 +467,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) { @@ -472,7 +477,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 bd61194560e6a232a5754bbf33fa60b3ed03dc6f..47e8bfab9d99c2009d12d2e3e4769aa993347f9c 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.departures.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 a337b0178c144f066ffea44ebd3898c475d850c0..50b4c576a9b2d0c9b1495e24fc1e26273098a3ab 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 ): StopDepartures? 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 b11a5dfcccc9048e0390e0dfe9ad530e875a7668..61103a2eefa0d02e66ea1701ae4d35d18115ddbb 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 ): StopDepartures? { 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 de9d0bc85201a2b5c4a5321fd1c64f4d9859048a..2d4ddeb90f97f54cd56246ae8072e59ccd40aa9b 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 ): StopDepartures? { 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 042048b10e8ca72c5956032013ac943358cfae06..c9ad5d9d8522c5e2af5f7077e55cca8204a96d65 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -58,7 +58,7 @@- 9sp
</style> <style name="Theme.Bimba.Splash" parent="Theme.SplashScreen"> - <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item> + <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item> <!-- TODO squircle logo --> <item name="windowSplashScreenIconBackgroundColor">@color/ic_launcher_background</item> <item name="postSplashScreenTheme">@style/Theme.Bimba</item> </style> diff --git a/app/src/main/res/values-v31/themes.xml b/app/src/main/res/values-v31/themes.xml index 1b04dfb059a09665e1aa20100b1a0e4b5f19d4cb..4d24368028a4091da274990c95e2fdadb5f25a08 100644 --- a/app/src/main/res/values-v31/themes.xml +++ b/app/src/main/res/values-v31/themes.xml @@ -58,7 +58,7 @@- 9sp
</style> <style name="Theme.Bimba.Splash" parent="Theme.SplashScreen"> - <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item> + <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item> <!-- TODO squircle logo --> <item name="windowSplashScreenIconBackgroundColor">@color/ic_launcher_background</item> <item name="postSplashScreenTheme">@style/Theme.Bimba</item> </style>