Bimba.git

commit 16c836581cf303adc064752dba313811be75e0da

Author: Adam Pioterek <adam.pioterek@protonmail.ch>

line suggestion

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


diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
index c81e53dcb5b80eed4e7dceefd4bab4e8bbd0c000..3278af11e13f5f7ab102f9f4d4cd557d6bca5cc1 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
@@ -150,7 +150,7 @@     }
 
     private fun getSuggestions() {
         timetable = Timetable.getTimetable(this)
-        suggestions = timetable.getStopSuggestions(context) //todo get lines, bike stations
+        suggestions = (timetable.getStopSuggestions(context) + timetable.getLineSuggestions()).sorted() //todo + bike stations, &c
     }
 
     private fun prepareListeners() {




diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt b/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
index 03e2eab9477450a925066438b53977be6d01c4cd..9f86876f52865b6f649e12114a1c62485e8872d6 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
@@ -9,6 +9,7 @@ import ml.adamsprogs.bimba.models.gtfs.AgencyAndId
 import ml.adamsprogs.bimba.models.gtfs.Route
 import ml.adamsprogs.bimba.models.gtfs.Trip
 import ml.adamsprogs.bimba.models.gtfs.Calendar
+import ml.adamsprogs.bimba.models.suggestions.LineSuggestion
 import ml.adamsprogs.bimba.models.suggestions.StopSuggestion
 import ml.adamsprogs.bimba.secondsAfterMidnight
 import org.supercsv.cellprocessor.ift.CellProcessor
@@ -81,6 +82,29 @@             }
             StopSuggestion(it.key, it.value, zones[it.key]!!, colour)
         }.sorted()
         return _stops!!
+    }
+
+    fun getLineSuggestions(): List<LineSuggestion> {
+        val routes = ArrayList<LineSuggestion>()
+        val file = File(filesDir, "gtfs_files/routes.txt")
+        val settings = CsvParserSettings()
+        settings.format.setLineSeparator("\r\n")
+        settings.format.quote = '"'
+        settings.isHeaderExtractionEnabled = true
+        val parser = CsvParser(settings)
+        parser.parseAll(file).forEach {
+            routes.add(LineSuggestion(it[2], createRoute(
+                    it[0],
+                    it[1],
+                    it[2],
+                    it[3],
+                    it[4],
+                    Integer.parseInt(it[5]),
+                    Integer.parseInt(it[6], 16),
+                    Integer.parseInt(it[7], 16)
+            )))
+        }
+        return routes.sortedBy { it.name }
     }
 
     fun getHeadlinesForStop(stops: Set<AgencyAndId>): Map<AgencyAndId, Pair<String, Set<String>>> {
@@ -315,21 +339,38 @@                 val desc = routeRow!!["route_desc"] as String
                 val type = Integer.parseInt(routeRow!!["route_type"] as String)
                 val colour = Integer.parseInt(routeRow!!["route_color"] as String, 16)
                 val textColour = Integer.parseInt(routeRow!!["route_text_color"] as String, 16)
-                val (to, from) = desc.split("|")
-                val toSplit = to.split("^")
-                val fromSplit = from.split("^")
-                val description = "${toSplit[0]}|${fromSplit[0]}"
-                val modifications = HashMap<String, String>()
-                toSplit.slice(1 until toSplit.size).forEach {
-                    val (k, v) = it.split(" - ")
-                    modifications[k] = v
-                }
-                return Route(AgencyAndId(id), AgencyAndId(agency), shortName, longName, description,
-                        type, colour, textColour, modifications)
+                return createRoute(id, agency, shortName, longName, desc, type, colour, textColour)
             }
         }
         mapReader.close()
         throw IllegalArgumentException("Trip ${trip.id.rawId} not in store")
+    }
+
+    private fun createRoute(id: String, agency: String, shortName: String, longName: String,
+                            desc: String, type: Int, colour: Int, textColour: Int): Route {
+        if (desc.contains("|")) {
+            val (to, from) = desc.split("|")
+            val fromSplit = from.split("^")
+            val toSplit = to.split("^")
+            val description = "${toSplit[0]}|${fromSplit[0]}"
+            val modifications = HashMap<String, String>()
+            toSplit.slice(1 until toSplit.size).forEach {
+                val (k, v) = it.split(" - ")
+                modifications[k] = v
+            }
+            return Route(AgencyAndId(id), AgencyAndId(agency), shortName, longName, description,
+                    type, colour, textColour, modifications)
+        } else {
+            val toSplit = desc.split("^")
+            val description = toSplit[0]
+            val modifications = HashMap<String, String>()
+            toSplit.slice(1 until toSplit.size).forEach {
+                val (k, v) = it.split(" - ")
+                modifications[k] = v
+            }
+            return Route(AgencyAndId(id), AgencyAndId(agency), shortName, longName, description,
+                    type, colour, textColour, modifications)
+        }
     }
 
 //    fun getLinesForStop(stopId: AgencyAndId): Set<AgencyAndId> {




diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/GtfsSuggestion.kt b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/GtfsSuggestion.kt
index 1fad7990dce4990d592b0cc17c9afec488b85a4d..edabd07aa75d649c2fd94f1d63497f7e3315d50f 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/GtfsSuggestion.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/GtfsSuggestion.kt
@@ -2,6 +2,6 @@ package ml.adamsprogs.bimba.models.suggestions
 
 import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion
 
-abstract class GtfsSuggestion(val name: String) : SearchSuggestion {
+abstract class GtfsSuggestion(val name: String) : SearchSuggestion, Comparable<GtfsSuggestion> {
     abstract fun getIcon(): Int
 }
\ No newline at end of file




diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/LineSuggestion.kt b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/LineSuggestion.kt
index 6975aea52f83aa7a8a3b744b991369eff47fcc94..5ad33995325f29d99cec71f072f9d8e1331c3747 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/LineSuggestion.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/LineSuggestion.kt
@@ -31,6 +31,12 @@     override fun getBody(): String {
         return name
     }
 
+    override fun compareTo(other: GtfsSuggestion): Int {
+        return if (other is LineSuggestion)
+            name.toInt().compareTo(other.name.toInt())
+        else
+            name.compareTo(other.name)
+    }
 
     companion object CREATOR : Parcelable.Creator<LineSuggestion> {
         override fun createFromParcel(parcel: Parcel): LineSuggestion {




diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/StopSuggestion.kt b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/StopSuggestion.kt
index 4f2a5ceb3c32de379ed2cf45be05bfa8f5b9551e..d0fbe0272348a38a004b1211de5aeed2c8ee5202 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/StopSuggestion.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/suggestions/StopSuggestion.kt
@@ -5,7 +5,7 @@ import android.os.Parcelable
 import ml.adamsprogs.bimba.R
 import ml.adamsprogs.bimba.models.gtfs.AgencyAndId
 
-class StopSuggestion(name: String, val ids: Set<AgencyAndId>, private val zone: String, private val zoneColour: String) : GtfsSuggestion(name), Comparable<StopSuggestion> {
+class StopSuggestion(name: String, val ids: Set<AgencyAndId>, private val zone: String, private val zoneColour: String) : GtfsSuggestion(name){
     @Suppress("UNCHECKED_CAST")
     constructor(parcel: Parcel) : this(parcel.readString(), parcel.readString().split(",").map { AgencyAndId(it) }.toSet(), parcel.readString(), parcel.readString())
 
@@ -28,7 +28,7 @@     override fun getIcon(): Int {
         return R.drawable.ic_stop
     }
 
-    override fun compareTo(other: StopSuggestion): Int {
+    override fun compareTo(other: GtfsSuggestion): Int {
         return name.compareTo(other.name)
     }
 




diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6e4c6f496a82be3eee9b13139e06baea5ac15c9f..61c43b38e2e9e29a8f944db933f85064b7951fda 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -15,7 +15,7 @@     no database background
     <string name="no_db_connect">Connect to the Internet to download the timetable</string>
     <string name="no_db_downloading">Timetable is being downloaded…</string>
     <string name="timetable_downloading">Downloading timetable</string>
-    <string name="search_placeholder">Search for a stop…</string>
+    <string name="search_placeholder">Stop or line…</string>
     <string name="no_connectivity">No connectivity – can’t update timetable</string>
     <string name="timetable_up_to_date">Timetable is up-to-date</string>
     <string name="validity_failed">Downloaded timetable is corrupted – can’t update</string>




diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 06a9df684010f6264c275f6113ac28c95cde4e0b..47931966e5b73c7c0d12fb83d3f3d9db1c04dc8b 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -16,7 +16,7 @@     Typ
     <string name="no_db_connect">Verbind mit dem Internet um zu den Fahrplan herunterladen</string>
     <string name="no_db_downloading">Fahrplan wird heruntergeladen…</string>
     <string name="timetable_downloading">Fahrplan wird heruntergeladen</string>
-    <string name="search_placeholder">Suche für Haltestelle…</string>
+    <string name="search_placeholder">Haltestelle oder Linie…</string>
     <string name="no_connectivity">Kein Verbindung – kann nicht den Fahrplan aktualisieren</string>
     <string name="timetable_up_to_date">Fahrplan ist aktuell</string>
     <string name="validity_failed">Der heruntergeladene Fahrplan ist geschädigt – kann nicht aktualisieren</string>




diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index f521f9def826aa47e427231290bd60edb270d624..295db1ba832686cee8de8844985921d37884e14b 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -19,7 +19,7 @@     Tipo
     <string name="no_db_connect">Connetti a Internet per scaricare l’orario</string>
     <string name="no_db_downloading">L’orario è stando scaricato</string>
     <string name="timetable_downloading">Scaricando l’orario</string>
-    <string name="search_placeholder">Cerca una fermata…</string>
+    <string name="search_placeholder">Fermata o linea…</string>
     <string name="no_connectivity">Nessuna connettività – non si riesce aggiornare l’orario</string>
     <string name="timetable_up_to_date">L’orario sta aggiornato</string>
     <string name="validity_failed">L’orario scaricato sta corrotto – non si riesce aggiornare</string>




diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml
index 7066cf0963d1e83859e531ced178e3abee0b4762..281bf8230bdb6dcb656d1d019b3502a76309f29d 100644
--- a/app/src/main/res/values-pl/strings.xml
+++ b/app/src/main/res/values-pl/strings.xml
@@ -11,7 +11,7 @@     → %1$s
     <string name="no_db_connect">Połącz się z Internetem aby pobrać rozkład</string>
     <string name="no_db_downloading">Pobieranie rozkładu…</string>
     <string name="timetable_downloading">Pobieranie rozkładu…</string>
-    <string name="search_placeholder">Szukaj przystanku…</string>
+    <string name="search_placeholder">Przystanek lub linia…</string>
     <string name="timetable_up_to_date">Rozkład jest aktualny</string>
     <string name="validity_failed">Pobrany rozkład jest uszkodzony – nie można zaktualizować</string>
     <string name="no_connectivity">Brak połączenia z Internetem – nie można zaktualizować rozkładu</string>