From 2da1739431d4cae656f1320d8b1124ba7ca08a10 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 28 Jul 2017 22:23:14 +0200 Subject: [PATCH] store default calendar reminders --- .../calendar/activities/SettingsActivity.kt | 18 ++++++++++++++---- .../asynctasks/FetchGoogleEventsTask.kt | 1 - .../calendar/helpers/Config.kt | 4 ++++ .../calendar/helpers/Constants.kt | 3 +++ 4 files changed, 21 insertions(+), 5 deletions(-) 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 2eebade17..adb6659df 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -18,15 +18,13 @@ import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccoun import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException import com.google.api.client.util.ExponentialBackOff import com.google.api.services.calendar.CalendarScopes +import com.google.api.services.calendar.model.CalendarListEntry import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.asynctasks.FetchGoogleEventsTask import com.simplemobiletools.calendar.dialogs.CustomEventReminderDialog import com.simplemobiletools.calendar.dialogs.SnoozePickerDialog import com.simplemobiletools.calendar.extensions.* -import com.simplemobiletools.calendar.helpers.FONT_SIZE_LARGE -import com.simplemobiletools.calendar.helpers.FONT_SIZE_MEDIUM -import com.simplemobiletools.calendar.helpers.FONT_SIZE_SMALL -import com.simplemobiletools.calendar.helpers.PRIMARY +import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.toast @@ -382,9 +380,21 @@ class SettingsActivity : SimpleActivity() { Thread({ val calendar = getGoogleSyncService().calendarList().get(PRIMARY).execute() config.googleDefaultEventColor = Color.parseColor(calendar.backgroundColor) + storeDefaultReminders(calendar) }).start() } + private fun storeDefaultReminders(calendar: CalendarListEntry) { + val reminderMinutes = ArrayList() + val reminders = calendar.defaultReminders + reminders.forEach { + if (it.method == POPUP) { + reminderMinutes.add(it.minutes) + } + } + config.googleDefaultReminders = reminderMinutes.joinToString() + } + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt index 6450e15b2..ecc9559ea 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt @@ -22,7 +22,6 @@ import java.util.* // more info about event fields at https://developers.google.com/google-apps/calendar/v3/reference/events/insert class FetchGoogleEventsTask(val context: Context, val googleSyncListener: GoogleSyncListener? = null) : AsyncTask() { private val ITEMS = "items" - private val OVERRIDES = "overrides" private val NEXT_PAGE_TOKEN = "nextPageToken" private var dbHelper = context.dbHelper diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt index e07bd4f3e..0e6d2018e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt @@ -90,6 +90,10 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getInt(GOOGLE_DEFAULT_EVENT_COLOR, primaryColor) set(color) = prefs.edit().putInt(GOOGLE_DEFAULT_EVENT_COLOR, color).apply() + var googleDefaultReminders: String + get() = prefs.getString(GOOGLE_DEFAULT_REMINDERS, "") + set(reminders) = prefs.edit().putString(GOOGLE_DEFAULT_REMINDERS, reminders).apply() + fun addDisplayEventType(type: String) { addDisplayEventTypes(HashSet(Arrays.asList(type))) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt index 96104bed2..52d8392b8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -46,6 +46,7 @@ val SYNC_ACCOUNT_NAME = "sync_account_name" val SNOOZE_DELAY = "snooze_delay" val DISPLAY_PAST_EVENTS = "display_past_events" val GOOGLE_DEFAULT_EVENT_COLOR = "google_default_event_color" +val GOOGLE_DEFAULT_REMINDERS = "google_default_reminders" val letterIDs = intArrayOf(R.string.sunday_letter, R.string.monday_letter, R.string.tuesday_letter, R.string.wednesday_letter, R.string.thursday_letter, R.string.friday_letter, R.string.saturday_letter) @@ -128,3 +129,5 @@ val POPUP = "popup" val OPERATION_INSERT = 1 val OPERATION_UPDATE = 2 val OPERATION_DELETE = 3 +val OVERRIDES = "overrides" +val DEFAULT_REMINDERS = "defaultReminders"