From 593af1b6bafc0ba7c32642d5bff41be6a35f4d9d Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 25 Jul 2017 20:50:55 +0200 Subject: [PATCH] preparations for updating event on Google cloud at updating locally --- .../calendar/activities/EventActivity.kt | 1 + .../calendar/extensions/Exception.kt | 10 +++++++ .../calendar/helpers/GoogleSyncHandler.kt | 26 ++++++++++++++----- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-hi-rIN/strings.xml | 1 + app/src/main/res/values-hu/strings.xml | 5 ++-- app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-iw/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-pt/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values-sk/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values-tr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 18 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Exception.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index de51bcd5b..ab51a1f76 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -500,6 +500,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { } private fun eventUpdated() { + GoogleSyncHandler().updateGoogleEvent(this, mEvent) toast(R.string.event_updated) finish() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Exception.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Exception.kt new file mode 100644 index 000000000..e80ed6dde --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Exception.kt @@ -0,0 +1,10 @@ +package com.simplemobiletools.calendar.extensions + +import com.google.gson.Gson +import com.simplemobiletools.calendar.models.GoogleError + +fun Exception.getGoogleMessageError(): String { + val json = message!!.substring(message!!.indexOf('{')) + val error = Gson().fromJson(json, GoogleError::class.java) + return error.message +} 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 c2e4c7f08..1ea93dcc7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/GoogleSyncHandler.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/GoogleSyncHandler.kt @@ -1,16 +1,16 @@ package com.simplemobiletools.calendar.helpers import android.widget.Toast +import com.google.api.client.googleapis.json.GoogleJsonResponseException 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.getGoogleMessageError 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.* @@ -52,11 +52,8 @@ class GoogleSyncHandler { 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) + } catch (e: GoogleJsonResponseException) { + val msg = String.format(activity.getString(R.string.google_sync_error_insert), e.getGoogleMessageError()) activity.toast(msg, Toast.LENGTH_LONG) } } @@ -73,4 +70,19 @@ class GoogleSyncHandler { } return com.google.api.services.calendar.model.Event.Reminders().setOverrides(reminders) } + + fun updateGoogleEvent(activity: SimpleActivity, event: Event) { + if (activity.isGoogleSyncActive()) { + if (activity.isOnline()) { + Thread({ + try { + val googleEvent = activity.getGoogleSyncService().events().get(PRIMARY, event.importId + "qw").execute() + } catch (e: GoogleJsonResponseException) { + val msg = String.format(activity.getString(R.string.google_sync_error_update), e.getGoogleMessageError()) + activity.toast(msg, Toast.LENGTH_LONG) + } + }).start() + } + } + } } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 7c026fc0d..921754452 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -196,6 +196,7 @@ 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 + Error updating 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 17835cd9a..4a181a5e0 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -196,6 +196,7 @@ 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 + Error updating 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 c629b6057..4ad249564 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -196,6 +196,7 @@ 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 + Error updating 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 601412c28..14945319a 100644 --- a/app/src/main/res/values-hi-rIN/strings.xml +++ b/app/src/main/res/values-hi-rIN/strings.xml @@ -196,6 +196,7 @@ 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 + Error updating 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 f4e4d04b2..8f595f787 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -194,8 +194,9 @@ 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? - Disabli - Error uploading event: %1$sng Google sync will delete all synced events from your device, while leaving them intact in 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 + Error updating event: %1$s %1$d minute diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index a8c91754e..30f9968ba 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -196,6 +196,7 @@ 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 + Error updating 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 8ec171983..271195e63 100644 --- a/app/src/main/res/values-iw/strings.xml +++ b/app/src/main/res/values-iw/strings.xml @@ -196,6 +196,7 @@ 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 + Error updating 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 fafb74beb..660e1fb41 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -196,6 +196,7 @@ 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 + Error updating 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 00ea6de45..df8f00c17 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -196,6 +196,7 @@ 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 + Error updating 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 13a87e3d7..107f42372 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -196,6 +196,7 @@ 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 + Error updating 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 980d9d459..beba5f1fc 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -210,6 +210,7 @@ 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 + Error updating 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 604976541..79ecdcce3 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -203,6 +203,7 @@ 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 + Chyba pri úprave 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 1ebf790e1..de33c093b 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -196,6 +196,7 @@ 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 + Error updating 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 424636891..66d6d20fd 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -196,6 +196,7 @@ 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 + Error updating 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 15efcb32b..dcba9329d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -196,6 +196,7 @@ 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 + Error updating event: %1$s %1$d minute