Bimba.git

commit e72a87d8185dc20f38cdd5b9b8ca421f1d0ee642

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

explain modification

 app/src/main/java/ml/adamsprogs/bimba/gtfs/Trip.kt | 19 -----
 app/src/main/java/ml/adamsprogs/bimba/models/Departure.kt | 9 +
 app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt | 32 ++++----


diff --git a/app/src/main/java/ml/adamsprogs/bimba/gtfs/Trip.kt b/app/src/main/java/ml/adamsprogs/bimba/gtfs/Trip.kt
index e7a45a9ebe4c3f90b1780bafd37b7da814d85441..528c6cfd5afa4a35a9a1b6d4759a99e5584e3146 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/gtfs/Trip.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/gtfs/Trip.kt
@@ -3,24 +3,7 @@
 data class Trip(val routeId: AgencyAndId, val serviceId: AgencyAndId, val id: ID,
                 val headsign: String, val direction: Int, val shapeId: AgencyAndId,
                 val wheelchairAccessible: Boolean) {
-    data class ID(val id: AgencyAndId, val modification: Set<Modification>, val isMain: Boolean) {
+    data class ID(val rawId:String, val id: AgencyAndId, val modification: Set<Modification>, val isMain: Boolean) {
         data class Modification(val id: AgencyAndId, val stopRange: IntRange?)
     }
-
-    val rawId: String
-        get() {
-            val builder = StringBuilder(id.id.toString())
-            id.modification.forEach {
-                builder.append("^")
-                builder.append(it.id)
-                if (it.stopRange != null) {
-                    builder.append(":")
-                    builder.append(it.stopRange.start)
-                    builder.append(it.stopRange.endInclusive)
-                }
-            }
-            if (id.isMain)
-                builder.append("+")
-            return builder.toString()
-        }
 }
\ No newline at end of file




diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/Departure.kt b/app/src/main/java/ml/adamsprogs/bimba/models/Departure.kt
index 4839a43533b9db54f692fccfe6a8f61b4cc18e6b..1d21bc607c0228596af6b0cd6f8f9c8931d77d27 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/Departure.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/Departure.kt
@@ -77,10 +77,15 @@         fun fromString(string: String): Departure {
             val array = string.split("|")
             if (array.size != 9)
                 throw IllegalArgumentException()
+            val modification =
+                    if (array[4] == "")
+                        ArrayList()
+                    else
+                        array[4].split(";")
             return Departure(AgencyAndId.convertFromString(array[0]),
                     array[1].split(";").map { Integer.parseInt(it) },
                     Integer.parseInt(array[2]), array[3] == "true",
-                    array[4].split(";"), array[5], array[6] == "true",
+                    modification, array[5], array[6] == "true",
                     array[7] == "true", array[8] == "true")
         }
     }
@@ -88,7 +93,7 @@
     fun timeTill(relative: Boolean = true): Long {
         val time = Calendar.getInstance().rollTime(this.time)
         var now = Calendar.getInstance()
-        if(!relative)
+        if (!relative)
             now = now.rollTime(0)
         if (this.tomorrow)
             time.add(Calendar.DAY_OF_MONTH, 1)




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 3a6a0597bc8860940c607b5997b06b60cfa8e60c..4abed4644acf22a83679d9416b9c61299ce1719f 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
@@ -266,17 +266,17 @@         mapReader.close()
         throw IllegalArgumentException("Service $serviceId not in store")
     }
 
-    private fun explainModification(trip: Trip, stopSequence: Int): List<String> {
-        return listOf("err")
-        val definitions = getRouteForTrip(trip).modifications
-        val explanations = ArrayList<String>()
+    private fun explainModification(trip: Trip, stopSequence: Int): List<String> { //todo "kurs obsługiwany taborem niskopodłogowym" -> ignore
+        val route = getRouteForTrip(trip)
+        val definitions = route.modifications
 
+        val explanations = ArrayList<String>()
         trip.id.modification.forEach {
             if (it.stopRange != null) {
                 if (stopSequence in it.stopRange)
                     explanations.add(definitions[it.id.id]!!)
             } else {
-                explanations.add(definitions[it.id.id]!!) //fixme null
+                explanations.add(definitions[it.id.id]!!)
             }
         }
 
@@ -284,7 +284,7 @@         return explanations
     }
 
     private fun getRouteForTrip(trip: Trip): Route {
-        val routeId = tripsCache[trip.rawId]!![0]
+        val routeId = tripsCache[trip.id.rawId]!![0]
 
         val tripsFile = File(filesDir, "gtfs_files/routes.txt")
         val mapReader = CsvMapReader(FileReader(tripsFile), CsvPreference.STANDARD_PREFERENCE)
@@ -317,7 +317,7 @@                         type, colour, textColour, modifications)
             }
         }
         mapReader.close()
-        throw IllegalArgumentException("Trip ${trip.rawId} not in store")
+        throw IllegalArgumentException("Trip ${trip.id.rawId} not in store")
     }
 
 //    fun getLinesForStop(stopId: AgencyAndId): Set<AgencyAndId> {
@@ -358,17 +358,19 @@             val isMain = modification[modification.length - 1] == '+'
             if (isMain)
                 modification = modification.subSequence(0, modification.length - 1) as String
             val modifications = HashSet<Trip.ID.Modification>()
-            modification.split(",").forEach {
-                try {
-                    val (id, start, end) = it.split(":")
-                    modifications.add(Trip.ID.Modification(AgencyAndId(id), IntRange(start.toInt(), end.toInt())))
-                } catch (e: Exception) {
-                    modifications.add(Trip.ID.Modification(AgencyAndId(it), null))
+            if (modification != "") {
+                modification.split(",").forEach {
+                    try {
+                        val (id, start, end) = it.split(":")
+                        modifications.add(Trip.ID.Modification(AgencyAndId(id), IntRange(start.toInt(), end.toInt())))
+                    } catch (e: Exception) {
+                        modifications.add(Trip.ID.Modification(AgencyAndId(it), null))
+                    }
                 }
             }
-            return Trip.ID(AgencyAndId(rawId.split("^")[0]), modifications, isMain)
+            return Trip.ID(rawId, AgencyAndId(rawId.split("^")[0]), modifications, isMain)
         } else
-            return Trip.ID(AgencyAndId(rawId), HashSet(), false)
+            return Trip.ID(rawId, AgencyAndId(rawId), HashSet(), false)
     }
 
     fun isEmpty(): Boolean {