show an error toast when something goes wrong at uploading an event

This commit is contained in:
tibbi 2017-07-25 18:48:53 +02:00
parent a95fed8c14
commit 8ea163b439
17 changed files with 69 additions and 8 deletions

View File

@ -1,26 +1,31 @@
package com.simplemobiletools.calendar.helpers 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.EventDateTime
import com.google.api.services.calendar.model.EventReminder 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.getGoogleSyncService
import com.simplemobiletools.calendar.extensions.isGoogleSyncActive import com.simplemobiletools.calendar.extensions.isGoogleSyncActive
import com.simplemobiletools.calendar.extensions.isOnline import com.simplemobiletools.calendar.extensions.isOnline
import com.simplemobiletools.calendar.models.Event import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.models.GoogleError
import com.simplemobiletools.commons.extensions.toast
import java.util.* import java.util.*
class GoogleSyncHandler { class GoogleSyncHandler {
fun uploadToGoogle(context: Context, event: Event) { fun uploadToGoogle(activity: SimpleActivity, event: Event) {
if (context.isGoogleSyncActive()) { if (activity.isGoogleSyncActive()) {
if (context.isOnline()) { if (activity.isOnline()) {
Thread({ Thread({
createRemoteGoogleEvent(context, event) createRemoteGoogleEvent(activity, event)
}).start() }).start()
} }
} }
} }
private fun createRemoteGoogleEvent(context: Context, event: Event) { private fun createRemoteGoogleEvent(activity: SimpleActivity, event: Event) {
try { try {
com.google.api.services.calendar.model.Event().apply { com.google.api.services.calendar.model.Event().apply {
summary = event.title summary = event.title
@ -45,7 +50,15 @@ class GoogleSyncHandler {
reminders = getEventReminders(event).setUseDefault(false) 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<GoogleError>(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) { } catch (ignored: Exception) {

View File

@ -0,0 +1,3 @@
package com.simplemobiletools.calendar.models
data class GoogleError(val message: String)

View File

@ -190,9 +190,12 @@
<string name="snooze_delay">Postpone reminder with Snooze by</string> <string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -190,9 +190,12 @@
<string name="snooze_delay">Postpone reminder with Snooze by</string> <string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -190,9 +190,12 @@
<string name="snooze_delay">Postpone reminder with Snooze by</string> <string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -190,9 +190,12 @@
<string name="snooze_delay">Postpone reminder with Snooze by</string> <string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -190,9 +190,12 @@
<string name="snooze_delay">Postpone reminder with Snooze by</string> <string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabli
<string name="google_sync_error_insert">Error uploading event: %1$s</string>ng Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -190,9 +190,12 @@
<string name="snooze_delay">Postpone reminder with Snooze by</string> <string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -190,9 +190,12 @@
<string name="snooze_delay">Postpone reminder with Snooze by</string> <string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -190,9 +190,12 @@
<string name="snooze_delay">Postpone reminder with Snooze by</string> <string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -190,9 +190,12 @@
<string name="snooze_delay">Postpone reminder with Snooze by</string> <string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -190,9 +190,12 @@
<string name="snooze_delay">Adiar lembrete com a opção Snooze</string> <string name="snooze_delay">Adiar lembrete com a opção Snooze</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">A sincronização Google ainda não está terminada. Reporte os erros encontrados para hello@simplemobiletools.com. Obrigado!</string> <string name="google_sync_testing">A sincronização Google ainda não está terminada. Reporte os erros encontrados para hello@simplemobiletools.com. Obrigado!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minuto</item> <item quantity="one">%1$d minuto</item>

View File

@ -204,9 +204,12 @@
<string name="snooze_delay">Postpone reminder with Snooze by</string> <string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d минута</item> <item quantity="one">%1$d минута</item>

View File

@ -197,9 +197,12 @@
<string name="snooze_delay">Posunúť pripomienku s Odložiť o</string> <string name="snooze_delay">Posunúť pripomienku s Odložiť o</string>
<string name="widgets">Widgety</string> <string name="widgets">Widgety</string>
<string name="cannot_while_offline">Nemôžete to urobiť bez internetu.</string> <string name="cannot_while_offline">Nemôžete to urobiť bez internetu.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Odoslať lokálne vytvorené udalosti do oblakov?</string> <string name="google_sync_existing">Odoslať lokálne vytvorené udalosti do oblakov?</string>
<string name="google_sync_disabling">Vypnutie Google synchonizácie odstráni všetky synchronizované udalosti zo zariadenia, no v oblakoch ostanú nedotknuté.</string> <string name="google_sync_disabling">Vypnutie Google synchonizácie odstráni všetky synchronizované udalosti zo zariadenia, no v oblakoch ostanú nedotknuté.</string>
<string name="google_sync_error_insert">Chyba pri nahrávaní udalosti: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minútu</item> <item quantity="one">%1$d minútu</item>

View File

@ -190,9 +190,12 @@
<string name="snooze_delay">Skjut upp påminnelse med Snooza</string> <string name="snooze_delay">Skjut upp påminnelse med Snooza</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minut</item> <item quantity="one">%1$d minut</item>

View File

@ -190,9 +190,12 @@
<string name="snooze_delay">Postpone reminder with Snooze by</string> <string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>

View File

@ -190,9 +190,12 @@
<string name="snooze_delay">Postpone reminder with Snooze by</string> <string name="snooze_delay">Postpone reminder with Snooze by</string>
<string name="widgets">Widgets</string> <string name="widgets">Widgets</string>
<string name="cannot_while_offline">You cannot do that while offline.</string> <string name="cannot_while_offline">You cannot do that while offline.</string>
<!-- Google sync -->
<string name="google_sync_testing">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!</string> <string name="google_sync_testing">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!</string>
<string name="google_sync_existing">Send locally created events to the cloud?</string> <string name="google_sync_existing">Send locally created events to the cloud?</string>
<string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string> <string name="google_sync_disabling">Disabling Google sync will delete all synced events from your device, while leaving them intact in the cloud.</string>
<string name="google_sync_error_insert">Error uploading event: %1$s</string>
<plurals name="minutes"> <plurals name="minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>