mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-18 04:40:36 +01:00
fix updating event type colors for caldav events
- add color field to Event class so it's included in the computation for hashCode, hashCode is used to determine when to update events
This commit is contained in:
parent
7fcf854e1a
commit
57fe6796ab
@ -14,10 +14,10 @@ import com.simplemobiletools.calendar.pro.models.*
|
|||||||
import com.simplemobiletools.calendar.pro.objects.States.isUpdatingCalDAV
|
import com.simplemobiletools.calendar.pro.objects.States.isUpdatingCalDAV
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import org.joda.time.DateTimeZone
|
|
||||||
import org.joda.time.format.DateTimeFormat
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
import org.joda.time.DateTimeZone
|
||||||
|
import org.joda.time.format.DateTimeFormat
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
class CalDAVHelper(val context: Context) {
|
class CalDAVHelper(val context: Context) {
|
||||||
@ -37,6 +37,7 @@ class CalDAVHelper(val context: Context) {
|
|||||||
title = calendar.displayName
|
title = calendar.displayName
|
||||||
caldavDisplayName = calendar.displayName
|
caldavDisplayName = calendar.displayName
|
||||||
caldavEmail = calendar.accountName
|
caldavEmail = calendar.accountName
|
||||||
|
color = calendar.color
|
||||||
eventsHelper.insertOrUpdateEventTypeSync(this)
|
eventsHelper.insertOrUpdateEventTypeSync(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +66,8 @@ class CalDAVHelper(val context: Context) {
|
|||||||
Calendars.ACCOUNT_TYPE,
|
Calendars.ACCOUNT_TYPE,
|
||||||
Calendars.OWNER_ACCOUNT,
|
Calendars.OWNER_ACCOUNT,
|
||||||
Calendars.CALENDAR_COLOR,
|
Calendars.CALENDAR_COLOR,
|
||||||
Calendars.CALENDAR_ACCESS_LEVEL)
|
Calendars.CALENDAR_ACCESS_LEVEL
|
||||||
|
)
|
||||||
|
|
||||||
val selection = if (ids.trim().isNotEmpty()) "${Calendars._ID} IN ($ids)" else null
|
val selection = if (ids.trim().isNotEmpty()) "${Calendars._ID} IN ($ids)" else null
|
||||||
context.queryCursor(uri, projection, selection, showErrors = showToasts) { cursor ->
|
context.queryCursor(uri, projection, selection, showErrors = showToasts) { cursor ->
|
||||||
@ -87,33 +89,15 @@ class CalDAVHelper(val context: Context) {
|
|||||||
fun updateCalDAVCalendar(eventType: EventType) {
|
fun updateCalDAVCalendar(eventType: EventType) {
|
||||||
val uri = Calendars.CONTENT_URI
|
val uri = Calendars.CONTENT_URI
|
||||||
val newUri = ContentUris.withAppendedId(uri, eventType.caldavCalendarId.toLong())
|
val newUri = ContentUris.withAppendedId(uri, eventType.caldavCalendarId.toLong())
|
||||||
val projection = arrayOf(
|
val values = ContentValues().apply {
|
||||||
Calendars.CALENDAR_COLOR_KEY,
|
put(Calendars.CALENDAR_COLOR, eventType.color)
|
||||||
Calendars.CALENDAR_COLOR,
|
put(Calendars.CALENDAR_DISPLAY_NAME, eventType.title)
|
||||||
Calendars.CALENDAR_DISPLAY_NAME
|
|
||||||
)
|
|
||||||
|
|
||||||
context.queryCursor(newUri, projection) { cursor ->
|
|
||||||
val properColorKey = cursor.getIntValue(Calendars.CALENDAR_COLOR_KEY)
|
|
||||||
val properColor = cursor.getIntValue(Calendars.CALENDAR_COLOR)
|
|
||||||
val displayName = cursor.getStringValue(Calendars.CALENDAR_DISPLAY_NAME)
|
|
||||||
if (eventType.color != properColor || displayName != eventType.title) {
|
|
||||||
val values = fillCalendarContentValues(properColorKey, displayName)
|
|
||||||
try {
|
|
||||||
context.contentResolver.update(newUri, values, null, null)
|
|
||||||
eventType.color = properColor
|
|
||||||
eventType.title = displayName
|
|
||||||
context.eventTypesDB.insertOrUpdate(eventType)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
try {
|
||||||
|
context.contentResolver.update(newUri, values, null, null)
|
||||||
private fun fillCalendarContentValues(colorKey: Int, title: String): ContentValues {
|
context.eventTypesDB.insertOrUpdate(eventType)
|
||||||
return ContentValues().apply {
|
} catch (e: IllegalArgumentException) {
|
||||||
put(Calendars.CALENDAR_COLOR_KEY, colorKey)
|
e.printStackTrace()
|
||||||
put(Calendars.CALENDAR_DISPLAY_NAME, title)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +156,7 @@ class CalDAVHelper(val context: Context) {
|
|||||||
Events.CALENDAR_TIME_ZONE,
|
Events.CALENDAR_TIME_ZONE,
|
||||||
Events.DELETED,
|
Events.DELETED,
|
||||||
Events.AVAILABILITY
|
Events.AVAILABILITY
|
||||||
)
|
)
|
||||||
|
|
||||||
val selection = "${Events.CALENDAR_ID} = $calendarId"
|
val selection = "${Events.CALENDAR_ID} = $calendarId"
|
||||||
context.queryCursor(uri, projection, selection, showErrors = showToasts) { cursor ->
|
context.queryCursor(uri, projection, selection, showErrors = showToasts) { cursor ->
|
||||||
@ -209,11 +193,13 @@ class CalDAVHelper(val context: Context) {
|
|||||||
|
|
||||||
val source = "$CALDAV-$calendarId"
|
val source = "$CALDAV-$calendarId"
|
||||||
val repeatRule = Parser().parseRepeatInterval(rrule, startTS)
|
val repeatRule = Parser().parseRepeatInterval(rrule, startTS)
|
||||||
val event = Event(null, startTS, endTS, title, location, description, reminder1?.minutes ?: REMINDER_OFF,
|
val event = Event(
|
||||||
|
null, startTS, endTS, title, location, description, reminder1?.minutes ?: REMINDER_OFF,
|
||||||
reminder2?.minutes ?: REMINDER_OFF, reminder3?.minutes ?: REMINDER_OFF, reminder1?.type
|
reminder2?.minutes ?: REMINDER_OFF, reminder3?.minutes ?: REMINDER_OFF, reminder1?.type
|
||||||
?: REMINDER_NOTIFICATION, reminder2?.type ?: REMINDER_NOTIFICATION, reminder3?.type
|
?: REMINDER_NOTIFICATION, reminder2?.type ?: REMINDER_NOTIFICATION, reminder3?.type
|
||||||
?: REMINDER_NOTIFICATION, repeatRule.repeatInterval, repeatRule.repeatRule,
|
?: REMINDER_NOTIFICATION, repeatRule.repeatInterval, repeatRule.repeatRule,
|
||||||
repeatRule.repeatLimit, ArrayList(), attendees, importId, eventTimeZone, allDay, eventTypeId, source = source, availability = availability)
|
repeatRule.repeatLimit, ArrayList(), attendees, importId, eventTimeZone, allDay, eventTypeId, source = source, availability = availability
|
||||||
|
)
|
||||||
|
|
||||||
if (event.getIsAllDay()) {
|
if (event.getIsAllDay()) {
|
||||||
event.startTS = Formatter.getShiftedImportTimestamp(event.startTS)
|
event.startTS = Formatter.getShiftedImportTimestamp(event.startTS)
|
||||||
@ -471,7 +457,8 @@ class CalDAVHelper(val context: Context) {
|
|||||||
val uri = Reminders.CONTENT_URI
|
val uri = Reminders.CONTENT_URI
|
||||||
val projection = arrayOf(
|
val projection = arrayOf(
|
||||||
Reminders.MINUTES,
|
Reminders.MINUTES,
|
||||||
Reminders.METHOD)
|
Reminders.METHOD
|
||||||
|
)
|
||||||
val selection = "${Reminders.EVENT_ID} = $eventId"
|
val selection = "${Reminders.EVENT_ID} = $eventId"
|
||||||
|
|
||||||
context.queryCursor(uri, projection, selection) { cursor ->
|
context.queryCursor(uri, projection, selection) { cursor ->
|
||||||
@ -494,7 +481,8 @@ class CalDAVHelper(val context: Context) {
|
|||||||
Attendees.ATTENDEE_NAME,
|
Attendees.ATTENDEE_NAME,
|
||||||
Attendees.ATTENDEE_EMAIL,
|
Attendees.ATTENDEE_EMAIL,
|
||||||
Attendees.ATTENDEE_STATUS,
|
Attendees.ATTENDEE_STATUS,
|
||||||
Attendees.ATTENDEE_RELATIONSHIP)
|
Attendees.ATTENDEE_RELATIONSHIP
|
||||||
|
)
|
||||||
val selection = "${Attendees.EVENT_ID} = $eventId"
|
val selection = "${Attendees.EVENT_ID} = $eventId"
|
||||||
context.queryCursor(uri, projection, selection) { cursor ->
|
context.queryCursor(uri, projection, selection) { cursor ->
|
||||||
val name = cursor.getStringValue(Attendees.ATTENDEE_NAME) ?: ""
|
val name = cursor.getStringValue(Attendees.ATTENDEE_NAME) ?: ""
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
package com.simplemobiletools.calendar.pro.models
|
package com.simplemobiletools.calendar.pro.models
|
||||||
|
|
||||||
import androidx.collection.LongSparseArray
|
import androidx.collection.LongSparseArray
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.*
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.Index
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import com.simplemobiletools.calendar.pro.extensions.seconds
|
import com.simplemobiletools.calendar.pro.extensions.seconds
|
||||||
import com.simplemobiletools.calendar.pro.helpers.*
|
import com.simplemobiletools.calendar.pro.helpers.*
|
||||||
import com.simplemobiletools.commons.extensions.addBitIf
|
import com.simplemobiletools.commons.extensions.addBitIf
|
||||||
|
import java.io.Serializable
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import org.joda.time.DateTimeZone
|
import org.joda.time.DateTimeZone
|
||||||
import java.io.Serializable
|
|
||||||
|
|
||||||
@Entity(tableName = "events", indices = [(Index(value = ["id"], unique = true))])
|
@Entity(tableName = "events", indices = [(Index(value = ["id"], unique = true))])
|
||||||
data class Event(
|
data class Event(
|
||||||
@ -38,8 +35,10 @@ data class Event(
|
|||||||
@ColumnInfo(name = "parent_id") var parentId: Long = 0,
|
@ColumnInfo(name = "parent_id") var parentId: Long = 0,
|
||||||
@ColumnInfo(name = "last_updated") var lastUpdated: Long = 0L,
|
@ColumnInfo(name = "last_updated") var lastUpdated: Long = 0L,
|
||||||
@ColumnInfo(name = "source") var source: String = SOURCE_SIMPLE_CALENDAR,
|
@ColumnInfo(name = "source") var source: String = SOURCE_SIMPLE_CALENDAR,
|
||||||
@ColumnInfo(name = "availability") var availability: Int = 0)
|
@ColumnInfo(name = "availability") var availability: Int = 0,
|
||||||
: Serializable {
|
@Ignore
|
||||||
|
var color: Int = 0,
|
||||||
|
) : Serializable {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val serialVersionUID = -32456795132345616L
|
private const val serialVersionUID = -32456795132345616L
|
||||||
@ -196,8 +195,6 @@ data class Event(
|
|||||||
flags = flags.addBitIf(isPastEvent, FLAG_IS_PAST_EVENT)
|
flags = flags.addBitIf(isPastEvent, FLAG_IS_PAST_EVENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
var color: Int = 0
|
|
||||||
|
|
||||||
fun getTimeZoneString(): String {
|
fun getTimeZoneString(): String {
|
||||||
return if (timeZone.isNotEmpty() && getAllTimeZones().map { it.zoneName }.contains(timeZone)) {
|
return if (timeZone.isNotEmpty() && getAllTimeZones().map { it.zoneName }.contains(timeZone)) {
|
||||||
timeZone
|
timeZone
|
||||||
|
Loading…
x
Reference in New Issue
Block a user