mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
handle adding queued events in google
This commit is contained in:
@@ -34,7 +34,10 @@ class FetchGoogleEventsTask(val context: Context, val googleSyncListener: Google
|
|||||||
queuedOperations.forEach {
|
queuedOperations.forEach {
|
||||||
when (it.operation) {
|
when (it.operation) {
|
||||||
OPERATION_INSERT -> {
|
OPERATION_INSERT -> {
|
||||||
|
val event = dbHelper.getEventWithId(it.eventId)
|
||||||
|
if (event != null)
|
||||||
|
GoogleSyncHandler().createRemoteGoogleEvent(context, event)
|
||||||
|
context.googleSyncQueue.clearOperationsOf(it.eventId)
|
||||||
}
|
}
|
||||||
OPERATION_UPDATE -> {
|
OPERATION_UPDATE -> {
|
||||||
|
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package com.simplemobiletools.calendar.helpers
|
package com.simplemobiletools.calendar.helpers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException
|
import com.google.api.client.googleapis.json.GoogleJsonResponseException
|
||||||
import com.google.api.services.calendar.model.EventDateTime
|
import com.google.api.services.calendar.model.EventDateTime
|
||||||
@@ -16,7 +17,11 @@ class GoogleSyncHandler {
|
|||||||
if (activity.isGoogleSyncActive()) {
|
if (activity.isGoogleSyncActive()) {
|
||||||
if (activity.isOnline()) {
|
if (activity.isOnline()) {
|
||||||
Thread({
|
Thread({
|
||||||
createRemoteGoogleEvent(activity, event)
|
val errorMsg = createRemoteGoogleEvent(activity, event)
|
||||||
|
if (errorMsg.isNotEmpty()) {
|
||||||
|
val msg = String.format(activity.getString(R.string.google_sync_error_insert), errorMsg)
|
||||||
|
activity.toast(msg, Toast.LENGTH_LONG)
|
||||||
|
}
|
||||||
}).start()
|
}).start()
|
||||||
} else {
|
} else {
|
||||||
activity.googleSyncQueue.addOperation(event.id, OPERATION_INSERT, event.importId)
|
activity.googleSyncQueue.addOperation(event.id, OPERATION_INSERT, event.importId)
|
||||||
@@ -24,19 +29,14 @@ class GoogleSyncHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createRemoteGoogleEvent(activity: SimpleActivity, event: Event) {
|
fun createRemoteGoogleEvent(context: Context, event: Event): String {
|
||||||
|
val googleEvent = mergeMyEventToGoogleEvent(com.google.api.services.calendar.model.Event(), event)
|
||||||
try {
|
try {
|
||||||
val googleEvent = mergeMyEventToGoogleEvent(com.google.api.services.calendar.model.Event(), event)
|
context.getGoogleSyncService().events().insert(PRIMARY, googleEvent).execute()
|
||||||
try {
|
} catch (e: GoogleJsonResponseException) {
|
||||||
activity.getGoogleSyncService().events().insert(PRIMARY, googleEvent).execute()
|
return e.getGoogleMessageError()
|
||||||
} catch (e: GoogleJsonResponseException) {
|
|
||||||
val msg = String.format(activity.getString(R.string.google_sync_error_insert), e.getGoogleMessageError())
|
|
||||||
activity.toast(msg, Toast.LENGTH_LONG)
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (ignored: Exception) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getEventReminders(event: Event): com.google.api.services.calendar.model.Event.Reminders {
|
private fun getEventReminders(event: Event): com.google.api.services.calendar.model.Event.Reminders {
|
||||||
|
Reference in New Issue
Block a user