Bimba.git

commit 000f62a6fdce6f47f89e8a4e96877b6543f8d8f6

Author: Adam <git@apiote.xyz>

show Line result (but not yet LineActivity)

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


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 b5bb6b933b8b419262ba34b9c615e5956206871d..694be1cd55695d8972808e7d02a6bf6f8b5f5166 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
@@ -189,7 +189,7 @@ 	val Line: LineStubV1,
 	val Headsign: String,
 	val CongestionLevel: ULong,
 	val OccupancyStatus: ULong
-):LocatableV1 {
+) : LocatableV1 {
 	companion object {
 		fun unmarshal(stream: InputStream): VehicleV1 {
 			val reader = Reader(stream)
@@ -216,7 +216,7 @@ 	val Line: LineStubV2,
 	val Headsign: String,
 	val CongestionLevel: ULong,
 	val OccupancyStatus: ULong
-): LocatableV2 {
+) : LocatableV2 {
 	companion object {
 		fun unmarshal(stream: InputStream): VehicleV2 {
 			val reader = Reader(stream)
@@ -379,13 +379,13 @@ 	}
 }
 
 data class LineV1(
+	val name: String,
 	val colour: ColourV1,
-	val type: LineTypeV1,
+	val type: LineTypeV2,
 	val headsignsThere: List<String>,
 	val headsignsBack: List<String>,
 	val graphThere: LineGraph,
-	val graphBack: LineGraph,
-	val name: String
+	val graphBack: LineGraph
 ) : QueryableV2 {
 	override fun toString(): String {
 		return "$name ($type) [$colour]\n→ [${headsignsThere.joinToString()}]\n→ [${headsignsBack.joinToString()}]\n"
@@ -394,6 +394,7 @@
 	companion object {
 		fun unmarshal(stream: InputStream): LineV1 {
 			val reader = Reader(stream)
+			val name = reader.readString()
 			val colour = ColourV1.unmarshal(stream)
 			val type = reader.readUInt()
 			val headsignsThereNum = reader.readUInt().toULong()
@@ -408,11 +409,10 @@ 				headsignsBack.add(reader.readString())
 			}
 			val graphThere = LineGraph.unmarshal(stream)
 			val graphBack = LineGraph.unmarshal(stream)
-			val name = reader.readString()
 			return LineV1(
 				name = name,
 				colour = colour,
-				type = LineTypeV1.of(type.toULong().toUInt()),
+				type = LineTypeV2.of(type.toULong().toUInt()),
 				headsignsThere = headsignsThere,
 				headsignsBack = headsignsBack,
 				graphThere = graphThere,
@@ -436,6 +436,7 @@ 			}
 		}
 	}
 }
+
 enum class LineTypeV2 {
 	UNKNOWN, TRAM, BUS, TROLLEYBUS;
 




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeFragment.kt b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeFragment.kt
index fc0fb193b4865bb66654a39eebbce989761c97d4..4c35c12f9aa56f10dc394cc10fb670ba153b3676 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeFragment.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/home/HomeFragment.kt
@@ -1,7 +1,6 @@
 package xyz.apiote.bimba.czwek.dashboard.ui.home
 
 import android.content.Context
-import android.content.Intent
 import android.net.ConnectivityManager
 import android.os.Bundle
 import android.view.KeyEvent
@@ -19,9 +18,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
 import com.google.android.material.search.SearchView
 import xyz.apiote.bimba.czwek.dashboard.MainActivity
 import xyz.apiote.bimba.czwek.databinding.FragmentHomeBinding
-import xyz.apiote.bimba.czwek.departures.DeparturesActivity
-import xyz.apiote.bimba.czwek.repo.Line
-import xyz.apiote.bimba.czwek.repo.Stop
 import xyz.apiote.bimba.czwek.search.BimbaResultsAdapter
 
 class HomeFragment : Fragment() {
@@ -71,22 +67,7 @@ 		binding.searchBar.setNavigationOnClickListener {
 			(context as MainActivity).onNavigationClicked()
 		}
 		binding.suggestionsRecycler.layoutManager = LinearLayoutManager(activity)
-		adapter = BimbaResultsAdapter(layoutInflater, activity, listOf()) {
-			when (it) {
-				is Stop -> {
-					val intent = Intent(activity, DeparturesActivity::class.java).apply {
-						putExtra("code", it.code)
-						putExtra("name", it.name)
-						putExtra("feedID", it.feedID)
-					}
-					startActivity(intent)
-				}
-
-				is Line -> {
-					TODO("[3.1] start line graph activity")
-				}
-			}
-		}
+		adapter = BimbaResultsAdapter(layoutInflater, activity, listOf())
 		binding.suggestionsRecycler.adapter = adapter
 
 		val cm = requireContext().getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager




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 9430921f4181c3cfabd1614980b6bd15ffdf269e..89db0abb858d11cb2cfa1150591d0ff53eeeb0d5 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
@@ -50,9 +50,7 @@ 			workRunnable = Runnable {
 				val text = s.toString()
 				getQueryables(cm, text, context)
 			}
-			handler.postDelayed(
-				workRunnable, 750
-			) // todo(ux,low) make good time (probably between 500, 1000ms)
+			handler.postDelayed(workRunnable, 750)
 		}
 	}
 }
\ No newline at end of file




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 a65bab7e10741eab719825d59f6d072697641c29..4a59c8cecb274c6136a5d69adc36ece60093d9db 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
@@ -3,16 +3,28 @@
 import android.content.Context
 import android.graphics.drawable.BitmapDrawable
 import android.graphics.drawable.Drawable
+import xyz.apiote.bimba.czwek.api.LineV1
 
 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 name: String
+	val graphBack: 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)
+	)
+
 	fun icon(context: Context, scale: Float = 1f): Drawable {
 		return BitmapDrawable(context.resources, super.icon(context, type, colour, scale))
 	}




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 be4936a4ff66f16c48596e949c4f66cfb3c0192b..026c87d0de0a545a23526f51ddaabf3817784289 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,7 +1,15 @@
 package xyz.apiote.bimba.czwek.repo
 
+import xyz.apiote.bimba.czwek.api.LineGraph
+
 data class LineGraph(
 	val stops: List<StopStub>,
 	val nextNodes: Map<Long, List<Long>>,
 	val prevNodes: Map<Long, List<Long>>
-)
\ No newline at end of file
+) {
+	constructor(lineGraph: LineGraph) : this(
+		lineGraph.stops.map { StopStub(it) },
+		lineGraph.nextNodes,
+		lineGraph.prevNodes
+	)
+}
\ 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 9c19fe0c80e031a4ee9860d434403b56a8e78609..e6ca30739439925c4d8a2612a2528192b204251d 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
@@ -8,6 +8,7 @@ import xyz.apiote.bimba.czwek.api.DeparturesResponse
 import xyz.apiote.bimba.czwek.api.DeparturesResponseDev
 import xyz.apiote.bimba.czwek.api.DeparturesResponseV1
 import xyz.apiote.bimba.czwek.api.ErrorResponse
+import xyz.apiote.bimba.czwek.api.LineV1
 import xyz.apiote.bimba.czwek.api.LocatablesResponse
 import xyz.apiote.bimba.czwek.api.LocatablesResponseDev
 import xyz.apiote.bimba.czwek.api.LocatablesResponseV1
@@ -23,7 +24,6 @@ import xyz.apiote.bimba.czwek.api.VehicleV2
 
 // todo [3.1] in Repository check if responses are BARE or HTML
 
-// todo add feedID
 class OnlineRepository : Repository {
 	override suspend fun getDepartures(
 		cm: ConnectivityManager,
@@ -132,7 +132,7 @@ 				withContext(Dispatchers.IO) { QueryablesResponse.unmarshal(result.stream!!) }) {
 				is QueryablesResponseDev -> response.queryables.map {
 					when (it) {
 						is StopV2 -> Stop(it)
-						// todo[lines] is LineV1 -> Line(it)
+						is LineV1 -> Line(it)
 						else -> TODO("nothing else")
 					}
 				}




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 58ca2abf7862876cb83f360d0fc4d4e33c4c863a..e46afb7ecf6532cdf9a9fe19b6ac7a8c81396717 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
@@ -1,3 +1,12 @@
 package xyz.apiote.bimba.czwek.repo
 
-data class StopStub(val name: String, val code: String, val zone: String, val onDemand: Boolean)
\ No newline at end of file
+import xyz.apiote.bimba.czwek.api.StopStub
+
+data class StopStub(val name: String, val code: String, val zone: String, val onDemand: Boolean) {
+	constructor(stopStub: StopStub) : this(
+		stopStub.name,
+		stopStub.code,
+		stopStub.zone,
+		stopStub.onDemand
+	)
+}
\ No newline at end of file




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 a9790eb7dcecc35710c5bf0b8fccc1f1d6c9c486..9f9cf5bd5d3c68c0af096227670b309341a230eb 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
@@ -2,6 +2,7 @@ package xyz.apiote.bimba.czwek.search
 
 import android.annotation.SuppressLint
 import android.content.Context
+import android.content.Intent
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
@@ -9,6 +10,7 @@ import android.widget.ImageView
 import android.widget.TextView
 import androidx.recyclerview.widget.RecyclerView
 import xyz.apiote.bimba.czwek.R
+import xyz.apiote.bimba.czwek.departures.DeparturesActivity
 import xyz.apiote.bimba.czwek.repo.Line
 import xyz.apiote.bimba.czwek.repo.Queryable
 import xyz.apiote.bimba.czwek.repo.Stop
@@ -28,7 +30,7 @@ 			onClickListener: (Queryable) -> Unit
 		) {
 			when (queryable) {
 				is Stop -> bindStop(queryable, holder, context)
-				//is Line -> bindLine(queryable, holder, context)
+				is Line -> bindLine(queryable, holder, context)
 			}
 			holder?.root?.setOnClickListener {
 				onClickListener(queryable)
@@ -75,9 +77,25 @@ class BimbaResultsAdapter(
 	private val inflater: LayoutInflater,
 	private val context: Context?,
 	private var queryables: List<Queryable>,
-	private val onClickListener: ((Queryable) -> Unit)
 ) :
 	RecyclerView.Adapter<BimbaViewHolder>() {
+	private val onClickListener: ((Queryable) -> Unit) = {
+		when (it) {
+			is Stop -> {
+				val intent = Intent(context, DeparturesActivity::class.java).apply {
+					putExtra("code", it.code)
+					putExtra("name", it.name)
+					putExtra("feedID", it.feedID)
+				}
+				context!!.startActivity(intent)
+			}
+
+			is Line -> {
+				TODO("[3.1] start line graph activity")
+			}
+		}
+	}
+
 	override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BimbaViewHolder {
 		val rowView = inflater.inflate(R.layout.result, parent, false)
 		return BimbaViewHolder(rowView)




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/search/ResultsActivity.kt b/app/src/main/java/xyz/apiote/bimba/czwek/search/ResultsActivity.kt
index 26f6d27c18b9b1c61ae2c615927008a6b5b9b77e..0ee6c08c8d8cde67376458a865b9cf3f44cecf67 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/search/ResultsActivity.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/search/ResultsActivity.kt
@@ -1,7 +1,6 @@
 package xyz.apiote.bimba.czwek.search
 
 import android.content.Context
-import android.content.Intent
 import android.location.Location
 import android.location.LocationListener
 import android.location.LocationManager
@@ -19,13 +18,10 @@ import kotlinx.coroutines.*
 import xyz.apiote.bimba.czwek.R
 import xyz.apiote.bimba.czwek.api.*
 import xyz.apiote.bimba.czwek.databinding.ActivityResultsBinding
-import xyz.apiote.bimba.czwek.departures.DeparturesActivity
 import xyz.apiote.bimba.czwek.repo.ErrorResponseError
-import xyz.apiote.bimba.czwek.repo.Line
 import xyz.apiote.bimba.czwek.repo.OnlineRepository
 import xyz.apiote.bimba.czwek.repo.Position
 import xyz.apiote.bimba.czwek.repo.Queryable
-import xyz.apiote.bimba.czwek.repo.Stop
 
 class ResultsActivity : AppCompatActivity(), LocationListener {
 	enum class Mode {
@@ -46,22 +42,7 @@ 		_binding = ActivityResultsBinding.inflate(layoutInflater)
 		setContentView(binding.root)
 
 		binding.resultsRecycler.layoutManager = LinearLayoutManager(this)
-		adapter = BimbaResultsAdapter(layoutInflater, this, listOf()) {
-			when (it) {
-				is Stop -> {
-					val intent = Intent(this, DeparturesActivity::class.java).apply {
-						putExtra("code", it.code)
-						putExtra("name", it.name)
-						putExtra("feedID", it.feedID)
-					}
-					startActivity(intent)
-				}
-
-				is Line -> {
-					TODO("[3.1] start line graph activity")
-				}
-			}
-		}
+		adapter = BimbaResultsAdapter(layoutInflater, this, listOf())
 		binding.resultsRecycler.adapter = adapter
 		setSupportActionBar(binding.topAppBar)