Bimba.git

commit bbe9c621a38627a8ce44ee46045f586b8e44704c

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

fixed downloading timetable

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


diff --git a/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt b/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt
index 1e90a23b1acc8a3901d25ef6981299ad1079ee91..43abad683f14f6a998d82ad52533142e37288077 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt
@@ -41,15 +41,13 @@
             var httpCon: HttpURLConnection
             try {
                 val sourceUrl = getDefaultSharedPreferences(this).getString(getString(R.string.key_timetable_source_url), getString(R.string.timetable_source_url))
+                sourceUrl.replace(Regex("^.*://", RegexOption.IGNORE_CASE), "")
+                val url = URL(sourceUrl)
                 try {
-                    if (!sourceUrl.matches(Regex("^https://.*$")))
-                        throw SSLException("Not https address")
-                    val url = URL(sourceUrl)
                     httpCon = url.openConnection() as HttpsURLConnection
                     httpCon.addRequestProperty("If-None-Match", localETag)
                     httpCon.connect()
                 } catch (e: SSLException) {
-                    val url = URL(sourceUrl.replace("https://", "http://"))
                     httpCon = url.openConnection() as HttpURLConnection
                     httpCon.addRequestProperty("If-None-Match", localETag)
                     httpCon.connect()




diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt b/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt
index 066091d80e19d3e01ae91d4914a28ab4758ad537..37e9fd76ff8f73dee734041f05d219d4fb26a665 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt
@@ -55,11 +55,6 @@
         val mapString = mapDir.readText()
         val ile = mapString.length / 1024
 
-        for (i in 0 until ile) {
-            println(mapString.slice(1024 * i until 1024 * (i+1)))
-        }
-
-        println(mapString)
         val map = HashMap<AgencyAndId, List<Departure>>()
         mapString.safeSplit("%").forEach {
             val (k, v) = it.split("#")




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 2f90bc4c61040997a02a5a7a4c227b27854a96e1..ceed419ddda0ed2bca34443399301c56f5818792 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
@@ -37,7 +37,7 @@         private fun constructTimetable(context: Context) {
             val timetable = Timetable()
             val filesDir = context.getSecondaryExternalFilesDir()
             val dbFile = File(filesDir, "timetable.db")
-            timetable.db = SQLiteDatabase.openDatabase(dbFile.path, null, SQLiteDatabase.OPEN_READONLY)
+            timetable.db = SQLiteDatabase.openDatabase(dbFile.path, null, SQLiteDatabase.OPEN_READONLY) // fixme can be null
             this.timetable = timetable
         }
     }




diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/adapters/DeparturesAdapter.kt b/app/src/main/java/ml/adamsprogs/bimba/models/adapters/DeparturesAdapter.kt
index fce1683f0fddeeefd30ec9ce69e2bc938bddc237..d9b1c1d14fdedf06307fcc8ef23a54ff6a58c478 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/adapters/DeparturesAdapter.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/adapters/DeparturesAdapter.kt
@@ -58,7 +58,6 @@             time.text = context.getString(R.string.no_departures)
             return
         }
         val departure = departures[position]
-        //println("${departure.line} -> ${departure.headsign} @${departure.time} (${if (departure.isModified) departure.modification[0] else {}})")
         val now = Calendar.getInstance()
         val departureTime = Calendar.getInstance().rollTime(departure.time)
         if (departure.tomorrow)