Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 75e5be4f authored by Patrick Lang's avatar Patrick Lang Committed by GitHub
Browse files

Added recuridTimezone and adapted logic for RecurrenceId (#100)

* Added recuridTimezone and adapted logic for RecurrenceId

* minor code improvement
parent 8c34e814
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ open class JtxICalObject(
    var exdate: String? = null   //only for recurring events, see https://tools.ietf.org/html/rfc5545#section-3.8.5.1
    var rdate: String? = null    //only for recurring events, see https://tools.ietf.org/html/rfc5545#section-3.8.5.2
    var recurid: String? = null  //only for recurring events, see https://tools.ietf.org/html/rfc5545#section-3.8.5

    var recuridTimezone: String? = null
    //var rstatus: String? = null

    var collectionId: Long = collection.id
@@ -416,7 +416,15 @@ open class JtxICalObject(
                        }
                        iCalObject.exdate = exdateList.toTypedArray().joinToString(separator = ",")
                    }
                    is RecurrenceId -> iCalObject.recurid = prop.value
                    is RecurrenceId -> {
                        iCalObject.recurid = prop.date.toString()
                        iCalObject.recuridTimezone = when {
                            prop.date is DateTime && prop.timeZone != null ->  prop.timeZone.id
                            prop.date is DateTime && prop.isUtc -> TimeZone.getTimeZone("UTC").id
                            prop.date is DateTime && !prop.isUtc && prop.timeZone == null -> null
                            else -> TZ_ALLDAY     // prop.date is Date (and not DateTime), therefore it must be Allday
                        }
                    }

                    //is RequestStatus -> iCalObject.rstatus = prop.value

@@ -932,10 +940,12 @@ open class JtxICalObject(
            props += RRule(rrule)
        }
        recurid?.let { recurid ->
            props += if(dtstartTimezone == TZ_ALLDAY)
                RecurrenceId(Date(recurid))
            else
                RecurrenceId(DateTime(recurid))
            props += when {
                recuridTimezone == TZ_ALLDAY -> RecurrenceId(Date(recurid))
                recuridTimezone == TimeZone.getTimeZone("UTC").id -> RecurrenceId(DateTime(recurid).apply { this.isUtc = true })
                recuridTimezone.isNullOrEmpty() -> RecurrenceId(DateTime(recurid).apply { this.isUtc = false })
                else -> RecurrenceId(DateTime(recurid, TimeZoneRegistryFactory.getInstance().createRegistry().getTimeZone(recuridTimezone)))
            }
        }

        rdate?.let { rdateString ->
@@ -1428,6 +1438,7 @@ duration?.let(props::add)
        this.rdate = newData.rdate
        this.exdate = newData.exdate
        this.recurid = newData.recurid
        this.recuridTimezone = newData.recuridTimezone


        this.categories = newData.categories
@@ -1483,6 +1494,7 @@ duration?.let(props::add)
        values.getAsString(JtxContract.JtxICalObject.EXDATE)?.let { exdate -> this.exdate = exdate }
        values.getAsString(JtxContract.JtxICalObject.RDATE)?.let { rdate -> this.rdate = rdate }
        values.getAsString(JtxContract.JtxICalObject.RECURID)?.let { recurid -> this.recurid = recurid }
        values.getAsString(JtxContract.JtxICalObject.RECURID_TIMEZONE)?.let { recuridTimezone -> this.recuridTimezone = recuridTimezone }

        this.collectionId = collection.id
        values.getAsString(JtxContract.JtxICalObject.DIRTY)?.let { dirty -> this.dirty = dirty == "1" || dirty == "true" }
@@ -1709,6 +1721,7 @@ duration?.let(props::add)
        put(JtxContract.JtxICalObject.RDATE, rdate)
        put(JtxContract.JtxICalObject.EXDATE, exdate)
        put(JtxContract.JtxICalObject.RECURID, recurid)
        put(JtxContract.JtxICalObject.RECURID_TIMEZONE, recuridTimezone)

        put(JtxContract.JtxICalObject.FILENAME, fileName)
        put(JtxContract.JtxICalObject.ETAG, eTag)
+12 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ object JtxContract {
    const val AUTHORITY = "at.techbee.jtx.provider"

    /** The version of this SyncContentProviderContract */
    const val VERSION = 5
    const val VERSION = 6

    /** Constructs an Uri for the Jtx Sync Adapter with the given Account
     * @param [account] The account that should be appended to the Base Uri
@@ -450,6 +450,17 @@ object JtxContract {
         */
        const val RECURID = "recurid"

        /**
         * Purpose:  This property is used in conjunction with the "UID" and
         * "SEQUENCE" properties to identify a specific instance of a
         * recurring "VEVENT", "VTODO", or "VJOURNAL" calendar component.
         * The property value is the original value of the "DTSTART" property
         * of the recurrence instance, ie. a DATE or DATETIME value e.g. "20211101T160000".
         * Must be null for non-recurring and original events from which recurring events are derived.
         * Type: [String?]
         */
        const val RECURID_TIMEZONE = "recuridtimezone"

        /**
         * Stores the reference to the original event from which the recurring event was derived.
         * This value is NULL for the orignal event or if the event is not recurring