Author: Adam Evyčędo <git@apiote.xyz>
fix reuse
%!v(PANIC=String method: strings: negative Repeat count)
diff --git a/.reuse/dep5 b/.reuse/dep5 deleted file mode 100644 index 0ec31152e0edaf81a99d37ff133cc698da9f669c..0000000000000000000000000000000000000000 --- a/.reuse/dep5 +++ /dev/null @@ -1,33 +0,0 @@ -Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: Bimba -Upstream-Contact: Adam Evyčędo <bimba@apiote.xyz> -Source: https://bimba.apiote.xyz - -Files: metadata/* -Copyright: 2024 Adam Evyčędo <bimba@apiote.xyz> -License: GPL-3.0-or-later - -Files: app/src/main/res/font/yellowcircle8.otf -Copyright: 2024 Adam Evyčędo <bimba@apiote.xyz> -License: OFL-1.1 - -Files: app/src/main/res/mipmap-hdpi/* -Copyright: 2024 Adam Evyčędo <bimba@apiote.xyz> -License: GPL-3.0-or-later - -Files: app/src/main/res/mipmap-mdpi/* -Copyright: 2024 Adam Evyčędo <bimba@apiote.xyz> -License: GPL-3.0-or-later - -Files: app/src/main/res/mipmap-xhdpi/* -Copyright: 2024 Adam Evyčędo <bimba@apiote.xyz> -License: GPL-3.0-or-later - -Files: app/src/main/res/mipmap-xxhdpi/* -Copyright: 2024 Adam Evyčędo <bimba@apiote.xyz> -License: GPL-3.0-or-later - -Files: app/src/main/res/mipmap-xxxhdpi/* -Copyright: 2024 Adam Evyčędo <bimba@apiote.xyz> -License: GPL-3.0-or-later - diff --git a/LICENSES/CC0-1.0.txt b/LICENSES/CC0-1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..0e259d42c996742e9e3cba14c677129b2c1b6311 --- /dev/null +++ b/LICENSES/CC0-1.0.txt @@ -0,0 +1,121 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. diff --git a/REUSE.toml b/REUSE.toml new file mode 100644 index 0000000000000000000000000000000000000000..5fc28d21bbdaa5e70044fd318072dd332d0fc987 --- /dev/null +++ b/REUSE.toml @@ -0,0 +1,50 @@ +# SPDX-FileCopyrightText: Adam Evyčędo +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +version = 1 +SPDX-PackageName = "Bimba" +SPDX-PackageSupplier = "Adam Evyčędo <bimba@apiote.xyz>" +SPDX-PackageDownloadLocation = "https://bimba.apiote.xyz" + +[[annotations]] +path = "metadata/**" +precedence = "aggregate" +SPDX-FileCopyrightText = "2024 Adam Evyčędo <bimba@apiote.xyz>" +SPDX-License-Identifier = "GPL-3.0-or-later" + +[[annotations]] +path = "app/src/main/res/font/yellowcircle8.otf" +precedence = "aggregate" +SPDX-FileCopyrightText = "2024 Adam Evyčędo <bimba@apiote.xyz>" +SPDX-License-Identifier = "OFL-1.1" + +[[annotations]] +path = "app/src/main/res/mipmap-hdpi/**" +precedence = "aggregate" +SPDX-FileCopyrightText = "2024 Adam Evyčędo <bimba@apiote.xyz>" +SPDX-License-Identifier = "GPL-3.0-or-later" + +[[annotations]] +path = "app/src/main/res/mipmap-mdpi/**" +precedence = "aggregate" +SPDX-FileCopyrightText = "2024 Adam Evyčędo <bimba@apiote.xyz>" +SPDX-License-Identifier = "GPL-3.0-or-later" + +[[annotations]] +path = "app/src/main/res/mipmap-xhdpi/**" +precedence = "aggregate" +SPDX-FileCopyrightText = "2024 Adam Evyčędo <bimba@apiote.xyz>" +SPDX-License-Identifier = "GPL-3.0-or-later" + +[[annotations]] +path = "app/src/main/res/mipmap-xxhdpi/**" +precedence = "aggregate" +SPDX-FileCopyrightText = "2024 Adam Evyčędo <bimba@apiote.xyz>" +SPDX-License-Identifier = "GPL-3.0-or-later" + +[[annotations]] +path = "app/src/main/res/mipmap-xxxhdpi/**" +precedence = "aggregate" +SPDX-FileCopyrightText = "2024 Adam Evyčędo <bimba@apiote.xyz>" +SPDX-License-Identifier = "GPL-3.0-or-later" diff --git a/app/src/androidTest/java/xyz/apiote/bimba/czwek/units/TGMKtTest.kt b/app/src/androidTest/java/xyz/apiote/bimba/czwek/units/TGMKtTest.kt index 8699c205595e80d6dca7922994585004ad8f3a31..4a2c9992ce3cee112261c8092a7f7c074a8bdc71 100644 --- a/app/src/androidTest/java/xyz/apiote/bimba/czwek/units/TGMKtTest.kt +++ b/app/src/androidTest/java/xyz/apiote/bimba/czwek/units/TGMKtTest.kt @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + package xyz.apiote.bimba.czwek.units import androidx.test.platform.app.InstrumentationRegistry diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 66a021e365d8b0f0506f6a62a283ce3d9d891df6..a841a0098342acf33be8ce9c99c169d9d4536bd5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,4 +1,11 @@ <?xml version="1.0" encoding="utf-8"?> + +<!-- +SPDX-FileCopyrightText: Adam Evyčędo + +SPDX-License-Identifier: AGPL-3.0-or-later +--> + <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tool="http://schemas.android.com/tools"> diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/RoundedBackgroundSpan.kt b/app/src/main/java/xyz/apiote/bimba/czwek/RoundedBackgroundSpan.kt index 13a93d42c47db30aa1a50a5bc2fbdfdd2ac8e3ff..de62227e174ece207c25db47a323c7f22bc7a863 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/RoundedBackgroundSpan.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/RoundedBackgroundSpan.kt @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + package xyz.apiote.bimba.czwek import android.graphics.Canvas diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/api/transitous.kt b/app/src/main/java/xyz/apiote/bimba/czwek/api/transitous.kt new file mode 100644 index 0000000000000000000000000000000000000000..4c6e3eeeab7d96968d1041e248f5aa80c61feb91 --- /dev/null +++ b/app/src/main/java/xyz/apiote/bimba/czwek/api/transitous.kt @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +package xyz.apiote.bimba.czwek.api + +import android.content.Context +import android.os.Build +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import xyz.apiote.bimba.czwek.R +import java.io.IOException +import java.net.HttpURLConnection +import java.net.URL + +suspend fun askTransitous(context: Context, json: String): Result { + return withContext(Dispatchers.IO) { + val url = URL("https://routing.spline.de/api/") + val c = (url.openConnection() as HttpURLConnection).apply { + setRequestProperty( + "User-Agent", + "${context.getString(R.string.applicationId)}/${context.getString(R.string.versionName)} (${Build.VERSION.SDK_INT})" + ) + addRequestProperty("Content-Type", "application/json") + requestMethod = "POST" + doOutput = true + outputStream.write(json.toByteArray()) + } + try { + if (c.responseCode == 200) { + Result(c.inputStream, null) + } else { + val (string, image) = mapHttpError(c.responseCode) + Result(c.errorStream, Error(c.responseCode, string, image)) + } + } catch (e: IOException) { + Result(null, Error(0, R.string.error_connecting, R.drawable.error_server)) + } + } +} \ No newline at end of file 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 new file mode 100644 index 0000000000000000000000000000000000000000..ae907d44738c5b7f79e98c31e48bfe6baef69ca5 --- /dev/null +++ b/app/src/main/java/xyz/apiote/bimba/czwek/api/transitousDepartures.kt @@ -0,0 +1,281 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +package xyz.apiote.bimba.czwek.api + +import android.content.Context +import android.util.JsonReader +import android.util.JsonToken +import android.util.Log +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import xyz.apiote.bimba.czwek.R +import xyz.apiote.bimba.czwek.api.responses.ErrorResponse +import xyz.apiote.bimba.czwek.repo.Alert +import xyz.apiote.bimba.czwek.repo.Colour +import xyz.apiote.bimba.czwek.repo.CongestionLevel +import xyz.apiote.bimba.czwek.repo.Departure +import xyz.apiote.bimba.czwek.repo.LineStub +import xyz.apiote.bimba.czwek.repo.LineType +import xyz.apiote.bimba.czwek.repo.OccupancyStatus +import xyz.apiote.bimba.czwek.repo.Position +import xyz.apiote.bimba.czwek.repo.Stop +import xyz.apiote.bimba.czwek.repo.StopDepartures +import xyz.apiote.bimba.czwek.repo.TrafficResponseException +import xyz.apiote.bimba.czwek.repo.Vehicle +import xyz.apiote.bimba.czwek.units.Mps +import java.security.MessageDigest +import java.time.Instant +import java.time.LocalDate +import java.time.ZoneId +import java.time.ZonedDateTime + +@OptIn(ExperimentalStdlibApi::class) +suspend fun getTransitousDepartures( + context: Context, + stop: String, + date: LocalDate?, + limit: Int? +): StopDepartures { + if (!isNetworkAvailable(context)) { + throw TrafficResponseException(0, "", Error(0, R.string.error_offline, R.drawable.error_net)) + } + + // TODO shouldn't it be start-of-day in stop's timezone? + val timestamp = + date?.atStartOfDay(ZoneId.systemDefault())?.toEpochSecond() ?: ZonedDateTime.now() + .toEpochSecond() + + val json = """ + { + "destination": { + "type": "Module", + "target": "/railviz/get_station" + }, + "content_type": "RailVizStationRequest", + "content": { + "station_id": "$stop", + "time": $timestamp, + "event_count": ${limit ?: 12}, + "direction": "LATER", + "by_schedule_time": false + } + } + """ + + val result = askTransitous(context, json) + + if (result.error != null) { + if (result.stream != null) { + val response = withContext(Dispatchers.IO) { ErrorResponse.unmarshal(result.stream) } + throw TrafficResponseException(result.error.statusCode, response.message, result.error) + } else { + throw TrafficResponseException(result.error.statusCode, "", result.error) + } + } else { + return withContext(Dispatchers.IO) { + val departures = mutableListOf<Departure>() + var stopID = "" + var stopName = "" + var latitude = 0.0 + var longitude = 0.0 + val r = JsonReader(result.stream!!.bufferedReader()) + r.withObject { name -> + if (name != "content") { + r.skipValue() + return@withObject + } + r.withObject { name -> + when (name) { + "events" -> { + r.withArray { + var reason = "" + var eventTimestamp: Long = 0 + var valid = false + var tripID = "" + var idLineID = "" + var stationID = "" + var targetStationID = "" + var targetTimestamp = 0 + var idTimestamp = 0 + var trainNr = 0 + var clasz = -1 + var direction = "" + var lineID = "" + var lineName = "" + var lineColour = "" + var eventType = "" + r.withObject { name -> + when (name) { + "event" -> { + r.withObject { name -> + when (name) { + "reason" -> reason = r.nextString() + "schedule_time" -> r.skipValue() + "schedule_track" -> r.skipValue() + "time" -> eventTimestamp = r.nextLong() + "track" -> r.skipValue() + "valid" -> valid = r.nextBoolean() + else -> r.skipValue() + } + } + } + + "trips" -> { + r.withArray { i -> + if (i == 0) { + r.withObject { name -> + when (name) { + "id" -> { + r.withObject { name -> + when (name) { + "id" -> tripID = r.nextString() + "line_id" -> idLineID = r.nextString() + "station_id" -> stationID = r.nextString() + "target_station_id" -> targetStationID = r.nextString() + "target_time" -> targetTimestamp = r.nextInt() + "time" -> idTimestamp = r.nextInt() + "train_nr" -> trainNr = r.nextInt() + else -> r.skipValue() + } + } + } + + "transport" -> { + r.withObject { name -> + Log.d("WithObject", "next is ${name}") + when (name) { + "clasz" -> clasz = r.nextInt() + "direction" -> direction = r.nextString() + "line_id" -> lineID = r.nextString() + "name" -> lineName = r.nextString() + "provider" -> r.skipValue() + "provider_url" -> r.skipValue() + "range" -> r.skipValue() + "route_color" -> lineColour = r.nextString() + "route_text_color" -> r.skipValue() + else -> r.skipValue() + } + } + } + else -> r.skipValue() + } + } + } else { + r.skipValue() + } + } + } + + "type" -> { + eventType = r.nextString() + } + else -> r.skipValue() + } + } + if (eventType == "ARR") { + val hash = MessageDigest.getInstance("SHA-256").let { + it.update(tripID.toByteArray()) + it.update(idLineID.toByteArray()) + it.update(stationID.toByteArray()) + it.update(targetStationID.toByteArray()) + it.update(targetTimestamp.toHexString().toByteArray()) + it.update(idTimestamp.toHexString().toByteArray()) + it.update(trainNr.toHexString().toByteArray()) + it.digest() + }.toHexString() + val t = + ZonedDateTime.ofInstant( + Instant.ofEpochSecond(eventTimestamp), + ZoneId.systemDefault() + ) + departures.add( + Departure( + ID = hash, + time = Time( + t.hour.toUInt(), + t.minute.toUInt(), + t.second.toUInt(), + (t.dayOfYear - ZonedDateTime.now().dayOfYear).toByte(), + ZoneId.systemDefault().id + ), + status = 0u, + isRealtime = reason in setOf("IS", "PROPAGATION", "FORECAST"), + vehicle = Vehicle( + "", + Position(0.0, 0.0), + 0u, + Mps(0), + LineStub( + lineName, + LineType.fromTransitous(clasz), + Colour.fromHex(lineColour) + ), + direction, + CongestionLevel.UNKNOWN, + OccupancyStatus.UNKNOWN + ), + boarding = 0xffu, + alerts = emptyList(), + exact = true, + terminusArrival = !valid + ) + ) + } + } + } + + "station" -> { + r.withObject { name -> + when (name) { + "id" -> stopID = r.nextString() + "name" -> stopName = r.nextString() + "pos" -> { + r.withObject { posName -> + when (posName) { + "lat" -> latitude = r.nextDouble() + "lng" -> longitude = r.nextDouble() + } + } + } + } + } + } + else -> r.skipValue() + } + } + } + + return@withContext StopDepartures( + departures, + Stop(stopID, stopName, stopName, "", "transitous", Position(latitude, longitude), listOf()), + listOf() + ) + } + } +} + +fun JsonReader.withObject(f: (String) -> Unit) { + beginObject() + while (hasNext()) { + try { + f(nextName()) + } catch (e: IllegalStateException) { + val a: JsonToken = this.peek() + Log.d("WithObject", "next is ${a.name} ${nextString()}") + throw e + } + } + endObject() +} + +fun JsonReader.withArray(f: (Int) -> Unit) { + beginArray() + var i = 0 + while (hasNext()) { + f(i) + i++ + } + endArray() +} \ No newline at end of file diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/api/transitousQueryables.kt b/app/src/main/java/xyz/apiote/bimba/czwek/api/transitousQueryables.kt new file mode 100644 index 0000000000000000000000000000000000000000..b76c39cdaf563c228ecbc91128e104282fe603c9 --- /dev/null +++ b/app/src/main/java/xyz/apiote/bimba/czwek/api/transitousQueryables.kt @@ -0,0 +1,194 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +package xyz.apiote.bimba.czwek.api + +import android.content.Context +import android.util.JsonReader +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import xyz.apiote.bimba.czwek.R +import xyz.apiote.bimba.czwek.api.responses.ErrorResponse +import xyz.apiote.bimba.czwek.repo.Position +import xyz.apiote.bimba.czwek.repo.Queryable +import xyz.apiote.bimba.czwek.repo.Stop +import xyz.apiote.bimba.czwek.repo.TrafficResponseException + +suspend fun getTransitousQueryables(query: String, context: Context): List<Queryable> { + if (!isNetworkAvailable(context)) { + throw TrafficResponseException(0, "", Error(0, R.string.error_offline, R.drawable.error_net)) + } + + val json = """ + { + "destination": { + "type": "Module", + "target": "/guesser" + }, + "content_type": "StationGuesserRequest", + "content": { + "input": "$query", + "guess_count": 24 + } + } + """ + val result = askTransitous(context, json) + + if (result.error != null) { + if (result.stream != null) { + val response = withContext(Dispatchers.IO) { ErrorResponse.unmarshal(result.stream) } + throw TrafficResponseException(result.error.statusCode, response.message, result.error) + } else { + throw TrafficResponseException(result.error.statusCode, "", result.error) + } + } else { + return withContext(Dispatchers.IO) { + val queryables = mutableListOf<Queryable>() + val r = JsonReader(result.stream!!.bufferedReader()) + r.beginObject() + while (r.hasNext()) { + val rootFieldName = r.nextName() // content + if (rootFieldName == "content") { + r.beginObject() + r.nextName() // guesses + r.beginArray() + while (r.hasNext()) { + var id = "" + var name = "" + var latitude = 0.0 + var longitude = 0.0 + r.beginObject() + while (r.hasNext()) { + val fieldName = r.nextName() + when (fieldName) { + "id" -> id = r.nextString() + "name" -> name = r.nextString() + "pos" -> { + r.beginObject() + while (r.hasNext()) { + val positionFieldName = r.nextName() + when (positionFieldName) { + "lat" -> latitude = r.nextDouble() + "lng" -> longitude = r.nextDouble() + } + } + r.endObject() + } + } + } + r.endObject() + queryables.add( + Stop( + code = id, + name = name, + nodeName = name, + zone = "", + feedID = "transitous", + position = Position(latitude = latitude, longitude = longitude), + changeOptions = emptyList() + ) + ) + } + r.endArray() + r.endObject() + } else { + r.skipValue() + } + } + r.endObject() + + return@withContext queryables + } + } +} + +suspend fun locateTransitousQueryables(position: Position, context: Context): List<Queryable> { + if (!isNetworkAvailable(context)) { + throw TrafficResponseException(0, "", Error(0, R.string.error_offline, R.drawable.error_net)) + } + + val json = """ + { + "destination": { + "type": "Module", + "target": "/lookup/geo_station" + }, + "content_type": "LookupGeoStationRequest", + "content": { + "max_radius": 500, + "pos": { + "lat": ${position.latitude}, + "lng": ${position.longitude} + } + } + } + """ + val result = askTransitous(context, json) + + if (result.error != null) { + if (result.stream != null) { + val response = withContext(Dispatchers.IO) { ErrorResponse.unmarshal(result.stream) } + throw TrafficResponseException(result.error.statusCode, response.message, result.error) + } else { + throw TrafficResponseException(result.error.statusCode, "", result.error) + } + } else { + return withContext(Dispatchers.IO) { + val queryables = mutableListOf<Queryable>() + val r = JsonReader(result.stream!!.bufferedReader()) + r.beginObject() + while (r.hasNext()) { + val rootFieldName = r.nextName() // content + if (rootFieldName == "content") { + r.beginObject() + r.nextName() // guesses + r.beginArray() + while (r.hasNext()) { + var id = "" + var name = "" + var latitude = 0.0 + var longitude = 0.0 + r.beginObject() + while (r.hasNext()) { + val fieldName = r.nextName() + when (fieldName) { + "id" -> id = r.nextString() + "name" -> name = r.nextString() + "pos" -> { + r.beginObject() + while (r.hasNext()) { + val positionFieldName = r.nextName() + when (positionFieldName) { + "lat" -> latitude = r.nextDouble() + "lng" -> longitude = r.nextDouble() + } + } + r.endObject() + } + } + } + r.endObject() + queryables.add( + Stop( + code = id, + name = name, + nodeName = name, + zone = "", + feedID = "transitous", + position = Position(latitude = latitude, longitude = longitude), + changeOptions = emptyList() + ) + ) + } + r.endArray() + r.endObject() + } else { + r.skipValue() + } + } + r.endObject() + return@withContext queryables + } + } +} \ No newline at end of file diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/api/transitousSettings.kt b/app/src/main/java/xyz/apiote/bimba/czwek/api/transitousSettings.kt new file mode 100644 index 0000000000000000000000000000000000000000..b976816c7ce659a9814b7b8a44dbca884ef30ffd --- /dev/null +++ b/app/src/main/java/xyz/apiote/bimba/czwek/api/transitousSettings.kt @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +package xyz.apiote.bimba.czwek.api + +import android.content.Context +import androidx.preference.PreferenceManager + +fun isTransitousEnabled(context: Context): Boolean { + return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("transitous_enabled", false) +} \ No newline at end of file diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/Favourite.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/Favourite.kt index a24d42ebccfb157547772a58006dcfcb0f561d05..fa0a08da12719f5e4c70a44f5f002a995adbeb45 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/repo/Favourite.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/repo/Favourite.kt @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + package xyz.apiote.bimba.czwek.repo data class Favourite(val sequence: Int?, val feedID: String, val feedName: String, val stopCode: String, val stopName: String, val lines: List<String>) \ No newline at end of file diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/search/geocoder.kt b/app/src/main/java/xyz/apiote/bimba/czwek/search/geocoder.kt index 7fd75e381c417517d76ecd5d8b2f68ac68718d0a..2eedfa8ae0b4b12f54659981d15aac8f1ce531a8 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/search/geocoder.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/search/geocoder.kt @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + package xyz.apiote.bimba.czwek.search import android.content.Context diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/settings/DownloadCitiesWorker.kt b/app/src/main/java/xyz/apiote/bimba/czwek/settings/DownloadCitiesWorker.kt index feb3d2b4e863968a3bd9715c5990bba505205e6f..659958c825ea9c7190bf7ae9e42390cbacac2f06 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/settings/DownloadCitiesWorker.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/settings/DownloadCitiesWorker.kt @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + package xyz.apiote.bimba.czwek.settings import android.Manifest diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/settings/SettingsActivity.kt b/app/src/main/java/xyz/apiote/bimba/czwek/settings/SettingsActivity.kt index 7f75a263c06670675535a7945c4367d2e62a30a1..574631882827027aab7db9264424a46b9f5ae01a 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/settings/SettingsActivity.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/settings/SettingsActivity.kt @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + package xyz.apiote.bimba.czwek.settings import android.content.Context diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/units/TGM.kt b/app/src/main/java/xyz/apiote/bimba/czwek/units/TGM.kt index d99b72fac627db1e05c134ee36112e0a1d2ac798..e08dd2695c1885cb85355d300f2445554a184882 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/units/TGM.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/units/TGM.kt @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + package xyz.apiote.bimba.czwek.units import android.content.Context diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/units/UnitSystem.kt b/app/src/main/java/xyz/apiote/bimba/czwek/units/UnitSystem.kt index 9d0e88c75fc8e29c60f42e938836d8aea33f5b09..3e3f5045e23857de6a6155aceb3a681b7cc66ec3 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/units/UnitSystem.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/units/UnitSystem.kt @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + package xyz.apiote.bimba.czwek.units import android.content.Context diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/units/imperial.kt b/app/src/main/java/xyz/apiote/bimba/czwek/units/imperial.kt index f06ce367fd44750b68a9f8eb3e1a60835d232898..5938c9e483126a316bf0f75ded2db2892d9ab77f 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/units/imperial.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/units/imperial.kt @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + package xyz.apiote.bimba.czwek.units import android.content.Context diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/units/metric.kt b/app/src/main/java/xyz/apiote/bimba/czwek/units/metric.kt index 2f410632b40b89c76a02ad9d6e1f33097c15970e..9ba9250282b2709ea0712489ccf6919f9592ea19 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/units/metric.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/units/metric.kt @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + package xyz.apiote.bimba.czwek.units import android.content.Context diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/units/usCustomary.kt b/app/src/main/java/xyz/apiote/bimba/czwek/units/usCustomary.kt index eb5013c9735a7166f5f822311799e00b4beb072d..b9228f6fd2577b0d9c3eca067940b40e09a639bb 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/units/usCustomary.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/units/usCustomary.kt @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: Adam Evyčędo +// +// SPDX-License-Identifier: AGPL-3.0-or-later + package xyz.apiote.bimba.czwek.units import android.content.Context diff --git a/app/src/main/res/drawable/matrix.xml b/app/src/main/res/drawable/matrix.xml index 54644fae698519a4c776de8dd92c0fd1e3e09053..2e289c80ee9ad890fbadaa99833a0c6de6ad5ecb 100644 --- a/app/src/main/res/drawable/matrix.xml +++ b/app/src/main/res/drawable/matrix.xml @@ -1,3 +1,9 @@ +<!-- +SPDX-FileCopyrightText: Matrix Foundation + +SPDX-License-Identifier: CC0-1.0 +--> + <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="48dp" android:height="48dp" diff --git a/app/src/main/res/drawable/plane_black.xml b/app/src/main/res/drawable/plane_black.xml new file mode 100644 index 0000000000000000000000000000000000000000..57d6132a2c3a543e412d8cda68b03fe36080fd5d --- /dev/null +++ b/app/src/main/res/drawable/plane_black.xml @@ -0,0 +1,11 @@ +<!-- +SPDX-FileCopyrightText: Google + +SPDX-License-Identifier: Apache-2.0 +--> + +<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp"> + + <path android:fillColor="@android:color/white" 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> diff --git a/app/src/main/res/layout/alert.xml b/app/src/main/res/layout/alert.xml index 56819d0fd9f418fd6c0e896db130906251530f78..a1488e4efc5bd06fdb4e6d8f23f1636b9ad07e0a 100644 --- a/app/src/main/res/layout/alert.xml +++ b/app/src/main/res/layout/alert.xml @@ -1,4 +1,11 @@ <?xml version="1.0" encoding="utf-8"?> + +<!-- +SPDX-FileCopyrightText: Adam Evyčędo + +SPDX-License-Identifier: AGPL-3.0-or-later +--> + <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tool="http://schemas.android.com/tools" diff --git a/app/src/main/res/layout/settings_activity.xml b/app/src/main/res/layout/settings_activity.xml index b5b5089cad3cc4480dae8e346bc72ab4d18096c9..d214c5dac728ebb9433d8cc381641595ffa3c6fe 100644 --- a/app/src/main/res/layout/settings_activity.xml +++ b/app/src/main/res/layout/settings_activity.xml @@ -1,3 +1,9 @@ +<!-- +SPDX-FileCopyrightText: Adam Evyčędo + +SPDX-License-Identifier: AGPL-3.0-or-later +--> + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index cf156aef73eedc2bde7a2d851b0b81fcf8842ac1..c710126e20b4f019657300ecb9aa147f18ad8b19 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -1,3 +1,9 @@ +<!-- +SPDX-FileCopyrightText: Adam Evyčędo + +SPDX-License-Identifier: AGPL-3.0-or-later +--> + <resources> <string-array name="unit_entries"> <item>@string/units_locale_based</item> diff --git a/app/src/main/res/xml/locales_config.xml b/app/src/main/res/xml/locales_config.xml index 27e57b55cc383ece2b9d21fa54bca4717eee18c2..52ded369d35deb8e357f2bba5c042a0adc2de048 100644 --- a/app/src/main/res/xml/locales_config.xml +++ b/app/src/main/res/xml/locales_config.xml @@ -1,4 +1,11 @@ <?xml version="1.0" encoding="utf-8"?> + +<!-- +SPDX-FileCopyrightText: Adam Evyčędo + +SPDX-License-Identifier: AGPL-3.0-or-later +--> + <locale-config xmlns:android="http://schemas.android.com/apk/res/android"> <locale android:name="en"/> <locale android:name="pl"/> diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 2127ae46dc0a24e21c53e4cc6fcd662fe492916e..47230fb1e059c9c12699e5d229b2b65e3182d971 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -1,3 +1,9 @@ +<!-- +SPDX-FileCopyrightText: Adam Evyčędo + +SPDX-License-Identifier: AGPL-3.0-or-later +--> + <PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"> <PreferenceCategory app:title="Units"> <ListPreference