show the currently selected calendar info on the events screen
This commit is contained in:
parent
20b6578225
commit
ed9b0caa7b
|
@ -14,6 +14,7 @@ import com.simplemobiletools.calendar.dialogs.*
|
||||||
import com.simplemobiletools.calendar.extensions.*
|
import com.simplemobiletools.calendar.extensions.*
|
||||||
import com.simplemobiletools.calendar.helpers.*
|
import com.simplemobiletools.calendar.helpers.*
|
||||||
import com.simplemobiletools.calendar.helpers.Formatter
|
import com.simplemobiletools.calendar.helpers.Formatter
|
||||||
|
import com.simplemobiletools.calendar.models.CalDAVCalendar
|
||||||
import com.simplemobiletools.calendar.models.Event
|
import com.simplemobiletools.calendar.models.Event
|
||||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
@ -388,15 +389,27 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
||||||
event_caldav_calendar_image.beVisible()
|
event_caldav_calendar_image.beVisible()
|
||||||
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() }
|
||||||
|
updateCurrentCalendarInfo(getCalendarWithId(calendars))
|
||||||
|
|
||||||
event_caldav_calendar_holder.setOnClickListener {
|
event_caldav_calendar_holder.setOnClickListener {
|
||||||
val calendars = CalDAVEventsHandler(applicationContext).getCalDAVCalendars().filter { it.canWrite() }
|
|
||||||
SelectEventCalendarDialog(this, calendars, config.lastUsedCaldavCalendar) {
|
SelectEventCalendarDialog(this, calendars, config.lastUsedCaldavCalendar) {
|
||||||
config.lastUsedCaldavCalendar = it
|
config.lastUsedCaldavCalendar = it
|
||||||
|
updateCurrentCalendarInfo(getCalendarWithId(calendars))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getCalendarWithId(calendars: List<CalDAVCalendar>): 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) {
|
private fun toggleAllDay(isChecked: Boolean) {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
event_start_time.beGoneIf(isChecked)
|
event_start_time.beGoneIf(isChecked)
|
||||||
|
|
|
@ -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,
|
val calendarItem = activity.layoutInflater.inflate(if (isEvent) R.layout.calendar_item_calendar else R.layout.calendar_item_account,
|
||||||
view.dialog_select_calendars_holder, false)
|
view.dialog_select_calendars_holder, false)
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ class CalDAVEventsHandler(val context: Context) {
|
||||||
cursor = context.contentResolver.query(uri, projection, selection, null, null)
|
cursor = context.contentResolver.query(uri, projection, selection, null, null)
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
val id = cursor.getLongValue(CalendarContract.Calendars._ID)
|
val id = cursor.getIntValue(CalendarContract.Calendars._ID)
|
||||||
val displayName = cursor.getStringValue(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME)
|
val displayName = cursor.getStringValue(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME)
|
||||||
val accountName = cursor.getStringValue(CalendarContract.Calendars.ACCOUNT_NAME)
|
val accountName = cursor.getStringValue(CalendarContract.Calendars.ACCOUNT_NAME)
|
||||||
val ownerName = cursor.getStringValue(CalendarContract.Calendars.OWNER_ACCOUNT)
|
val ownerName = cursor.getStringValue(CalendarContract.Calendars.OWNER_ACCOUNT)
|
||||||
|
@ -53,7 +53,7 @@ class CalDAVEventsHandler(val context: Context) {
|
||||||
return calendars
|
return calendars
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fetchCalDAVCalendarEvents(calendarId: Long, eventTypeId: Int) {
|
fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int) {
|
||||||
val importIdsMap = HashMap<String, Event>()
|
val importIdsMap = HashMap<String, Event>()
|
||||||
val existingEvents = context.dbHelper.getEventsFromCalDAVCalendar(calendarId)
|
val existingEvents = context.dbHelper.getEventsFromCalDAVCalendar(calendarId)
|
||||||
existingEvents.forEach {
|
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 uri = CalendarContract.Events.CONTENT_URI
|
||||||
val values = ContentValues().apply {
|
val values = ContentValues().apply {
|
||||||
put(CalendarContract.Events.CALENDAR_ID, calendarId)
|
put(CalendarContract.Events.CALENDAR_ID, calendarId)
|
||||||
|
@ -196,5 +196,5 @@ class CalDAVEventsHandler(val context: Context) {
|
||||||
return reminders
|
return reminders
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCalDAVEventImportId(calendarId: Long, eventId: Long) = "$CALDAV-$calendarId-$eventId"
|
fun getCalDAVEventImportId(calendarId: Int, eventId: Long) = "$CALDAV-$calendarId-$eventId"
|
||||||
}
|
}
|
||||||
|
|
|
@ -675,7 +675,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEventsFromCalDAVCalendar(calendarId: Long): List<Event> {
|
fun getEventsFromCalDAVCalendar(calendarId: Int): List<Event> {
|
||||||
val selection = "$MAIN_TABLE_NAME.$COL_EVENT_SOURCE = ?"
|
val selection = "$MAIN_TABLE_NAME.$COL_EVENT_SOURCE = ?"
|
||||||
val selectionArgs = arrayOf("$CALDAV-$calendarId")
|
val selectionArgs = arrayOf("$CALDAV-$calendarId")
|
||||||
val cursor = getEventsCursor(selection, selectionArgs)
|
val cursor = getEventsCursor(selection, selectionArgs)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package com.simplemobiletools.calendar.models
|
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
|
fun canWrite() = accessLevel >= 500
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue