create a helper function for retrieving caldav event attendees

This commit is contained in:
tibbi 2019-03-13 15:04:16 +01:00
parent d0e0324e57
commit 75ac968b46
2 changed files with 32 additions and 4 deletions

View File

@ -10,10 +10,7 @@ import android.provider.CalendarContract.Reminders
import android.util.SparseIntArray
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.extensions.*
import com.simplemobiletools.calendar.pro.models.CalDAVCalendar
import com.simplemobiletools.calendar.pro.models.Event
import com.simplemobiletools.calendar.pro.models.EventType
import com.simplemobiletools.calendar.pro.models.Reminder
import com.simplemobiletools.calendar.pro.models.*
import com.simplemobiletools.calendar.pro.objects.States.isUpdatingCalDAV
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALENDAR
@ -474,6 +471,32 @@ class CalDAVHelper(val context: Context) {
return reminders.sortedBy { it.minutes }
}
private fun getCalDAVEventAttendees(eventId: Long): List<Attendee> {
val attendees = ArrayList<Attendee>()
val uri = CalendarContract.Attendees.CONTENT_URI
val projection = arrayOf(
CalendarContract.Attendees.ATTENDEE_NAME,
CalendarContract.Attendees.ATTENDEE_EMAIL,
CalendarContract.Attendees.ATTENDEE_STATUS)
val selection = "${CalendarContract.Attendees.EVENT_ID} = $eventId"
var cursor: Cursor? = null
try {
cursor = context.contentResolver.query(uri, projection, selection, null, null)
if (cursor?.moveToFirst() == true) {
do {
val name = cursor.getStringValue(CalendarContract.Attendees.ATTENDEE_NAME)
val email = cursor.getStringValue(CalendarContract.Attendees.ATTENDEE_EMAIL)
val status = cursor.getIntValue(CalendarContract.Attendees.ATTENDEE_STATUS)
val attendee = Attendee(name, email, status)
attendees.add(attendee)
} while (cursor.moveToNext())
}
} finally {
cursor?.close()
}
return attendees
}
private fun getCalDAVEventImportId(calendarId: Int, eventId: Long) = "$CALDAV-$calendarId-$eventId"
private fun refreshCalDAVCalendar(event: Event) = context.refreshCalDAVCalendars(event.getCalDAVCalendarId().toString(), false)

View File

@ -0,0 +1,5 @@
package com.simplemobiletools.calendar.pro.models
data class Attendee(val name: String, val email: String, val status: Int) {
fun getPublicName() = if (name.isNotEmpty()) name else email
}