Bimba.git

commit 84ed24430cd07e422990716112e9a37e4ef14329

Author: Adam <git@apiote.xyz>

show Line result (but not yet LineActivity)

 app/src/main/java/xyz/apiote/bimba/czwek/api/Structs.kt | 83 ++++---
 app/src/main/java/xyz/apiote/bimba/czwek/repo/Line.kt | 40 +++
 app/src/main/java/xyz/apiote/bimba/czwek/repo/LineGraph.kt | 9 
 app/src/main/java/xyz/apiote/bimba/czwek/repo/StopStub.kt | 5 
 app/src/main/java/xyz/apiote/bimba/czwek/search/Results.kt | 8 
 app/src/main/res/values-pl/strings.xml | 2 
 app/src/main/res/values/strings.xml | 4 


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 694be1cd55695d8972808e7d02a6bf6f8b5f5166..c1b231a82b20e4d37216e0e3e9ace145a7dd9908 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
@@ -382,13 +382,38 @@ data class LineV1(
 	val name: String,
 	val colour: ColourV1,
 	val type: LineTypeV2,
-	val headsignsThere: List<String>,
-	val headsignsBack: List<String>,
-	val graphThere: LineGraph,
-	val graphBack: LineGraph
+	val feedID: String,
+	val headsigns: Array<List<String>>,
+	val graphs: Array<LineGraph>,
 ) : QueryableV2 {
 	override fun toString(): String {
-		return "$name ($type) [$colour]\n→ [${headsignsThere.joinToString()}]\n→ [${headsignsBack.joinToString()}]\n"
+		return "$name ($type) [$colour]\n→ [${headsigns[0].joinToString()}]\n→ [${headsigns[0].joinToString()}]\n"
+	}
+
+	override fun equals(other: Any?): Boolean {
+		if (this === other) return true
+		if (javaClass != other?.javaClass) return false
+
+		other as LineV1
+
+		if (name != other.name) return false
+		if (colour != other.colour) return false
+		if (type != other.type) return false
+		if (feedID != other.feedID) return false
+		if (!headsigns.contentEquals(other.headsigns)) return false
+		if (!graphs.contentEquals(other.graphs)) return false
+
+		return true
+	}
+
+	override fun hashCode(): Int {
+		var result = name.hashCode()
+		result = 31 * result + colour.hashCode()
+		result = 31 * result + type.hashCode()
+		result = 31 * result + feedID.hashCode()
+		result = 31 * result + headsigns.contentHashCode()
+		result = 31 * result + graphs.contentHashCode()
+		return result
 	}
 
 	companion object {
@@ -397,15 +422,13 @@ 			val reader = Reader(stream)
 			val name = reader.readString()
 			val colour = ColourV1.unmarshal(stream)
 			val type = reader.readUInt()
-			val headsignsThereNum = reader.readUInt().toULong()
-			val headsignsThere = mutableListOf<String>()
-			for (i in 0UL until headsignsThereNum) {
-				headsignsThere.add(reader.readString())
-			}
-			val headsignsBackNum = reader.readUInt().toULong()
-			val headsignsBack = mutableListOf<String>()
-			for (i in 0UL until headsignsBackNum) {
-				headsignsBack.add(reader.readString())
+			val feedID = reader.readString()
+			val headsigns = arrayOf<List<String>>(mutableListOf(), mutableListOf())
+			for (i in 0..1) {
+				val headsignsNum = reader.readUInt().toULong()
+				for (j in 0UL until headsignsNum) {
+					(headsigns[i] as MutableList).add(reader.readString())
+				}
 			}
 			val graphThere = LineGraph.unmarshal(stream)
 			val graphBack = LineGraph.unmarshal(stream)
@@ -413,10 +436,9 @@ 			return LineV1(
 				name = name,
 				colour = colour,
 				type = LineTypeV2.of(type.toULong().toUInt()),
-				headsignsThere = headsignsThere,
-				headsignsBack = headsignsBack,
-				graphThere = graphThere,
-				graphBack = graphBack
+				feedID = feedID,
+				headsigns = headsigns,
+				graphs = arrayOf(graphThere, graphBack)
 			)
 		}
 	}
@@ -465,8 +487,7 @@ }
 
 data class LineGraph(
 	val stops: List<StopStub>,
-	val nextNodes: Map<Long, List<Long>>,
-	val prevNodes: Map<Long, List<Long>>
+	val nextNodes: Map<Long, List<Long>>
 ) {
 	companion object {
 		fun unmarshal(stream: InputStream): LineGraph {
@@ -487,30 +508,26 @@ 					to.add(reader.readInt().toLong())
 				}
 				nextNodes[from] = to
 			}
-			val prevNodesNum = reader.readUInt().toULong()
-			val prevNodes = mutableMapOf<Long, List<Long>>()
-			for (i in 0UL until prevNodesNum) {
-				val from = reader.readInt().toLong()
-				val toNum = reader.readUInt().toULong()
-				val to = mutableListOf<Long>()
-				for (j in 0UL until toNum) {
-					to.add(reader.readInt().toLong())
-				}
-				prevNodes[from] = to
-			}
 
-			return LineGraph(stops = stops, nextNodes = nextNodes, prevNodes = prevNodes)
+			return LineGraph(stops = stops, nextNodes = nextNodes)
 		}
 	}
 }
 
-data class StopStub(val name: String, val code: String, val zone: String, val onDemand: Boolean) {
+data class StopStub(
+	val code: String,
+	val name: String,
+	val nodeName: String,
+	val zone: String,
+	val onDemand: Boolean
+) {
 	companion object {
 		fun unmarshal(stream: InputStream): StopStub {
 			val reader = Reader(stream)
 			return StopStub(
 				code = reader.readString(),
 				name = reader.readString(),
+				nodeName = reader.readString(),
 				zone = reader.readString(),
 				onDemand = reader.readBoolean()
 			)




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/Line.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/Line.kt
index 4a59c8cecb274c6136a5d69adc36ece60093d9db..55a472675d6a413ebaa288771f2e19a5d24906f9 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/repo/Line.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/repo/Line.kt
@@ -9,23 +9,47 @@ data class Line(
 	val name: String,
 	val colour: Colour,
 	val type: LineType,
-	val headsignsThere: List<String>,
-	val headsignsBack: List<String>,
-	val graphThere: LineGraph,
-	val graphBack: LineGraph
+	val feedID: String,
+	val headsigns: Array<List<String>>,
+	val graphs: Array<LineGraph>,
 ) : Queryable, LineAbstract {
 
 	constructor(line: LineV1) : this(
 		line.name,
 		Colour(line.colour),
 		LineType.of(line.type),
-		line.headsignsThere,
-		line.headsignsBack,
-		LineGraph(line.graphThere),
-		LineGraph(line.graphBack)
+		line.feedID,
+		line.headsigns,
+		line.graphs.map{LineGraph(it)}.toTypedArray()
 	)
 
 	fun icon(context: Context, scale: Float = 1f): Drawable {
 		return BitmapDrawable(context.resources, super.icon(context, type, colour, scale))
+	}
+
+	override fun equals(other: Any?): Boolean {
+		if (this === other) return true
+		if (javaClass != other?.javaClass) return false
+
+		other as Line
+
+		if (name != other.name) return false
+		if (colour != other.colour) return false
+		if (type != other.type) return false
+		if (feedID != other.feedID) return false
+		if (!headsigns.contentEquals(other.headsigns)) return false
+		if (!graphs.contentEquals(other.graphs)) return false
+
+		return true
+	}
+
+	override fun hashCode(): Int {
+		var result = name.hashCode()
+		result = 31 * result + colour.hashCode()
+		result = 31 * result + type.hashCode()
+		result = 31 * result + feedID.hashCode()
+		result = 31 * result + headsigns.contentHashCode()
+		result = 31 * result + graphs.contentHashCode()
+		return result
 	}
 }
\ No newline at end of file




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/LineGraph.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/LineGraph.kt
index 026c87d0de0a545a23526f51ddaabf3817784289..c8c34108be0c167e3bfa1bac52a6492275cf5fd6 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/repo/LineGraph.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/repo/LineGraph.kt
@@ -1,15 +1,16 @@
 package xyz.apiote.bimba.czwek.repo
 
+import android.os.Parcelable
+import kotlinx.parcelize.Parcelize
 import xyz.apiote.bimba.czwek.api.LineGraph
 
+@Parcelize
 data class LineGraph(
 	val stops: List<StopStub>,
 	val nextNodes: Map<Long, List<Long>>,
-	val prevNodes: Map<Long, List<Long>>
-) {
+) : Parcelable {
 	constructor(lineGraph: LineGraph) : this(
 		lineGraph.stops.map { StopStub(it) },
-		lineGraph.nextNodes,
-		lineGraph.prevNodes
+		lineGraph.nextNodes
 	)
 }
\ No newline at end of file




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/StopStub.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/StopStub.kt
index e46afb7ecf6532cdf9a9fe19b6ac7a8c81396717..5fac1fd0c30f08ada1f894d1199a96dc3a703911 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/repo/StopStub.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/repo/StopStub.kt
@@ -2,9 +2,12 @@ package xyz.apiote.bimba.czwek.repo
 
 import xyz.apiote.bimba.czwek.api.StopStub
 
-data class StopStub(val name: String, val code: String, val zone: String, val onDemand: Boolean) {
+@Parcelize
+data class StopStub(val name: String, val nodeName: String, val code: String, val zone: String, val onDemand: Boolean) :
+	Parcelable {
 	constructor(stopStub: StopStub) : this(
 		stopStub.name,
+		stopStub.nodeName,
 		stopStub.code,
 		stopStub.zone,
 		stopStub.onDemand




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 9f9cf5bd5d3c68c0af096227670b309341a230eb..988821e7833eb0b19d611d1410d35925099a73c6 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
@@ -62,12 +62,12 @@ 			}
 			holder?.title?.text = line.name
 			holder?.description?.text = context?.getString(
 				R.string.line_headsigns,
-				line.headsignsThere.joinToString { it },
-				line.headsignsBack.joinToString { it })
+				line.headsigns[0].joinToString { it },
+				line.headsigns[1].joinToString { it })
 			holder?.description?.contentDescription = context?.getString(
 				R.string.line_headsigns_content_description,
-				line.headsignsThere.joinToString { it },
-				line.headsignsBack.joinToString { it })
+				line.headsigns[0].joinToString { it },
+				line.headsigns[1].joinToString { it })
 		}
 	}
 }




diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 44619c46efccbb0288935b313c3f5f121381a488..d2030511c15b7a4599667e790c0e5b051aadc04c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -4,7 +4,7 @@ 	Home
 	<string name="title_map">Map</string>
 	<string name="title_voyage">Voyage</string>
 	<string name="home_fab_description">GPS icon</string>
-	<string name="search_placeholder">Search stops or plus codes</string> <!-- and lines -->
+	<string name="search_placeholder">stops, lines, or plus codes</string> <!-- and lines -->
 	<string name="title_activity_results">Results</string>
 	<string name="cont">Continue</string>
 	<string name="save">Save</string>
@@ -66,7 +66,7 @@ 	USB charging
 	<string name="show_departures">Show departures</string>
 	<string name="open_in_maps_app">Open in maps app</string>
 	<string name="stop_content_description">stop</string>
-	<string name="seatbelts_everyone">Seatbelts, everyone!</string> <!-- taken from ‘Magic School Bus’. Should be translated like in the series -->
+	<string name="seatbelts_everyone">Seatbelts, everyone!</string> <!-- taken from ‘Magic School Bus’. Should be translated like in the series. It’s the first words of the intro song -->
 	<string name="onboarding_question">How would you like to start?</string>
 	<string name="onboarding_simple">Simple</string>
 	<string name="onboarding_simple_action">choose localities</string>




diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml
index 95365f4e60105b11ba1916a1df10055a74ecc0d0..70cb2df3dade94746ec4de9cad9504bae60c0e6a 100644
--- a/app/src/main/res/values-pl/strings.xml
+++ b/app/src/main/res/values-pl/strings.xml
@@ -5,7 +5,7 @@ 	Dom
 	<string name="title_map">Mapa</string>
 	<string name="title_voyage">Podróż</string>
 	<string name="home_fab_description">ikona lokalizacji</string>
-	<string name="search_placeholder">Przeszukuj przystanki lub kody OLC</string>
+	<string name="search_placeholder">przystanki, linie lub kody OLC</string>
 	<string name="title_activity_results">Wyniki</string>
 	<string name="cont">Kontynuuj</string>
 	<string name="save">Zapisz</string>