Bimba.git

commit 724ddb1af33d71885b5bf73ff1953a4ef9e753fd

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

Downloadinf timetable as new and then swapping

%!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 57cfa34269959a7d8366d5dba4979cb0b9378c4c..2134f12397b6378e7fc50ec698b48a11e3a33f88 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
@@ -84,8 +84,8 @@         }
 
         val validSince = timetable.getValidSince()
         val validTill = timetable.getValidTill()
-        drawerView.menu.findItem(R.id.drawer_validity_since).title = getString(R.string.valid_since, validSince)
-        drawerView.menu.findItem(R.id.drawer_validity_till).title = getString(R.string.valid_till, validTill)
+        drawerView.menu.findItem(R.id.drawer_validity_since).title = getString(R.string.valid_since, validSince) //todo date format
+        drawerView.menu.findItem(R.id.drawer_validity_till).title = getString(R.string.valid_till, validTill) //todo date format
 
         searchView = search_view
 
@@ -282,6 +282,7 @@             else -> getString(R.string.error_try_later)
         }
         Snackbar.make(findViewById(R.id.drawer_layout), message, Snackbar.LENGTH_LONG).show()
         if (result == TimetableDownloader.RESULT_FINISHED) {
+            timetable = Timetable.getTimetable(this, true)
             getSuggestions()
 
             drawerView.menu.findItem(R.id.drawer_validity_since).title = getString(R.string.valid_since, timetable.getValidSince())




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 ec07e8287e99776930285e6639bdf06a5d226789..46e05f2a8bc7c1fde6b1a96c31d1ea21e6dc41a3 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt
@@ -76,7 +76,7 @@
             notify(0, R.string.timetable_downloading, R.string.timetable_uncompressing, sizeCompressed, sizeUncompressed)
 
 
-            val gtfsDb = File(getSecondaryExternalFilesDir(), "timetable.db")
+            val gtfsDb = File(getSecondaryExternalFilesDir(), "timetable_new.db")
 
             val inputStream = httpCon.inputStream
             val gzipInputStream = GZIPInputStream(inputStream)
@@ -89,6 +89,9 @@
             val prefsEditor = prefs.edit()
             prefsEditor.putString("etag", newETag)
             prefsEditor.apply()
+
+            val oldDb = File(getSecondaryExternalFilesDir(), "timetable.db")
+            gtfsDb.renameTo(oldDb) // todo delete old before downloading (may require stopping VmClient)
 
             cancelNotification()