show an error toast when something goes wrong at uploading an event
This commit is contained in:
parent
a95fed8c14
commit
8ea163b439
|
@ -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<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) {
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package com.simplemobiletools.calendar.models
|
||||
|
||||
data class GoogleError(val message: String)
|
|
@ -190,9 +190,12 @@
|
|||
<string name="snooze_delay">Postpone reminder with Snooze by</string>
|
||||
<string name="widgets">Widgets</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_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_error_insert">Error uploading event: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d minute</item>
|
||||
|
|
|
@ -190,9 +190,12 @@
|
|||
<string name="snooze_delay">Postpone reminder with Snooze by</string>
|
||||
<string name="widgets">Widgets</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_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_error_insert">Error uploading event: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d minute</item>
|
||||
|
|
|
@ -190,9 +190,12 @@
|
|||
<string name="snooze_delay">Postpone reminder with Snooze by</string>
|
||||
<string name="widgets">Widgets</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_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_error_insert">Error uploading event: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d minute</item>
|
||||
|
|
|
@ -190,9 +190,12 @@
|
|||
<string name="snooze_delay">Postpone reminder with Snooze by</string>
|
||||
<string name="widgets">Widgets</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_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_error_insert">Error uploading event: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d minute</item>
|
||||
|
|
|
@ -190,9 +190,12 @@
|
|||
<string name="snooze_delay">Postpone reminder with Snooze by</string>
|
||||
<string name="widgets">Widgets</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_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">
|
||||
<item quantity="one">%1$d minute</item>
|
||||
|
|
|
@ -190,9 +190,12 @@
|
|||
<string name="snooze_delay">Postpone reminder with Snooze by</string>
|
||||
<string name="widgets">Widgets</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_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_error_insert">Error uploading event: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d minute</item>
|
||||
|
|
|
@ -190,9 +190,12 @@
|
|||
<string name="snooze_delay">Postpone reminder with Snooze by</string>
|
||||
<string name="widgets">Widgets</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_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_error_insert">Error uploading event: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d minute</item>
|
||||
|
|
|
@ -190,9 +190,12 @@
|
|||
<string name="snooze_delay">Postpone reminder with Snooze by</string>
|
||||
<string name="widgets">Widgets</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_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_error_insert">Error uploading event: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d minute</item>
|
||||
|
|
|
@ -190,9 +190,12 @@
|
|||
<string name="snooze_delay">Postpone reminder with Snooze by</string>
|
||||
<string name="widgets">Widgets</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_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_error_insert">Error uploading event: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d minute</item>
|
||||
|
|
|
@ -190,9 +190,12 @@
|
|||
<string name="snooze_delay">Adiar lembrete com a opção Snooze</string>
|
||||
<string name="widgets">Widgets</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_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_error_insert">Error uploading event: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d minuto</item>
|
||||
|
|
|
@ -204,9 +204,12 @@
|
|||
<string name="snooze_delay">Postpone reminder with Snooze by</string>
|
||||
<string name="widgets">Widgets</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_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_error_insert">Error uploading event: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d минута</item>
|
||||
|
|
|
@ -197,9 +197,12 @@
|
|||
<string name="snooze_delay">Posunúť pripomienku s Odložiť o</string>
|
||||
<string name="widgets">Widgety</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_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_error_insert">Chyba pri nahrávaní udalosti: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d minútu</item>
|
||||
|
|
|
@ -190,9 +190,12 @@
|
|||
<string name="snooze_delay">Skjut upp påminnelse med Snooza</string>
|
||||
<string name="widgets">Widgets</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_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_error_insert">Error uploading event: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d minut</item>
|
||||
|
|
|
@ -190,9 +190,12 @@
|
|||
<string name="snooze_delay">Postpone reminder with Snooze by</string>
|
||||
<string name="widgets">Widgets</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_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_error_insert">Error uploading event: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d minute</item>
|
||||
|
|
|
@ -190,9 +190,12 @@
|
|||
<string name="snooze_delay">Postpone reminder with Snooze by</string>
|
||||
<string name="widgets">Widgets</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_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_error_insert">Error uploading event: %1$s</string>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%1$d minute</item>
|
||||
|
|
Loading…
Reference in New Issue