From ed9b0caa7b63ef02240d20aecf44c8b69997fbc2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 17 Aug 2017 16:01:10 +0200 Subject: [PATCH] show the currently selected calendar info on the events screen --- .../calendar/activities/EventActivity.kt | 15 ++++++++++++++- .../calendar/dialogs/SelectCalendarsDialog.kt | 2 +- .../calendar/dialogs/SelectEventCalendarDialog.kt | 2 +- .../calendar/helpers/CalDAVEventsHandler.kt | 8 ++++---- .../calendar/helpers/DBHelper.kt | 2 +- .../calendar/models/CalDAVCalendar.kt | 2 +- 6 files changed, 22 insertions(+), 9 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 9afb30792..2413d361a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -14,6 +14,7 @@ import com.simplemobiletools.calendar.dialogs.* import com.simplemobiletools.calendar.extensions.* import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.calendar.helpers.Formatter +import com.simplemobiletools.calendar.models.CalDAVCalendar import com.simplemobiletools.calendar.models.Event import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* @@ -388,15 +389,27 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { event_caldav_calendar_image.beVisible() event_caldav_calendar_holder.beVisible() event_caldav_calendar_divider.beVisible() + + val calendars = CalDAVEventsHandler(applicationContext).getCalDAVCalendars().filter { it.canWrite() } + updateCurrentCalendarInfo(getCalendarWithId(calendars)) + event_caldav_calendar_holder.setOnClickListener { - val calendars = CalDAVEventsHandler(applicationContext).getCalDAVCalendars().filter { it.canWrite() } SelectEventCalendarDialog(this, calendars, config.lastUsedCaldavCalendar) { config.lastUsedCaldavCalendar = it + updateCurrentCalendarInfo(getCalendarWithId(calendars)) } } } } + private fun getCalendarWithId(calendars: List): CalDAVCalendar? = + calendars.firstOrNull { it.id == config.lastUsedCaldavCalendar } + + private fun updateCurrentCalendarInfo(currentCalendar: CalDAVCalendar?) { + event_caldav_calendar_name.text = currentCalendar?.displayName + event_caldav_calendar_email.text = currentCalendar?.accountName + } + private fun toggleAllDay(isChecked: Boolean) { hideKeyboard() event_start_time.beGoneIf(isChecked) 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 8cb023f97..374f4e8ce 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectCalendarsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectCalendarsDialog.kt @@ -40,7 +40,7 @@ class SelectCalendarsDialog(val activity: Activity, val callback: () -> Unit) : } } - private fun addCalendarItem(isEvent: Boolean, text: String, tag: Long = 0L, shouldCheck: Boolean = false) { + private fun addCalendarItem(isEvent: Boolean, text: String, tag: Int = 0, shouldCheck: Boolean = false) { val calendarItem = activity.layoutInflater.inflate(if (isEvent) R.layout.calendar_item_calendar else R.layout.calendar_item_account, view.dialog_select_calendars_holder, false) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventCalendarDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventCalendarDialog.kt index af35c4668..30cf4ecb0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventCalendarDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SelectEventCalendarDialog.kt @@ -63,4 +63,4 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List() val existingEvents = context.dbHelper.getEventsFromCalDAVCalendar(calendarId) existingEvents.forEach { @@ -122,7 +122,7 @@ class CalDAVEventsHandler(val context: Context) { } } - fun addCalDAVEvent(event: Event, calendarId: Long) { + fun addCalDAVEvent(event: Event, calendarId: Int) { val uri = CalendarContract.Events.CONTENT_URI val values = ContentValues().apply { put(CalendarContract.Events.CALENDAR_ID, calendarId) @@ -196,5 +196,5 @@ class CalDAVEventsHandler(val context: Context) { return reminders } - fun getCalDAVEventImportId(calendarId: Long, eventId: Long) = "$CALDAV-$calendarId-$eventId" + fun getCalDAVEventImportId(calendarId: Int, eventId: Long) = "$CALDAV-$calendarId-$eventId" } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index 9caf8d130..fd96367e0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -675,7 +675,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont return events } - fun getEventsFromCalDAVCalendar(calendarId: Long): List { + fun getEventsFromCalDAVCalendar(calendarId: Int): List { val selection = "$MAIN_TABLE_NAME.$COL_EVENT_SOURCE = ?" val selectionArgs = arrayOf("$CALDAV-$calendarId") val cursor = getEventsCursor(selection, selectionArgs) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/models/CalDAVCalendar.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/models/CalDAVCalendar.kt index dda0ec26a..809513e6f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/models/CalDAVCalendar.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/models/CalDAVCalendar.kt @@ -1,5 +1,5 @@ package com.simplemobiletools.calendar.models -data class CalDAVCalendar(val id: Long, val displayName: String, val accountName: String, val ownerName: String, val color: Int, val accessLevel: Int) { +data class CalDAVCalendar(val id: Int, val displayName: String, val accountName: String, val ownerName: String, val color: Int, val accessLevel: Int) { fun canWrite() = accessLevel >= 500 }