From d95152d53c308e1f30ae21d44579a33acec76f14 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 23 Jul 2017 23:05:20 +0200 Subject: [PATCH] add a helper function for checking if google sync is active --- .../calendar/activities/EventActivity.kt | 11 +++++++++++ .../calendar/activities/MainActivity.kt | 2 +- .../calendar/activities/SettingsActivity.kt | 2 +- .../simplemobiletools/calendar/extensions/Context.kt | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) 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 db1d4edd5..c46667cf6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -470,6 +470,13 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { } else { toast(R.string.event_added) } + + if (isGoogleSyncActive()) { + if (isOnline()) { + createRemoteGoogleEvent() + } + } + finish() } } else { @@ -493,6 +500,10 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { } } + private fun createRemoteGoogleEvent() { + + } + private fun updateStartTexts() { updateStartDateText() updateStartTimeText() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt index cb07d3990..71209c37a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -90,7 +90,7 @@ class MainActivity : SimpleActivity(), NavigationListener { config.googleSync = false } - if (config.googleSync && config.syncAccountName.isNotEmpty()) { + if (isGoogleSyncActive()) { FetchGoogleEventsTask(this, googleSyncListener).execute() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt index 29efdb349..48f42b6af 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -109,7 +109,7 @@ class SettingsActivity : SimpleActivity() { } private fun setupGoogleSync() { - settings_google_sync.isChecked = config.googleSync + settings_google_sync.isChecked = isGoogleSyncActive() settings_google_sync_holder.setOnClickListener { if (config.googleSync) { ConfirmationDialog(this, getString(R.string.google_sync_disabling), positive = R.string.ok, negative = R.string.cancel) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index eb367fef2..8102e0336 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -249,6 +249,8 @@ fun Context.getNewEventTimestampFromCode(dayCode: String) = Formatter.getLocalDa fun Context.getCurrentOffset() = SimpleDateFormat("Z", Locale.getDefault()).format(Date()) +fun Context.isGoogleSyncActive() = config.googleSync && config.syncAccountName.isNotEmpty() + val Context.config: Config get() = Config.newInstance(this) val Context.dbHelper: DBHelper get() = DBHelper.newInstance(this)