Bimba.git

commit 0881a51254b8e4c99cfc0cb990723805f21edb07

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

refreshing cache: stops, and message

 app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt | 3 
 app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt | 5 
 app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt | 13 -
 app/src/main/res/values-de/strings.xml | 1 
 app/src/main/res/values-it/strings.xml | 1 
 app/src/main/res/values-pl/strings.xml | 1 
 app/src/main/res/values/strings.xml | 1 


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 49dcbb5db4881a919b5254e40f1c2e94c70bbdd9..2c898aa2ecf98d97a50a5f2f686167f479e8076c 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
@@ -254,11 +254,12 @@             TimetableDownloader.RESULT_UP_TO_DATE -> getString(R.string.timetable_up_to_date)
             TimetableDownloader.RESULT_VALIDITY_FAILED -> getString(R.string.validity_failed)
             else -> getString(R.string.error_try_later)
         }
+        Snackbar.make(findViewById(R.id.drawer_layout), message, Snackbar.LENGTH_LONG).show()
+        Snackbar.make(findViewById(R.id.drawer_layout), getString(R.string.refreshing_cache), Snackbar.LENGTH_LONG).show()
         if (result == TimetableDownloader.RESULT_DOWNLOADED) {
             timetable.refresh(context)
             stops = timetable.getStops() as ArrayList<StopSuggestion>
         }
-        Snackbar.make(findViewById(R.id.drawer_layout), message, Snackbar.LENGTH_LONG).show()
     }
 
     override fun edit(name: String): Boolean {




diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt
index cf5957bb9d98ae49ece7663ad2923fe1bfcb3e21..6df41f975f15c73a5a74bf640a89f46b93d6d26f 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt
@@ -12,14 +12,11 @@ import android.support.v7.widget.*
 import android.support.v4.app.*
 import android.support.v4.view.*
 import android.support.v4.content.res.ResourcesCompat
-import android.util.Log
 
 import ml.adamsprogs.bimba.models.*
 import ml.adamsprogs.bimba.*
 import kotlin.concurrent.thread
 import kotlinx.android.synthetic.main.activity_stop.*
-
-//check does favourites retain onVM after parcelation? Ie. does it refresh?
 
 class StopActivity : AppCompatActivity(), MessageReceiver.OnVmListener {
 
@@ -83,7 +80,6 @@
         sectionsPagerAdapter = SectionsPagerAdapter(supportFragmentManager, null)
         thread {
             if (sourceType == SOURCE_TYPE_STOP) {
-                Log.i("SQL", "from onCreate")
                 @Suppress("UNCHECKED_CAST")
                 sectionsPagerAdapter!!.departures = Departure.createDepartures(stopId!!) as HashMap<String, ArrayList<Departure>>
             } else {
@@ -155,7 +151,6 @@     }
 
     override fun onVm(vmDepartures: ArrayList<Departure>?, requester: String) {
         if (timetableType == "departure" && requester == REQUESTER_ID && sourceType == SOURCE_TYPE_STOP) {
-            Log.i("SQL", "from onVM")
             @Suppress("UNCHECKED_CAST")
             val fullDepartures = Departure.createDepartures(stopId!!) as HashMap<String, ArrayList<Departure>>
             if (vmDepartures != null) {




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 d5b9a727035db5a1e46534a1690c96f52d389a6d..7bec2461efcac9263d22dc3bd1dc5464c45ceac4 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt
@@ -5,7 +5,6 @@ import android.database.CursorIndexOutOfBoundsException
 import android.database.sqlite.SQLiteCantOpenDatabaseException
 import android.database.sqlite.SQLiteDatabase
 import android.database.sqlite.SQLiteDatabaseCorruptException
-import android.util.Log
 import ml.adamsprogs.bimba.CacheManager
 import java.io.File
 
@@ -61,14 +60,13 @@             throw SQLiteCantOpenDatabaseException("db corrupt")
         }
         this.db = db
 
-        Log.i("SQL", "from refresh")
         cacheManager.recreate(getStopDeparturesByPlates(cacheManager.keys().toSet()))
 
-        //todo recreate stops
+        getStops(true)
     }
 
-    fun getStops(): List<StopSuggestion> {
-        if (_stops != null)
+    fun getStops(force: Boolean = false): List<StopSuggestion> {
+        if (_stops != null && !force)
             return _stops!!
 
         val stops = ArrayList<StopSuggestion>()
@@ -123,7 +121,6 @@                         toGet.add(it)
                     }
                 }
 
-        Log.i("SQL", "from (stop)")
         getStopDeparturesByPlates(toGet).forEach { cacheManager.push(it); plates.add(it) }
 
         return Plate.join(plates)
@@ -155,7 +152,6 @@                 result.add(cacheManager.get(plate)!!)
             else
                 toGet.add(plate)
         }
-        Log.i("SQL", "from (plates)")
 
         getStopDeparturesByPlates(toGet).forEach { cacheManager.push(it); result.add(it) }
 
@@ -178,10 +174,7 @@                 "where " +
                 condition +
                 "order by " +
                 "mode, time;"
-        Log.i("SQL", sql)
         val cursor = db.rawQuery(sql, null)
-
-
 
         while (cursor.moveToNext()) {
             val lineId = cursor.getString(7)




diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 24540c50b4f52056f76e6445b065aee643c9a272..177034ccde1941a01f5c80bd83c7619cc2dae5a9 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -69,4 +69,5 @@     Getting departures…
     <string name="valid_since">Valid since %1$s</string>
     <string name="departure_floor" translatable="false">departure floor type (lowFloor)</string>
     <string name="departure_info" translatable="false">departure info icon</string>
+    <string name="refreshing_cache">Refreshing cache. May take some time…</string>
 </resources>




diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 0bf75fb8428823d450b12fff9fdb1e8bcf20cfdd..cabe97a591e5a5b49262af0aab80be4c0fc16d34 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -57,4 +57,5 @@         "Der offizielle Fahrplan ist vorbereitet besonders für Feiertagen — es wird sich als"
         "heute zeigen (wenn es Dienstag ist, es wird auf „Arbeitstage“ Karte sein).\n"
         "Sei sicher, die Nachrichten auf\nhttps://www.ztm.poznan.pl/en\nkonsultieren.\n\n"
     </string>
+    <string name="refreshing_cache">Cache wird aktualisiert. Es kann einige Zeit dauern…</string>
 </resources>




diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index c5725729dde24238130abb6b13c5dddba42b5260..a1a4b4fdd484920dfb7ae0d4cbe1bf66456a448a 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -55,4 +55,5 @@         "L’orario ufficiale è preparato specialmente per giorni festivi – sarà mostrato come oggi"
         "(se è martedì, sarà nella scheda «giorni di lavoro»).\n"
         "Assicurati di consultare le notifiche su\nhttps://www.ztm.poznan.pl/en.\n\n"
     </string>
+    <string name="refreshing_cache">Cache sta essendo aggiornato. Può richiedere un certo tempo…</string>
 </resources>




diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml
index fcd45d495808aa9f80b0104e9bf71dcb705d0ac5..327158c95ac287d69894bd806ee48caed60981a5 100644
--- a/app/src/main/res/values-pl/strings.xml
+++ b/app/src/main/res/values-pl/strings.xml
@@ -57,4 +57,5 @@         "Pamiętaj, aby sprawdzić aktualności na\nhttps://www.ztm.poznan.pl.\n\n"
     </string>
     <string name="departure_row_getting_departures">Zbieranie odjazdów…</string>
     <string name="valid_since">Ważny od %1$s</string>
+    <string name="refreshing_cache">Odświeżanie pamięci podręcznej. Może chwilę potrwać…</string>
 </resources>
\ No newline at end of file