mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
add an initial way of uploading local events to google
This commit is contained in:
@@ -9,6 +9,7 @@ import android.text.method.LinkMovementMethod
|
|||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
|
import com.google.api.services.calendar.model.EventDateTime
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.dialogs.*
|
import com.simplemobiletools.calendar.dialogs.*
|
||||||
import com.simplemobiletools.calendar.extensions.*
|
import com.simplemobiletools.calendar.extensions.*
|
||||||
@@ -473,7 +474,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||||||
|
|
||||||
if (isGoogleSyncActive()) {
|
if (isGoogleSyncActive()) {
|
||||||
if (isOnline()) {
|
if (isOnline()) {
|
||||||
|
Thread({
|
||||||
createRemoteGoogleEvent()
|
createRemoteGoogleEvent()
|
||||||
|
}).start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,8 +504,19 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createRemoteGoogleEvent() {
|
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() {
|
private fun updateStartTexts() {
|
||||||
updateStartDateText()
|
updateStartDateText()
|
||||||
|
@@ -21,7 +21,6 @@ import java.util.*
|
|||||||
|
|
||||||
// more info about event fields at https://developers.google.com/google-apps/calendar/v3/reference/events/insert
|
// 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>() {
|
class FetchGoogleEventsTask(val activity: Activity, val googleSyncListener: GoogleSyncListener? = null) : AsyncTask<Void, Void, String>() {
|
||||||
private val CONFIRMED = "confirmed"
|
|
||||||
private val ITEMS = "items"
|
private val ITEMS = "items"
|
||||||
private val OVERRIDES = "overrides"
|
private val OVERRIDES = "overrides"
|
||||||
private val POPUP = "popup"
|
private val POPUP = "popup"
|
||||||
@@ -86,7 +85,7 @@ class FetchGoogleEventsTask(val activity: Activity, val googleSyncListener: Goog
|
|||||||
for (googleEvent in googleEvents) {
|
for (googleEvent in googleEvents) {
|
||||||
val importId = googleEvent.id
|
val importId = googleEvent.id
|
||||||
remoteImportIds.add(importId)
|
remoteImportIds.add(importId)
|
||||||
if (googleEvent.status != CONFIRMED)
|
if (!googleEvent.status.equals(CONFIRMED, true))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
val lastUpdate = DateTime(googleEvent.updated).millis
|
val lastUpdate = DateTime(googleEvent.updated).millis
|
||||||
|
@@ -12,7 +12,6 @@ val EVENT_OCCURRENCE_TS = "event_occurrence_ts"
|
|||||||
val NEW_EVENT_START_TS = "new_event_start_ts"
|
val NEW_EVENT_START_TS = "new_event_start_ts"
|
||||||
val WEEK_START_TIMESTAMP = "week_start_timestamp"
|
val WEEK_START_TIMESTAMP = "week_start_timestamp"
|
||||||
val NEW_EVENT_SET_HOUR_DURATION = "new_event_set_hour_duration"
|
val NEW_EVENT_SET_HOUR_DURATION = "new_event_set_hour_duration"
|
||||||
val PRIMARY = "primary"
|
|
||||||
|
|
||||||
val MONTHLY_VIEW = 1
|
val MONTHLY_VIEW = 1
|
||||||
val YEARLY_VIEW = 2
|
val YEARLY_VIEW = 2
|
||||||
@@ -121,3 +120,6 @@ val FONT_SIZE_LARGE = 2
|
|||||||
val SOURCE_SIMPLE_CALENDAR = 0
|
val SOURCE_SIMPLE_CALENDAR = 0
|
||||||
val SOURCE_GOOGLE_SYNC = 1
|
val SOURCE_GOOGLE_SYNC = 1
|
||||||
val SOURCE_IMPORTED_ICS = 2
|
val SOURCE_IMPORTED_ICS = 2
|
||||||
|
|
||||||
|
// Google Sync
|
||||||
|
val PRIMARY = "primary"
|
||||||
|
Reference in New Issue
Block a user