add an initial way of uploading local events to google

This commit is contained in:
tibbi 2017-07-23 23:28:55 +02:00
parent d95152d53c
commit 33f10240af
3 changed files with 19 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import android.text.method.LinkMovementMethod
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import com.google.api.services.calendar.model.EventDateTime
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.dialogs.*
import com.simplemobiletools.calendar.extensions.*
@ -473,7 +474,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
if (isGoogleSyncActive()) {
if (isOnline()) {
createRemoteGoogleEvent()
Thread({
createRemoteGoogleEvent()
}).start()
}
}
@ -501,7 +504,18 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
}
private fun createRemoteGoogleEvent() {
try {
com.google.api.services.calendar.model.Event().apply {
summary = mEvent.title
description = mEvent.description
start = EventDateTime().setDateTime(com.google.api.client.util.DateTime(mEvent.startTS * 1000L))
end = EventDateTime().setDateTime(com.google.api.client.util.DateTime(mEvent.endTS * 1000L))
status = CONFIRMED.toLowerCase()
getGoogleSyncService().events().insert(PRIMARY, this).execute()
}
} catch (ignored: Exception) {
}
}
private fun updateStartTexts() {

View File

@ -21,7 +21,6 @@ import java.util.*
// more info about event fields at https://developers.google.com/google-apps/calendar/v3/reference/events/insert
class FetchGoogleEventsTask(val activity: Activity, val googleSyncListener: GoogleSyncListener? = null) : AsyncTask<Void, Void, String>() {
private val CONFIRMED = "confirmed"
private val ITEMS = "items"
private val OVERRIDES = "overrides"
private val POPUP = "popup"
@ -86,7 +85,7 @@ class FetchGoogleEventsTask(val activity: Activity, val googleSyncListener: Goog
for (googleEvent in googleEvents) {
val importId = googleEvent.id
remoteImportIds.add(importId)
if (googleEvent.status != CONFIRMED)
if (!googleEvent.status.equals(CONFIRMED, true))
continue
val lastUpdate = DateTime(googleEvent.updated).millis

View File

@ -12,7 +12,6 @@ val EVENT_OCCURRENCE_TS = "event_occurrence_ts"
val NEW_EVENT_START_TS = "new_event_start_ts"
val WEEK_START_TIMESTAMP = "week_start_timestamp"
val NEW_EVENT_SET_HOUR_DURATION = "new_event_set_hour_duration"
val PRIMARY = "primary"
val MONTHLY_VIEW = 1
val YEARLY_VIEW = 2
@ -121,3 +120,6 @@ val FONT_SIZE_LARGE = 2
val SOURCE_SIMPLE_CALENDAR = 0
val SOURCE_GOOGLE_SYNC = 1
val SOURCE_IMPORTED_ICS = 2
// Google Sync
val PRIMARY = "primary"