Author: Adam Pioterek <adam.pioterek@protonmail.ch>
timetable downloading notification
%!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 6f88678004f21be61fcca03fb9c0ec650d1f7a65..7fcb3e1ac4c36f0e0bcafc7fcc995bb468e920c7 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 @@ val newETag = httpCon.getHeaderField("ETag") sizeCompressed = httpCon.getHeaderField("Content-Length").toInt() / 1024 sizeUncompressed = httpCon.getHeaderField("X-Uncompressed-Content-Length").toInt() / 1024 - notify(0, R.string.timetable_downloading, R.string.timetable_uncompressing, sizeCompressed, sizeUncompressed) + notify(0, R.string.timetable_downloading, R.string.timetable_downloading_progress, R.string.timetable_decompressing, sizeCompressed, sizeUncompressed) val gtfsDb = File(getSecondaryExternalFilesDir(), "timetable_new.db") @@ -86,7 +86,7 @@ val gzipInputStream = GZIPInputStream(inputStream) val outputStream = FileOutputStream(gtfsDb) gzipInputStream.listenableCopyTo(outputStream) { - notify((it / 1024).toInt(), R.string.timetable_downloading, R.string.timetable_uncompressing, sizeCompressed, sizeUncompressed) + notify((it / 1024).toInt(), R.string.timetable_downloading, R.string.timetable_downloading_progress, R.string.timetable_decompressing, sizeCompressed, sizeUncompressed) } val prefsEditor = prefs.edit() @@ -110,16 +110,21 @@ broadcastIntent.putExtra(EXTRA_RESULT, result) sendBroadcast(broadcastIntent) } - private fun notify(progress: Int, titleId: Int, messageId: Int, sizeCompressed: Int, sizeUncompressed: Int) { - /*val quotient = sizeCompressed.toFloat() / sizeUncompressed.toFloat() - val message = getString(messageId, Math.max(progress * quotient, sizeCompressed.toFloat()), - sizeCompressed, ((progress.toFloat() / sizeUncompressed.toFloat()) * 100)) fixme<p:2> format error*/ - val message = "" - val title = getString(titleId) + private fun notify(downloadedKBytes: Int, titleId: Int, dwdMessageId: Int, dcmMessageId: Int, sizeCompressed: Int, sizeUncompressed: Int) { + val progress = Math.min(downloadedKBytes, sizeCompressed) + val message = if (progress < sizeCompressed) + getString(dwdMessageId, + progress / 1024F, sizeCompressed / 1024F) + else + "" + val title = if (progress < sizeCompressed) + getString(titleId) + else + getString(dcmMessageId) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) - notifyCompat(progress, title, message, sizeUncompressed) + notifyCompat(downloadedKBytes, title, message, sizeUncompressed) else - notifyStandard(progress, title, message, sizeUncompressed) + notifyStandard(downloadedKBytes, title, message, sizeUncompressed) } @Suppress("DEPRECATION") diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e3a8b50047e42052f159d3529e703a103518d6a0..59bae428d441c18d3f8b73074d7e738ee2d1c448 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,7 +15,8 @@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="timetable_uncompressing">%1$d/%2$d, uncompressing: %3$f%</string> + <string name="timetable_downloading_progress" translatable="false">%1$1.2f MiB/%2$1.2f MiB</string> + <string name="timetable_decompressing">Decompressing timetable</string> <string name="search_placeholder">Stop…</string> <string name="no_connectivity">No connectivity – can’t update timetable</string> <string name="timetable_up_to_date">Timetable is up-to-date</string> @@ -84,7 +85,7 @@Timetable validity ends tomorrow. <string name="just_departed">Just departed</string> <string name="validity_offline_unavailable">Offline timetable unavailable</string> <string name="pref_category_timetable">Timetable</string> - <string name="timetable_source_url" translatable="false">http://bimba.tk/gtfs</string> + <string name="timetable_source_url" translatable="false">https://bimba.tk/gtfs</string> <string name="key_timetable_source_url" translatable="false">key_timetable_source_url</string> <string name="title_timetable_source_url">Timetable source</string> <string name="title_activity_settings">Settings</string> diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 7fb73d0a01547683f4570520d350ab9d7ae9fcf4..74a1403bc6cf2643facca4506c5f1b23cd015a27 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -67,10 +67,10 @@Fahrplan gilt nur bis heute. <string name="timetable_validity_finished">Die Gültigkeit des Zeitplans ist beendet. Verbind mit dem Internet, um eine neue herunterzuladen und um fortzufahren.</string> <string name="timetable_validity_tomorrow">Fahrplan gilt nur bis morgen.</string> <string name="just_departed">Gerade gegangen</string> - <string name="timetable_uncompressing">%1$d/%2$d, dekompression: %3$f%</string> <string name="validity_offline_unavailable">Offline-Fahrplan ist nicht verfügbar</string> <string name="pref_category_timetable">Fahrplan</string> <string name="title_timetable_source_url">Quelle des Fahrplans</string> <string name="title_activity_settings">Einstellungen</string> <string name="settings">Einstellungen</string> + <string name="timetable_decompressing">Fahrplan wird entpackt</string> </resources> diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 1a1526712f99734b218ab768630570b5db20e6d1..e18d6d65bf573b10800637ce426adbf393ea9bda 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -65,10 +65,10 @@L’orario è valido solo fino ad oggi. <string name="timetable_validity_finished">"La validità dell’orario è terminata. Connetti a Internet per scaricarne uno nuovo e continuare. "</string> <string name="timetable_validity_tomorrow">L’orario è valido solo fino a domani.</string> <string name="just_departed">Appena partito</string> - <string name="timetable_uncompressing">%1$d/%2$d, decompressione: %3$f%</string> <string name="validity_offline_unavailable">L’orario offline non è disponibile</string> <string name="pref_category_timetable">Orario</string> <string name="title_timetable_source_url">Fonte dell’Orario</string> <string name="title_activity_settings">Impostazioni</string> <string name="settings">Impostazioni</string> + <string name="timetable_decompressing">Decomprimendo l’orario</string> </resources> diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 6cd7cb5405c52d4986e2135442f806bf588ba6ff..3693fadac99d212054a413ec878bf37f093d5c77 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -11,7 +11,6 @@Op %1$s <string name="no_db_connect">Maak verbinding met internet om de dienstregeling te downloaden.</string> <string name="no_db_downloading">De dienstregeling wordt gedownload…</string> <string name="timetable_downloading">Bezig met downloaden van dienstregeling</string> - <string name="timetable_uncompressing">%1$d/%2$d, bezig met uitpakken: %3$f%</string> <string name="search_placeholder">Halte…</string> <string name="no_connectivity">Geen internetverbinding – de dienstregeling kan niet worden bijgewerkt.</string> <string name="timetable_up_to_date">De dienstregeling is volledig bijgewerkt.</string> @@ -74,4 +73,5 @@Dienstregeling <string name="title_timetable_source_url">Bron van de dienstregeling</string> <string name="title_activity_settings">Instellingen</string> <string name="settings">Instellingen</string> + <string name="timetable_decompressing">Bezig met uitpakken van dienstregeling</string> </resources> diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index ed5b2634c76a2f74ad1ec86a3dd1e467a81c0922..15370f10365138c4426f4c71c7ab5af1bc7370b0 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -10,7 +10,7 @@O %1$s <string name="departure_to">→ %1$s</string> <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="timetable_downloading">Pobieranie rozkładu</string> <string name="search_placeholder">Przystanek…</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> @@ -67,10 +67,10 @@Rozkład obowiązuje tylko do dzisiaj. <string name="timetable_validity_finished">Rozkład przestał obowiązywać. Połącz się z Internetem, aby pobrać nowy i kontynuować.</string> <string name="timetable_validity_tomorrow">Rozkład obowiązuje tylko do jutra.</string> <string name="just_departed">Właśnie odjechał</string> - <string name="timetable_uncompressing">%1$d/%2$d, dekompresja: %3$f%</string> <string name="validity_offline_unavailable">Rozkład offline jest niedostępny</string> <string name="pref_category_timetable">Rozkład</string> <string name="title_timetable_source_url">Źródło rozkładu</string> <string name="title_activity_settings">Ustawienia</string> <string name="settings">Ustawienia</string> + <string name="timetable_decompressing">Rozpakowywanie rozkładu</string> </resources> \ No newline at end of file