From e6d49184a5893b4b349e8627239c90fd2f5c6d3f Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 2 May 2018 10:27:58 +0200 Subject: [PATCH] store the last used event type id, use it as default in new events --- .../calendar/activities/EventActivity.kt | 11 +++++++++-- .../com/simplemobiletools/calendar/helpers/Config.kt | 4 ++++ .../simplemobiletools/calendar/helpers/Constants.kt | 1 + 3 files changed, 14 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 30f0e4b73..66b9fc930 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -60,6 +60,12 @@ class EventActivity : SimpleActivity() { return } + if (dbHelper.getEventType(config.lastUsedLocalEventTypeId) == null) { + config.lastUsedLocalEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID + } + + mEventTypeId = config.lastUsedLocalEventTypeId + if (event != null) { mEvent = event mEventOccurrenceTS = intent.getIntExtra(EVENT_OCCURRENCE_TS, 0) @@ -440,7 +446,7 @@ class EventActivity : SimpleActivity() { hideKeyboard() SelectEventCalendarDialog(this, calendars, mEventCalendarId) { if (mEventCalendarId != STORED_LOCALLY_ONLY && it == STORED_LOCALLY_ONLY) { - mEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID + mEventTypeId = config.lastUsedLocalEventTypeId updateEventType() } mEventCalendarId = it @@ -522,10 +528,11 @@ class EventActivity : SimpleActivity() { val newEventType = if (!config.caldavSync || config.lastUsedCaldavCalendar == 0 || mEventCalendarId == STORED_LOCALLY_ONLY) { mEventTypeId } else { - dbHelper.getEventTypeWithCalDAVCalendarId(config.lastUsedCaldavCalendar)?.id ?: DBHelper.REGULAR_EVENT_TYPE_ID + dbHelper.getEventTypeWithCalDAVCalendarId(config.lastUsedCaldavCalendar)?.id ?: config.lastUsedLocalEventTypeId } val newSource = if (!config.caldavSync || config.lastUsedCaldavCalendar == 0 || mEventCalendarId == STORED_LOCALLY_ONLY) { + config.lastUsedLocalEventTypeId = newEventType SOURCE_SIMPLE_CALENDAR } else { "$CALDAV-${config.lastUsedCaldavCalendar}" 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 8fd699de6..be6b5edc4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt @@ -81,6 +81,10 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getInt(LAST_USED_CALDAV_CALENDAR, getSyncedCalendarIdsAsList().first().toInt()) set(calendarId) = prefs.edit().putInt(LAST_USED_CALDAV_CALENDAR, calendarId).apply() + var lastUsedLocalEventTypeId: Int + get() = prefs.getInt(LAST_USED_LOCAL_EVENT_TYPE_ID, DBHelper.REGULAR_EVENT_TYPE_ID) + set(lastUsedLocalEventTypeId) = prefs.edit().putInt(LAST_USED_LOCAL_EVENT_TYPE_ID, lastUsedLocalEventTypeId).apply() + var replaceDescription: Boolean get() = prefs.getBoolean(REPLACE_DESCRIPTION, false) set(replaceDescription) = prefs.edit().putBoolean(REPLACE_DESCRIPTION, replaceDescription).apply() 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 5343a0c04..969626802 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -48,6 +48,7 @@ const val FONT_SIZE = "font_size" const val CALDAV_SYNC = "caldav_sync" const val CALDAV_SYNCED_CALENDAR_IDS = "caldav_synced_calendar_ids" const val LAST_USED_CALDAV_CALENDAR = "last_used_caldav_calendar" +const val LAST_USED_LOCAL_EVENT_TYPE_ID = "last_used_local_event_type_id" const val DISPLAY_PAST_EVENTS = "display_past_events" const val REPLACE_DESCRIPTION = "replace_description" const val SHOW_GRID = "show_grid"