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 2413d361a..caaa1fe70 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -390,7 +390,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { event_caldav_calendar_holder.beVisible() event_caldav_calendar_divider.beVisible() - val calendars = CalDAVEventsHandler(applicationContext).getCalDAVCalendars().filter { it.canWrite() } + val calendars = CalDAVEventsHandler(applicationContext).getCalDAVCalendars().filter { + it.canWrite() && config.getSyncedCalendarIdsAsList().contains(it.id.toString()) + } updateCurrentCalendarInfo(getCalendarWithId(calendars)) event_caldav_calendar_holder.setOnClickListener { 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 da47ab61e..038639bf7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -125,17 +125,17 @@ class SettingsActivity : SimpleActivity() { settings_caldav_sync.isChecked = false config.caldavSync = false settings_manage_synced_calendars_holder.beGone() - config.getCalendarIdsAsList().forEach { + config.getSyncedCalendarIdsAsList().forEach { CalDAVEventsHandler(applicationContext).deleteCalDAVCalendarEvents(it.toLong()) } } } private fun showCalendarPicker() { - val oldCalendarIds = config.getCalendarIdsAsList() + val oldCalendarIds = config.getSyncedCalendarIdsAsList() SelectCalendarsDialog(this) { - val newCalendarIds = config.getCalendarIdsAsList() + val newCalendarIds = config.getSyncedCalendarIdsAsList() settings_manage_synced_calendars_holder.beVisibleIf(newCalendarIds.isNotEmpty()) settings_caldav_sync.isChecked = newCalendarIds.isNotEmpty() config.caldavSync = newCalendarIds.isNotEmpty() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectCalendarsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectCalendarsDialog.kt index 95d984372..5aa2d0e15 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectCalendarsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectCalendarsDialog.kt @@ -20,7 +20,7 @@ class SelectCalendarsDialog(val activity: Activity, val callback: () -> Unit) : var view = (activity.layoutInflater.inflate(R.layout.dialog_select_calendars, null) as ViewGroup) init { - val ids = activity.config.getCalendarIdsAsList() + val ids = activity.config.getSyncedCalendarIdsAsList() val calendars = CalDAVEventsHandler(activity).getCalDAVCalendars() val sorted = calendars.sortedWith(compareBy({ it.accountName }, { it.displayName })) sorted.forEach { 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 8b55d0fc5..ed1d1647a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt @@ -79,10 +79,10 @@ class Config(context: Context) : BaseConfig(context) { set(calendarIDs) = prefs.edit().putString(CALDAV_SYNCED_CALENDAR_IDS, calendarIDs).apply() var lastUsedCaldavCalendar: Int - get() = prefs.getInt(LAST_USED_CALDAV_CALENDAR, getCalendarIdsAsList().first().toInt()) + get() = prefs.getInt(LAST_USED_CALDAV_CALENDAR, getSyncedCalendarIdsAsList().first().toInt()) set(calendarId) = prefs.edit().putInt(LAST_USED_CALDAV_CALENDAR, calendarId).apply() - fun getCalendarIdsAsList() = caldavSyncedCalendarIDs.split(",").filter { it.trim().isNotEmpty() } as ArrayList + fun getSyncedCalendarIdsAsList() = caldavSyncedCalendarIDs.split(",").filter { it.trim().isNotEmpty() } as ArrayList fun addDisplayEventType(type: String) { addDisplayEventTypes(HashSet(Arrays.asList(type)))