From 8ea163b439bc16a632a736028a2093b06d7aa6b9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 25 Jul 2017 18:48:53 +0200 Subject: [PATCH] show an error toast when something goes wrong at uploading an event --- .../calendar/helpers/GoogleSyncHandler.kt | 27 ++++++++++++++----- .../calendar/models/GoogleError.kt | 3 +++ app/src/main/res/values-de/strings.xml | 3 +++ app/src/main/res/values-es/strings.xml | 3 +++ app/src/main/res/values-fr/strings.xml | 3 +++ app/src/main/res/values-hi-rIN/strings.xml | 3 +++ app/src/main/res/values-hu/strings.xml | 5 +++- app/src/main/res/values-it/strings.xml | 3 +++ app/src/main/res/values-iw/strings.xml | 3 +++ app/src/main/res/values-ja/strings.xml | 3 +++ app/src/main/res/values-pt-rBR/strings.xml | 3 +++ app/src/main/res/values-pt/strings.xml | 3 +++ app/src/main/res/values-ru/strings.xml | 3 +++ app/src/main/res/values-sk/strings.xml | 3 +++ app/src/main/res/values-sv/strings.xml | 3 +++ app/src/main/res/values-tr/strings.xml | 3 +++ app/src/main/res/values/strings.xml | 3 +++ 17 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/models/GoogleError.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/GoogleSyncHandler.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/GoogleSyncHandler.kt index 85d3e0e07..c2e4c7f08 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/GoogleSyncHandler.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/GoogleSyncHandler.kt @@ -1,26 +1,31 @@ package com.simplemobiletools.calendar.helpers -import android.content.Context +import android.widget.Toast import com.google.api.services.calendar.model.EventDateTime import com.google.api.services.calendar.model.EventReminder +import com.google.gson.Gson +import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.activities.SimpleActivity import com.simplemobiletools.calendar.extensions.getGoogleSyncService import com.simplemobiletools.calendar.extensions.isGoogleSyncActive import com.simplemobiletools.calendar.extensions.isOnline import com.simplemobiletools.calendar.models.Event +import com.simplemobiletools.calendar.models.GoogleError +import com.simplemobiletools.commons.extensions.toast import java.util.* class GoogleSyncHandler { - fun uploadToGoogle(context: Context, event: Event) { - if (context.isGoogleSyncActive()) { - if (context.isOnline()) { + fun uploadToGoogle(activity: SimpleActivity, event: Event) { + if (activity.isGoogleSyncActive()) { + if (activity.isOnline()) { Thread({ - createRemoteGoogleEvent(context, event) + createRemoteGoogleEvent(activity, event) }).start() } } } - private fun createRemoteGoogleEvent(context: Context, event: Event) { + private fun createRemoteGoogleEvent(activity: SimpleActivity, event: Event) { try { com.google.api.services.calendar.model.Event().apply { summary = event.title @@ -45,7 +50,15 @@ class GoogleSyncHandler { reminders = getEventReminders(event).setUseDefault(false) } - context.getGoogleSyncService().events().insert(PRIMARY, this).execute() + try { + activity.getGoogleSyncService().events().insert(PRIMARY, this).execute() + } catch (e: Exception) { + val message = e.message!! + val json = message.substring(message.indexOf('{')) + val error = Gson().fromJson(json, GoogleError::class.java) + val msg = String.format(activity.getString(R.string.google_sync_error_insert), error.message) + activity.toast(msg, Toast.LENGTH_LONG) + } } } catch (ignored: Exception) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/models/GoogleError.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/models/GoogleError.kt new file mode 100644 index 000000000..1f5cd41cd --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/models/GoogleError.kt @@ -0,0 +1,3 @@ +package com.simplemobiletools.calendar.models + +data class GoogleError(val message: String) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 26d166867..7c026fc0d 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -190,9 +190,12 @@ Postpone reminder with Snooze by Widgets You cannot do that while offline. + + Google sync is in a testing mode, please be cautions when relying on it. Reporting any feedback at hello@simplemobiletools.com would be appreciated. Thanks! Send locally created events to the cloud? Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Error uploading event: %1$s %1$d minute diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index b997d42da..17835cd9a 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -190,9 +190,12 @@ Postpone reminder with Snooze by Widgets You cannot do that while offline. + + Google sync is in a testing mode, please be cautions when relying on it. Reporting any feedback at hello@simplemobiletools.com would be appreciated. Thanks! Send locally created events to the cloud? Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Error uploading event: %1$s %1$d minute diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index b57498ee3..c629b6057 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -190,9 +190,12 @@ Postpone reminder with Snooze by Widgets You cannot do that while offline. + + Google sync is in a testing mode, please be cautions when relying on it. Reporting any feedback at hello@simplemobiletools.com would be appreciated. Thanks! Send locally created events to the cloud? Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Error uploading event: %1$s %1$d minute diff --git a/app/src/main/res/values-hi-rIN/strings.xml b/app/src/main/res/values-hi-rIN/strings.xml index db14db958..601412c28 100644 --- a/app/src/main/res/values-hi-rIN/strings.xml +++ b/app/src/main/res/values-hi-rIN/strings.xml @@ -190,9 +190,12 @@ Postpone reminder with Snooze by Widgets You cannot do that while offline. + + Google sync is in a testing mode, please be cautions when relying on it. Reporting any feedback at hello@simplemobiletools.com would be appreciated. Thanks! Send locally created events to the cloud? Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Error uploading event: %1$s %1$d minute diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index d720c8837..f4e4d04b2 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -190,9 +190,12 @@ Postpone reminder with Snooze by Widgets You cannot do that while offline. + + Google sync is in a testing mode, please be cautions when relying on it. Reporting any feedback at hello@simplemobiletools.com would be appreciated. Thanks! Send locally created events to the cloud? - Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Disabli + Error uploading event: %1$sng Google sync will delete all synced events from your device, while leaving them intact in the cloud. %1$d minute diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index fe8bdcb90..a8c91754e 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -190,9 +190,12 @@ Postpone reminder with Snooze by Widgets You cannot do that while offline. + + Google sync is in a testing mode, please be cautions when relying on it. Reporting any feedback at hello@simplemobiletools.com would be appreciated. Thanks! Send locally created events to the cloud? Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Error uploading event: %1$s %1$d minute diff --git a/app/src/main/res/values-iw/strings.xml b/app/src/main/res/values-iw/strings.xml index eba6f5625..8ec171983 100644 --- a/app/src/main/res/values-iw/strings.xml +++ b/app/src/main/res/values-iw/strings.xml @@ -190,9 +190,12 @@ Postpone reminder with Snooze by Widgets You cannot do that while offline. + + Google sync is in a testing mode, please be cautions when relying on it. Reporting any feedback at hello@simplemobiletools.com would be appreciated. Thanks! Send locally created events to the cloud? Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Error uploading event: %1$s %1$d minute diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index b715bf31a..fafb74beb 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -190,9 +190,12 @@ Postpone reminder with Snooze by Widgets You cannot do that while offline. + + Google sync is in a testing mode, please be cautions when relying on it. Reporting any feedback at hello@simplemobiletools.com would be appreciated. Thanks! Send locally created events to the cloud? Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Error uploading event: %1$s %1$d minute diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 86ef7c876..00ea6de45 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -190,9 +190,12 @@ Postpone reminder with Snooze by Widgets You cannot do that while offline. + + Google sync is in a testing mode, please be cautions when relying on it. Reporting any feedback at hello@simplemobiletools.com would be appreciated. Thanks! Send locally created events to the cloud? Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Error uploading event: %1$s %1$d minute diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index e5bd23767..13a87e3d7 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -190,9 +190,12 @@ Adiar lembrete com a opção Snooze Widgets You cannot do that while offline. + + A sincronização Google ainda não está terminada. Reporte os erros encontrados para hello@simplemobiletools.com. Obrigado! Send locally created events to the cloud? Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Error uploading event: %1$s %1$d minuto diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 8497af17f..980d9d459 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -204,9 +204,12 @@ Postpone reminder with Snooze by Widgets You cannot do that while offline. + + Google sync is in a testing mode, please be cautions when relying on it. Reporting any feedback at hello@simplemobiletools.com would be appreciated. Thanks! Send locally created events to the cloud? Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Error uploading event: %1$s %1$d минута diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 300c2521e..604976541 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -197,9 +197,12 @@ Posunúť pripomienku s Odložiť o Widgety Nemôžete to urobiť bez internetu. + + Google synchronizácia je v testovacej prevádzke, buďte opatrní pri spoliehaní sa na ňu. Nahlásenie akýchkoľvek ohlasov na hello@simplemobiletools.com je vítané. Vďaka! Odoslať lokálne vytvorené udalosti do oblakov? Vypnutie Google synchonizácie odstráni všetky synchronizované udalosti zo zariadenia, no v oblakoch ostanú nedotknuté. + Chyba pri nahrávaní udalosti: %1$s %1$d minútu diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 9f9f719a7..1ebf790e1 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -190,9 +190,12 @@ Skjut upp påminnelse med Snooza Widgets You cannot do that while offline. + + Google sync is in a testing mode, please be cautions when relying on it. Reporting any feedback at hello@simplemobiletools.com would be appreciated. Thanks! Send locally created events to the cloud? Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Error uploading event: %1$s %1$d minut diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index be6d5c62b..424636891 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -190,9 +190,12 @@ Postpone reminder with Snooze by Widgets You cannot do that while offline. + + Google sync is in a testing mode, please be cautions when relying on it. Reporting any feedback at hello@simplemobiletools.com would be appreciated. Thanks! Send locally created events to the cloud? Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Error uploading event: %1$s %1$d minute diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8c9c748ef..15efcb32b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -190,9 +190,12 @@ Postpone reminder with Snooze by Widgets You cannot do that while offline. + + Google sync is in a testing mode, please be cautions when relying on it. Reporting any feedback at hello@simplemobiletools.com would be appreciated. Thanks! Send locally created events to the cloud? Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud. + Error uploading event: %1$s %1$d minute