Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing event JSON mapping #382

Merged
merged 2 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ class CalendarDelegate : PluginRegistry.RequestPermissionsResultListener {
private fun buildEventContentValues(event: Event, calendarId: String): ContentValues {
val values = ContentValues()
val duration: String? = null
values.put(Events.ALL_DAY, event.allDay)
values.put(Events.ALL_DAY, event.eventAllDay)

if (event.allDay) {
if (event.eventAllDay) {
val calendar = java.util.Calendar.getInstance()
calendar.timeInMillis = event.eventStartDate!!
calendar.set(java.util.Calendar.HOUR, 0)
Expand All @@ -479,18 +479,18 @@ class CalendarDelegate : PluginRegistry.RequestPermissionsResultListener {

values.put(Events.DTSTART, calendar.timeInMillis)
values.put(Events.DTEND, calendar.timeInMillis)
values.put(Events.EVENT_TIMEZONE, getTimeZone(event.startTimeZone).id)
values.put(Events.EVENT_TIMEZONE, getTimeZone(event.eventStartTimeZone).id)
} else {
values.put(Events.DTSTART, event.eventStartDate!!)
values.put(Events.EVENT_TIMEZONE, getTimeZone(event.startTimeZone).id)
values.put(Events.EVENT_TIMEZONE, getTimeZone(event.eventStartTimeZone).id)

values.put(Events.DTEND, event.eventEndDate!!)
values.put(Events.EVENT_END_TIMEZONE, getTimeZone(event.endTimeZone).id)
values.put(Events.EVENT_END_TIMEZONE, getTimeZone(event.eventEndTimeZone).id)
}
values.put(Events.TITLE, event.title)
values.put(Events.DESCRIPTION, event.description)
values.put(Events.EVENT_LOCATION, event.location)
values.put(Events.CUSTOM_APP_URI, event.url)
values.put(Events.TITLE, event.eventTitle)
values.put(Events.DESCRIPTION, event.eventDescription)
values.put(Events.EVENT_LOCATION, event.eventLocation)
values.put(Events.CUSTOM_APP_URI, event.eventURL)
values.put(Events.CALENDAR_ID, calendarId)
values.put(Events.DURATION, duration)
values.put(Events.AVAILABILITY, getAvailability(event.availability))
Expand Down Expand Up @@ -713,18 +713,18 @@ class CalendarDelegate : PluginRegistry.RequestPermissionsResultListener {
val availability = parseAvailability(cursor.getInt(EVENT_PROJECTION_AVAILABILITY_INDEX))

val event = Event()
event.title = title ?: "New Event"
event.eventTitle = title ?: "New Event"
event.eventId = eventId.toString()
event.calendarId = calendarId
event.description = description
event.eventDescription = description
event.eventStartDate = begin
event.eventEndDate = end
event.allDay = allDay
event.location = location
event.url = url
event.eventAllDay = allDay
event.eventLocation = location
event.eventURL = url
event.recurrenceRule = parseRecurrenceRuleString(recurringRule)
event.startTimeZone = startTimeZone
event.endTimeZone = endTimeZone
event.eventStartTimeZone = startTimeZone
event.eventEndTimeZone = endTimeZone
event.availability = availability

return event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,17 @@ class DeviceCalendarPlugin() : FlutterPlugin, MethodCallHandler, ActivityAware {

private fun parseEventArgs(call: MethodCall, calendarId: String?): Event {
val event = Event()
event.title = call.argument<String>(EVENT_TITLE_ARGUMENT)
event.eventTitle = call.argument<String>(EVENT_TITLE_ARGUMENT)
event.calendarId = calendarId
event.eventId = call.argument<String>(EVENT_ID_ARGUMENT)
event.description = call.argument<String>(EVENT_DESCRIPTION_ARGUMENT)
event.allDay = call.argument<Boolean>(EVENT_ALL_DAY_ARGUMENT) ?: false
event.eventDescription = call.argument<String>(EVENT_DESCRIPTION_ARGUMENT)
event.eventAllDay = call.argument<Boolean>(EVENT_ALL_DAY_ARGUMENT) ?: false
event.eventStartDate = call.argument<Long>(EVENT_START_DATE_ARGUMENT)!!
event.eventEndDate = call.argument<Long>(EVENT_END_DATE_ARGUMENT)!!
event.startTimeZone = call.argument<String>(EVENT_START_TIMEZONE_ARGUMENT)
event.endTimeZone = call.argument<String>(EVENT_END_TIMEZONE_ARGUMENT)
event.location = call.argument<String>(EVENT_LOCATION_ARGUMENT)
event.url = call.argument<String>(EVENT_URL_ARGUMENT)
event.eventStartTimeZone = call.argument<String>(EVENT_START_TIMEZONE_ARGUMENT)
event.eventEndTimeZone = call.argument<String>(EVENT_END_TIMEZONE_ARGUMENT)
event.eventLocation = call.argument<String>(EVENT_LOCATION_ARGUMENT)
event.eventURL = call.argument<String>(EVENT_URL_ARGUMENT)
event.availability = parseAvailability(call.argument<String>(EVENT_AVAILABILITY_ARGUMENT))

if (call.hasArgument(RECURRENCE_RULE_ARGUMENT) && call.argument<Map<String, Any>>(RECURRENCE_RULE_ARGUMENT) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package com.builttoroam.devicecalendar.models


class Event {
var title: String? = null
var eventTitle: String? = null
var eventId: String? = null
var calendarId: String? = null
var description: String? = null
var eventDescription: String? = null
var eventStartDate: Long? = null
var eventEndDate: Long? = null
var startTimeZone: String? = null
var endTimeZone: String? = null
var allDay: Boolean = false
var location: String? = null
var url: String? = null
var eventStartTimeZone: String? = null
var eventEndTimeZone: String? = null
var eventAllDay: Boolean = false
var eventLocation: String? = null
var eventURL: String? = null
var attendees: MutableList<Attendee> = mutableListOf()
var recurrenceRule: RecurrenceRule? = null
var organizer: Attendee? = null
Expand Down
24 changes: 12 additions & 12 deletions ios/Classes/SwiftDeviceCalendarPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin {
struct Event: Codable {
let eventId: String
let calendarId: String
let title: String
let description: String?
let eventTitle: String
let eventDescription: String?
let eventStartDate: Int64
let eventEndDate: Int64
let startTimeZone: String?
let allDay: Bool
let eventStartTimeZone: String?
let eventAllDay: Bool
let attendees: [Attendee]
let location: String?
let url: String?
let eventLocation: String?
let eventURL: String?
let recurrenceRule: RecurrenceRule?
let organizer: Attendee?
let reminders: [Reminder]
Expand Down Expand Up @@ -350,15 +350,15 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin {
let event = Event(
eventId: ekEvent.eventIdentifier,
calendarId: calendarId,
title: ekEvent.title ?? "New Event",
description: ekEvent.notes,
eventTitle: ekEvent.title ?? "New Event",
eventDescription: ekEvent.notes,
eventStartDate: Int64(ekEvent.startDate.millisecondsSinceEpoch),
eventEndDate: Int64(ekEvent.endDate.millisecondsSinceEpoch),
startTimeZone: ekEvent.timeZone?.identifier,
allDay: ekEvent.isAllDay,
eventStartTimeZone: ekEvent.timeZone?.identifier,
eventAllDay: ekEvent.isAllDay,
attendees: attendees,
location: ekEvent.location,
url: ekEvent.url?.absoluteString,
eventLocation: ekEvent.location,
eventURL: ekEvent.url?.absoluteString,
recurrenceRule: recurrenceRule,
organizer: convertEkParticipantToAttendee(ekParticipant: ekEvent.organizer),
reminders: reminders,
Expand Down