mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-05 04:58:58 +01:00
handle adding attendees in caldav calendars
This commit is contained in:
parent
c457bb36b5
commit
b8f206e042
@ -5,6 +5,7 @@ import android.app.TimePickerDialog
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.CalendarContract
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
@ -1146,7 +1147,7 @@ class EventActivity : SimpleActivity() {
|
||||
val attendeeEmails = mAttendeeViews.map { it.value }.filter { it.isNotEmpty() }.toMutableList() as ArrayList<String>
|
||||
val attendees = ArrayList<Attendee>()
|
||||
attendeeEmails.mapTo(attendees) {
|
||||
Attendee("", it, 0)
|
||||
Attendee("", it, CalendarContract.Attendees.ATTENDEE_STATUS_INVITED)
|
||||
}
|
||||
return Gson().toJson(attendees)
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import android.provider.CalendarContract
|
||||
import android.provider.CalendarContract.Reminders
|
||||
import android.util.SparseIntArray
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.extensions.*
|
||||
import com.simplemobiletools.calendar.pro.models.*
|
||||
@ -323,6 +324,7 @@ class CalDAVHelper(val context: Context) {
|
||||
event.importId = getCalDAVEventImportId(calendarId, eventRemoteID)
|
||||
|
||||
setupCalDAVEventReminders(event)
|
||||
setupCalDAVEventAttendees(event)
|
||||
setupCalDAVEventImportId(event)
|
||||
refreshCalDAVCalendar(event)
|
||||
}
|
||||
@ -337,11 +339,11 @@ class CalDAVHelper(val context: Context) {
|
||||
context.contentResolver.update(newUri, values, null, null)
|
||||
|
||||
setupCalDAVEventReminders(event)
|
||||
setupCalDAVEventAttendees(event)
|
||||
setupCalDAVEventImportId(event)
|
||||
refreshCalDAVCalendar(event)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun setupCalDAVEventReminders(event: Event) {
|
||||
clearEventReminders(event)
|
||||
event.getReminders().forEach {
|
||||
@ -359,6 +361,25 @@ class CalDAVHelper(val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupCalDAVEventAttendees(event: Event) {
|
||||
clearEventAttendees(event)
|
||||
val attendees = Gson().fromJson<ArrayList<Attendee>>(event.attendees, object : TypeToken<List<Attendee>>() {}.type) ?: ArrayList()
|
||||
attendees.forEach {
|
||||
val contentValues = ContentValues().apply {
|
||||
put(CalendarContract.Attendees.ATTENDEE_NAME, it.name)
|
||||
put(CalendarContract.Attendees.ATTENDEE_EMAIL, it.email)
|
||||
put(CalendarContract.Attendees.ATTENDEE_STATUS, CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED)
|
||||
put(CalendarContract.Attendees.EVENT_ID, event.getCalDAVEventId())
|
||||
}
|
||||
|
||||
try {
|
||||
context.contentResolver.insert(CalendarContract.Attendees.CONTENT_URI, contentValues)
|
||||
} catch (e: Exception) {
|
||||
context.toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupCalDAVEventImportId(event: Event) {
|
||||
context.eventsDB.updateEventImportIdAndSource(event.importId, "$CALDAV-${event.getCalDAVCalendarId()}", event.id!!)
|
||||
}
|
||||
@ -394,13 +415,18 @@ class CalDAVHelper(val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun clearEventReminders(event: Event) {
|
||||
val selection = "${Reminders.EVENT_ID} = ?"
|
||||
val selectionArgs = arrayOf(event.getCalDAVEventId().toString())
|
||||
context.contentResolver.delete(Reminders.CONTENT_URI, selection, selectionArgs)
|
||||
}
|
||||
|
||||
private fun clearEventAttendees(event: Event) {
|
||||
val selection = "${CalendarContract.Attendees.EVENT_ID} = ?"
|
||||
val selectionArgs = arrayOf(event.getCalDAVEventId().toString())
|
||||
context.contentResolver.delete(CalendarContract.Attendees.CONTENT_URI, selection, selectionArgs)
|
||||
}
|
||||
|
||||
private fun getDurationCode(event: Event): String {
|
||||
return if (event.getIsAllDay()) {
|
||||
val dur = Math.max(1, (event.endTS - event.startTS) / DAY)
|
||||
@ -425,7 +451,6 @@ class CalDAVHelper(val context: Context) {
|
||||
refreshCalDAVCalendar(event)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun insertEventRepeatException(event: Event, occurrenceTS: Long): Long {
|
||||
val uri = CalendarContract.Events.CONTENT_URI
|
||||
val values = fillEventRepeatExceptionValues(event, occurrenceTS)
|
||||
|
Loading…
x
Reference in New Issue
Block a user