add a helper function for checking which caldav calendar is writable
This commit is contained in:
parent
4898311b0b
commit
9546220a8c
|
@ -389,7 +389,7 @@ 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()
|
||||||
event_caldav_calendar_holder.setOnClickListener {
|
event_caldav_calendar_holder.setOnClickListener {
|
||||||
|
val calendars = CalDAVEventsHandler(applicationContext).getCalDAVCalendars().filter { it.canWrite() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,10 @@ class CalDAVEventsHandler(val context: Context) {
|
||||||
CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
|
CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
|
||||||
CalendarContract.Calendars.ACCOUNT_NAME,
|
CalendarContract.Calendars.ACCOUNT_NAME,
|
||||||
CalendarContract.Calendars.OWNER_ACCOUNT,
|
CalendarContract.Calendars.OWNER_ACCOUNT,
|
||||||
CalendarContract.Calendars.CALENDAR_COLOR)
|
CalendarContract.Calendars.CALENDAR_COLOR,
|
||||||
val selection = if (ids.trim().isNotEmpty()) "${CalendarContract.Calendars._ID} IN ($ids)" else null
|
CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL)
|
||||||
|
|
||||||
|
val selection = if (ids.trim().isNotEmpty()) "${CalendarContract.Calendars._ID} IN ($ids)" else null
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = context.contentResolver.query(uri, projection, selection, null, null)
|
cursor = context.contentResolver.query(uri, projection, selection, null, null)
|
||||||
|
@ -41,7 +42,8 @@ class CalDAVEventsHandler(val context: Context) {
|
||||||
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)
|
||||||
val color = cursor.getIntValue(CalendarContract.Calendars.CALENDAR_COLOR)
|
val color = cursor.getIntValue(CalendarContract.Calendars.CALENDAR_COLOR)
|
||||||
val calendar = CalDAVCalendar(id, displayName, accountName, ownerName, color)
|
val accessLevel = cursor.getIntValue(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL)
|
||||||
|
val calendar = CalDAVCalendar(id, displayName, accountName, ownerName, color, accessLevel)
|
||||||
calendars.add(calendar)
|
calendars.add(calendar)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
|
@ -68,8 +70,8 @@ class CalDAVEventsHandler(val context: Context) {
|
||||||
CalendarContract.Events.DURATION,
|
CalendarContract.Events.DURATION,
|
||||||
CalendarContract.Events.ALL_DAY,
|
CalendarContract.Events.ALL_DAY,
|
||||||
CalendarContract.Events.RRULE)
|
CalendarContract.Events.RRULE)
|
||||||
val selection = "${CalendarContract.Events.CALENDAR_ID} = $calendarId"
|
|
||||||
|
|
||||||
|
val selection = "${CalendarContract.Events.CALENDAR_ID} = $calendarId"
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = context.contentResolver.query(uri, projection, selection, null, null)
|
cursor = context.contentResolver.query(uri, projection, selection, null, null)
|
||||||
|
|
|
@ -1,3 +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)
|
data class CalDAVCalendar(val id: Long, val displayName: String, val accountName: String, val ownerName: String, val color: Int, val accessLevel: Int) {
|
||||||
|
fun canWrite() = accessLevel >= 500
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue