preparations for updating event on Google cloud at updating locally

This commit is contained in:
tibbi 2017-07-25 20:50:55 +02:00
parent d0eb958c9c
commit 593af1b6ba
18 changed files with 47 additions and 9 deletions

View File

@ -500,6 +500,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
}
private fun eventUpdated() {
GoogleSyncHandler().updateGoogleEvent(this, mEvent)
toast(R.string.event_updated)
finish()
}

View File

@ -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<GoogleError>(json, GoogleError::class.java)
return error.message
}

View File

@ -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<GoogleError>(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()
}
}
}
}

View File

@ -196,6 +196,7 @@
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>

View File

@ -196,6 +196,7 @@
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>

View File

@ -196,6 +196,7 @@
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>

View File

@ -196,6 +196,7 @@
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>

View File

@ -194,8 +194,9 @@
<!-- 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">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>
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>

View File

@ -196,6 +196,7 @@
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>

View File

@ -196,6 +196,7 @@
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>

View File

@ -196,6 +196,7 @@
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>

View File

@ -196,6 +196,7 @@
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>

View File

@ -196,6 +196,7 @@
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minuto</item>

View File

@ -210,6 +210,7 @@
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d минута</item>

View File

@ -203,6 +203,7 @@
<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>
<string name="google_sync_error_update">Chyba pri úprave udalosti: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minútu</item>

View File

@ -196,6 +196,7 @@
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minut</item>

View File

@ -196,6 +196,7 @@
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>

View File

@ -196,6 +196,7 @@
<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>
<string name="google_sync_error_update">Error updating event: %1$s</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>