do not show not synced calendars at the calendar selector

This commit is contained in:
tibbi 2017-08-17 21:58:19 +02:00
parent 82d18556bf
commit 53e08da673
4 changed files with 9 additions and 7 deletions

View File

@ -390,7 +390,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
event_caldav_calendar_holder.beVisible() event_caldav_calendar_holder.beVisible()
event_caldav_calendar_divider.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)) updateCurrentCalendarInfo(getCalendarWithId(calendars))
event_caldav_calendar_holder.setOnClickListener { event_caldav_calendar_holder.setOnClickListener {

View File

@ -125,17 +125,17 @@ class SettingsActivity : SimpleActivity() {
settings_caldav_sync.isChecked = false settings_caldav_sync.isChecked = false
config.caldavSync = false config.caldavSync = false
settings_manage_synced_calendars_holder.beGone() settings_manage_synced_calendars_holder.beGone()
config.getCalendarIdsAsList().forEach { config.getSyncedCalendarIdsAsList().forEach {
CalDAVEventsHandler(applicationContext).deleteCalDAVCalendarEvents(it.toLong()) CalDAVEventsHandler(applicationContext).deleteCalDAVCalendarEvents(it.toLong())
} }
} }
} }
private fun showCalendarPicker() { private fun showCalendarPicker() {
val oldCalendarIds = config.getCalendarIdsAsList() val oldCalendarIds = config.getSyncedCalendarIdsAsList()
SelectCalendarsDialog(this) { SelectCalendarsDialog(this) {
val newCalendarIds = config.getCalendarIdsAsList() val newCalendarIds = config.getSyncedCalendarIdsAsList()
settings_manage_synced_calendars_holder.beVisibleIf(newCalendarIds.isNotEmpty()) settings_manage_synced_calendars_holder.beVisibleIf(newCalendarIds.isNotEmpty())
settings_caldav_sync.isChecked = newCalendarIds.isNotEmpty() settings_caldav_sync.isChecked = newCalendarIds.isNotEmpty()
config.caldavSync = newCalendarIds.isNotEmpty() config.caldavSync = newCalendarIds.isNotEmpty()

View File

@ -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) var view = (activity.layoutInflater.inflate(R.layout.dialog_select_calendars, null) as ViewGroup)
init { init {
val ids = activity.config.getCalendarIdsAsList() val ids = activity.config.getSyncedCalendarIdsAsList()
val calendars = CalDAVEventsHandler(activity).getCalDAVCalendars() val calendars = CalDAVEventsHandler(activity).getCalDAVCalendars()
val sorted = calendars.sortedWith(compareBy({ it.accountName }, { it.displayName })) val sorted = calendars.sortedWith(compareBy({ it.accountName }, { it.displayName }))
sorted.forEach { sorted.forEach {

View File

@ -79,10 +79,10 @@ class Config(context: Context) : BaseConfig(context) {
set(calendarIDs) = prefs.edit().putString(CALDAV_SYNCED_CALENDAR_IDS, calendarIDs).apply() set(calendarIDs) = prefs.edit().putString(CALDAV_SYNCED_CALENDAR_IDS, calendarIDs).apply()
var lastUsedCaldavCalendar: Int 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() set(calendarId) = prefs.edit().putInt(LAST_USED_CALDAV_CALENDAR, calendarId).apply()
fun getCalendarIdsAsList() = caldavSyncedCalendarIDs.split(",").filter { it.trim().isNotEmpty() } as ArrayList<String> fun getSyncedCalendarIdsAsList() = caldavSyncedCalendarIDs.split(",").filter { it.trim().isNotEmpty() } as ArrayList<String>
fun addDisplayEventType(type: String) { fun addDisplayEventType(type: String) {
addDisplayEventTypes(HashSet<String>(Arrays.asList(type))) addDisplayEventTypes(HashSet<String>(Arrays.asList(type)))