Author: Adam <git@apiote.xyz>
todos, formatting, dependencies
%!v(PANIC=String method: strings: negative Repeat count)
diff --git a/app/build.gradle b/app/build.gradle index f9dfb822e4edf7551e2d829f6cbb227e7094b5cc..6dcf044352dd8a02d4aadbeefcd0d23eadf48767 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,8 +48,8 @@ implementation 'com.google.android.material:material:1.9.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1' - implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3' - implementation 'androidx.navigation:navigation-ui-ktx:2.5.3' + implementation 'androidx.navigation:navigation-fragment-ktx:2.6.0' + implementation 'androidx.navigation:navigation-ui-ktx:2.6.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.core:core-splashscreen:1.0.1' implementation 'com.google.openlocationcode:openlocationcode:1.0.4' diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/Bimba.kt b/app/src/main/java/xyz/apiote/bimba/czwek/Bimba.kt index f32fbfbb49ce718e677036fbd07d223fb01f1f35..dfa1fb1659a435ec02e450071088b1b5b8233f97 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/Bimba.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/Bimba.kt @@ -3,6 +3,12 @@ import org.osmdroid.config.Configuration import java.io.File +/* todo + api.AlertV1 enums (Structs.kt) + repo.Alert enums (Departure.kt) + ErrorResponseError + repo.Vehicle enums (Vehicle.kt) +*/ class Bimba : android.app.Application() { override fun onCreate() { super.onCreate() diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/api/Api.kt b/app/src/main/java/xyz/apiote/bimba/czwek/api/Api.kt index 4cba8902ca3652ee80da5ecd0c4dd4f10ed28c46..651daf551fd70c738ca448781bb530606a32ee95 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/api/Api.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/api/Api.kt @@ -13,8 +13,8 @@ import java.net.MalformedURLException import java.net.URL import java.net.URLEncoder -// todo [3.1] constants -// todo [3.1] split api files to classes files +// todo [3.2] constants +// todo [3.2] split api files to classes files data class Server(val host: String, val token: String, val feeds: String, val apiPath: String) { companion object { @@ -146,7 +146,7 @@ responseVersion: Array, feeds: String? ): Result { return withContext(Dispatchers.IO) { - val url = URL( // todo [3.1] scheme, host, path, constructed query + val url = URL( // todo [3.2] scheme, host, path, constructed query "${server.apiPath}/${feeds?.ifEmpty { server.feeds } ?: server.feeds}/$resource${ if (item == null) { "" diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/api/Responses.kt b/app/src/main/java/xyz/apiote/bimba/czwek/api/Responses.kt index 411ff36c468c9920ecbf9bd182cf5f676b5f8e67..995a8f761ebe42cc963f9d6b8a12d0973f2316e0 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/api/Responses.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/api/Responses.kt @@ -46,9 +46,11 @@ return when (val v = reader.readUInt().toULong()) { 0UL -> { DeparturesResponseDev.unmarshal(stream) } + 1UL -> { DeparturesResponseV1.unmarshal(stream) } + else -> { throw UnknownResponseVersion("Departures", v) } @@ -119,9 +121,11 @@ return when (val v = reader.readUInt().toULong()) { 0UL -> { QueryablesResponseDev.unmarshal(stream) } + 1UL -> { QueryablesResponseV1.unmarshal(stream) } + else -> { throw UnknownResponseVersion("Queryables", v) } @@ -141,6 +145,7 @@ when (val r = reader.readUInt().toULong()) { 0UL -> { queryables.add(StopV1.unmarshal(stream)) } + else -> { throw UnknownResourceVersion("Queryable/$r", 1u) } @@ -162,9 +167,11 @@ when (val r = reader.readUInt().toULong()) { 0UL -> { queryables.add(StopV2.unmarshal(stream)) } + 1UL -> { queryables.add(LineV1.unmarshal(stream)) } + else -> { throw UnknownResourceVersion("Queryable/$r", 1u) } @@ -183,9 +190,11 @@ return when (val v = reader.readUInt().toULong()) { 0UL -> { FeedsResponseDev.unmarshal(stream) } + 1UL -> { FeedsResponseV1.unmarshal(stream) } + else -> { throw UnknownResponseVersion("Feeds", v) } @@ -234,9 +243,11 @@ return when (val v = reader.readUInt().toULong()) { 0UL -> { LocatablesResponseDev.unmarshal(stream) } + 1UL -> { LocatablesResponseV1.unmarshal(stream) } + else -> { throw UnknownResponseVersion("Locatables", v) } @@ -256,9 +267,11 @@ when (val r = reader.readUInt().toULong()) { 0UL -> { locatables.add(StopV1.unmarshal(stream)) } + 1UL -> { locatables.add(VehicleV1.unmarshal(stream)) } + else -> { throw UnknownResourceVersion("Locatable/$r", 1u) } @@ -268,6 +281,7 @@ return LocatablesResponseV1(locatables) } } } + data class LocatablesResponseDev(val locatables: List<LocatableV2>) : LocatablesResponse { companion object { fun unmarshal(stream: InputStream): LocatablesResponseDev { @@ -279,9 +293,11 @@ when (val r = reader.readUInt().toULong()) { 0UL -> { locatables.add(StopV2.unmarshal(stream)) } + 1UL -> { locatables.add(VehicleV2.unmarshal(stream)) } + else -> { throw UnknownResourceVersion("Locatable/$r", 1u) } diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/api/Structs.kt b/app/src/main/java/xyz/apiote/bimba/czwek/api/Structs.kt index 0b620b1604ee37b25998b635562bfb57c263794b..90fe803508308ca2bca30cbc05c99c502d367a75 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/api/Structs.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/api/Structs.kt @@ -368,11 +368,7 @@ for (i in 0UL until chOptionsNum) { changeOptions.add(ChangeOptionV1.unmarshal(stream)) } return StopV1( - name = name, - code = code, - zone = zone, - position = position, - changeOptions = changeOptions + name = name, code = code, zone = zone, position = position, changeOptions = changeOptions ) } } @@ -465,8 +461,7 @@ } } data class LineGraph( - val stops: List<StopStub>, - val nextNodes: Map<Long, List<Long>> + val stops: List<StopStub>, val nextNodes: Map<Long, List<Long>> ) { companion object { fun unmarshal(stream: InputStream): LineGraph { @@ -494,11 +489,7 @@ } } data class StopStub( - val code: String, - val name: String, - val nodeName: String, - val zone: String, - val onDemand: Boolean + val code: String, val name: String, val nodeName: String, val zone: String, val onDemand: Boolean ) { companion object { fun unmarshal(stream: InputStream): StopStub { diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt index eeece9a4a3c56b2e206fc1dc7da7742b93acb9a4..eb7c07ea9d76e95d21a3a00f8807ae024d9113f0 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/MainActivity.kt @@ -187,7 +187,7 @@ } } private fun showResults(query: String, centerLatitude: Double, centerLongitude: Double) { - /* todo [3.1] (ux,low) animation + /* todo [3.2] (ux,low) animation https://developer.android.com/guide/fragments/animate https://github.com/raheemadamboev/fab-explosion-animation-app */ @@ -201,7 +201,7 @@ startActivity(intent) } private fun showResults(mode: ResultsActivity.Mode, query: String = "") { - /* todo [3.1] (ux,low) animation + /* todo [3.2] (ux,low) animation https://developer.android.com/guide/fragments/animate https://github.com/raheemadamboev/fab-explosion-animation-app */ 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 87c96df07b95db0132b064943c29da4937b52df5..50eb6a889b34dfc238ff57b48b3d0a6d70f8286d 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 @@ -66,7 +66,7 @@ vehicle.Line.name, vehicle.Headsign ) } - // todo units -- [3.1] settings or system-based + // todo units -- [3.2] settings or system-based content.findViewById<TextView>(R.id.speed_text).text = ctx.getString(R.string.speed_in_km_per_h, vehicle.Speed * 3.6) content.findViewById<TextView>(R.id.congestion_text).text = vehicle.congestion(ctx) diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/departures/Departures.kt b/app/src/main/java/xyz/apiote/bimba/czwek/departures/Departures.kt index 9861781222203de84d18b8c0519e00f593d320a9..2b1f5c69ea8581714518c6abb9d3bf7a56ff6f99 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/departures/Departures.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/departures/Departures.kt @@ -96,7 +96,7 @@ departures[position] } } - @SuppressLint("NotifyDataSetChanged") // todo [3.1] DiffUtil + @SuppressLint("NotifyDataSetChanged") // todo [3.2] DiffUtil fun update(departures: List<Departure>) { val newPositions: MutableMap<String, Int> = HashMap() departures.forEachIndexed { i, departure -> @@ -171,7 +171,7 @@ ) } findViewById<TextView>(R.id.boarding_text).text = departure.boardingText(ctx) - // todo units -- [3.1] settings or system-based + // todo units -- [3.2] settings or system-based findViewById<TextView>(R.id.speed_text).text = getString(R.string.speed_in_km_per_h, departure.vehicle.Speed * 3.6) findViewById<TextView>(R.id.congestion_text).text = departure.vehicle.congestion(ctx) 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 4c8d7a0a8146a5c88ecdcffa186e992714cf6f1a..499074ee40192d3c10c16413cd45dd371ca24f2f 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 @@ -168,7 +168,7 @@ binding.errorImage.visibility = View.GONE binding.errorText.visibility = View.GONE binding.departuresRecycler.visibility = View.VISIBLE } - // todo [3.1] alerts - // todo [3.1] stop info + // todo [3.2; traffic] alerts + // todo [3.2; traffic] stop info } } \ No newline at end of file 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 5fc157428a5c0cf50e52f7b2e111840813078bdc..7e228854d67caaaceb5534bab94da75ae7b47b42 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 @@ -25,7 +25,7 @@ import xyz.apiote.bimba.czwek.api.StopV2 import xyz.apiote.bimba.czwek.api.VehicleV1 import xyz.apiote.bimba.czwek.api.VehicleV2 -// todo [3.1] in Repository check if responses are BARE or HTML +// todo [3.2] in Repository check if responses are BARE or HTML class OnlineRepository : Repository { override suspend fun getDepartures( @@ -35,7 +35,8 @@ stop: String, line: String?, context: Context ): StopDepartures? { - val result = xyz.apiote.bimba.czwek.api.getDepartures(cm, Server.get(context), feedID, stop, line) + val result = + xyz.apiote.bimba.czwek.api.getDepartures(cm, Server.get(context), feedID, stop, line) if (result.error != null) { if (result.stream != null) { val response = withContext(Dispatchers.IO) { ErrorResponse.unmarshal(result.stream) } @@ -46,8 +47,16 @@ } } else { return when (val response = withContext(Dispatchers.IO) { DeparturesResponse.unmarshal(result.stream!!) }) { - is DeparturesResponseDev -> StopDepartures(response.departures.map { Departure(it) }, Stop(response.stop), response.alerts.map{Alert(it)}) - is DeparturesResponseV1 -> StopDepartures(response.departures.map { Departure(it) }, Stop(response.stop), response.alerts.map{Alert(it)}) + is DeparturesResponseDev -> StopDepartures( + response.departures.map { Departure(it) }, + Stop(response.stop), + response.alerts.map { Alert(it) }) + + is DeparturesResponseV1 -> StopDepartures( + response.departures.map { Departure(it) }, + Stop(response.stop), + response.alerts.map { Alert(it) }) + else -> null } } diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/search/Results.kt b/app/src/main/java/xyz/apiote/bimba/czwek/search/Results.kt index 700383540800c6646d4e8f7b4d46d6aca2851116..b70409a51d62b6593e5a26a1747c823544730431 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/search/Results.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/search/Results.kt @@ -154,7 +154,7 @@ } override fun getItemCount(): Int = queryables.size - @SuppressLint("NotifyDataSetChanged") // todo [3.1] DiffUtil + @SuppressLint("NotifyDataSetChanged") // todo [3.2] DiffUtil fun update(queryables: List<Queryable>?) { this.queryables = queryables ?: emptyList() notifyDataSetChanged() diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/settings/feeds/FeedInfos.kt b/app/src/main/java/xyz/apiote/bimba/czwek/settings/feeds/FeedInfos.kt index dd00f08cf5b25aaa579b89960915a34a4870dc62..8e8391c997e8fdd7d13c371139583e671d31d38f 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/settings/feeds/FeedInfos.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/settings/feeds/FeedInfos.kt @@ -65,7 +65,7 @@ } override fun getItemCount(): Int = feeds.size - @SuppressLint("NotifyDataSetChanged") // todo [3.1] DiffUtil + @SuppressLint("NotifyDataSetChanged") // todo [3.2] DiffUtil fun update(items: List<FeedInfoV1>) { feeds = items.sortedBy { it.name } notifyDataSetChanged() diff --git a/app/src/main/res/xml/locales_config.xml b/app/src/main/res/xml/locales_config.xml index 5a77e406011dbc90df5a8abfa920fbb595a3080e..2faaf2fe9da36d47ac25ac14e8e92f4cfa087c24 100644 --- a/app/src/main/res/xml/locales_config.xml +++ b/app/src/main/res/xml/locales_config.xml @@ -2,5 +2,4 @@ <locale-config xmlns:android="http://schemas.android.com/apk/res/android"> <locale android:name="en" /> <locale android:name="pl" /> -</locale-config> - +</locale-config> \ No newline at end of file