diff --git a/.gitignore b/.gitignore index 736ea414..dc649c50 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ doc/api/ device_calendar.code-workspace device_calendar/example/.flutter-plugins-dependencies device_calendar/example/ios/Flutter/flutter_export_environment.sh +device_calendar/example/ios/Flutter/Flutter.podspec diff --git a/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/CalendarDelegate.kt b/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/CalendarDelegate.kt index 73087c6a..5fdf1c8b 100644 --- a/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/CalendarDelegate.kt +++ b/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/CalendarDelegate.kt @@ -28,6 +28,7 @@ import com.builttoroam.devicecalendar.common.Constants.Companion.EVENT_PROJECTIO import com.builttoroam.devicecalendar.common.Constants.Companion.EVENT_PROJECTION_DESCRIPTION_INDEX import com.builttoroam.devicecalendar.common.Constants.Companion.EVENT_PROJECTION_END_INDEX import com.builttoroam.devicecalendar.common.Constants.Companion.EVENT_PROJECTION_EVENT_LOCATION_INDEX +import com.builttoroam.devicecalendar.common.Constants.Companion.EVENT_PROJECTION_CUSTOM_APP_URI_INDEX import com.builttoroam.devicecalendar.common.Constants.Companion.EVENT_PROJECTION_ID_INDEX import com.builttoroam.devicecalendar.common.Constants.Companion.EVENT_PROJECTION_RECURRING_RULE_INDEX import com.builttoroam.devicecalendar.common.Constants.Companion.EVENT_PROJECTION_TITLE_INDEX @@ -362,6 +363,7 @@ class CalendarDelegate : PluginRegistry.RequestPermissionsResultListener { 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.CALENDAR_ID, calendarId) values.put(Events.DURATION, duration) @@ -487,6 +489,7 @@ class CalendarDelegate : PluginRegistry.RequestPermissionsResultListener { val recurringRule = cursor.getString(EVENT_PROJECTION_RECURRING_RULE_INDEX) val allDay = cursor.getInt(EVENT_PROJECTION_ALL_DAY_INDEX) > 0 val location = cursor.getString(EVENT_PROJECTION_EVENT_LOCATION_INDEX) + var url = cursor.getString(EVENT_PROJECTION_CUSTOM_APP_URI_INDEX) val event = Event() event.title = title @@ -497,6 +500,7 @@ class CalendarDelegate : PluginRegistry.RequestPermissionsResultListener { event.end = end event.allDay = allDay event.location = location + event.url = url event.recurrenceRule = parseRecurrenceRuleString(recurringRule) return event } diff --git a/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/DeviceCalendarPlugin.kt b/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/DeviceCalendarPlugin.kt index a79839ea..3bc323ba 100644 --- a/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/DeviceCalendarPlugin.kt +++ b/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/DeviceCalendarPlugin.kt @@ -33,6 +33,7 @@ class DeviceCalendarPlugin() : MethodCallHandler { private val EVENT_ID_ARGUMENT = "eventId" private val EVENT_TITLE_ARGUMENT = "eventTitle" private val EVENT_LOCATION_ARGUMENT = "eventLocation" + private val EVENT_URL_ARGUMENT = "eventURL" private val EVENT_DESCRIPTION_ARGUMENT = "eventDescription" private val EVENT_START_DATE_ARGUMENT = "eventStartDate" private val EVENT_END_DATE_ARGUMENT = "eventEndDate" @@ -122,6 +123,7 @@ class DeviceCalendarPlugin() : MethodCallHandler { event.start = call.argument(EVENT_START_DATE_ARGUMENT)!! event.end = call.argument(EVENT_END_DATE_ARGUMENT)!! event.location = call.argument(EVENT_LOCATION_ARGUMENT) + event.url = call.argument(EVENT_URL_ARGUMENT) if (call.hasArgument(RECURRENCE_RULE_ARGUMENT) && call.argument>(RECURRENCE_RULE_ARGUMENT) != null) { val recurrenceRule = parseRecurrenceRuleArgs(call) diff --git a/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/common/Constants.kt b/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/common/Constants.kt index 29e8ffe7..3416d646 100644 --- a/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/common/Constants.kt +++ b/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/common/Constants.kt @@ -26,6 +26,7 @@ class Constants { const val EVENT_PROJECTION_RECURRING_RULE_INDEX: Int = 7 const val EVENT_PROJECTION_ALL_DAY_INDEX: Int = 8 const val EVENT_PROJECTION_EVENT_LOCATION_INDEX: Int = 9 + const val EVENT_PROJECTION_CUSTOM_APP_URI_INDEX: Int = 10 val EVENT_PROJECTION: Array = arrayOf( CalendarContract.Instances.EVENT_ID, @@ -37,7 +38,8 @@ class Constants { CalendarContract.Events.RDATE, CalendarContract.Events.RRULE, CalendarContract.Events.ALL_DAY, - CalendarContract.Events.EVENT_LOCATION + CalendarContract.Events.EVENT_LOCATION, + CalendarContract.Events.CUSTOM_APP_URI ) const val ATTENDEE_ID_INDEX: Int = 0 diff --git a/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/models/Event.kt b/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/models/Event.kt index f7c42808..f85a5809 100644 --- a/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/models/Event.kt +++ b/device_calendar/android/src/main/kotlin/com/builttoroam/devicecalendar/models/Event.kt @@ -9,6 +9,7 @@ class Event { var end: Long? = null var allDay: Boolean = false var location: String? = null + var url: String? = null var attendees: MutableList = mutableListOf() var recurrenceRule: RecurrenceRule? = null var organizer: Attendee? = null diff --git a/device_calendar/example/ios/Podfile.lock b/device_calendar/example/ios/Podfile.lock index 4383a0a8..b81b0078 100644 --- a/device_calendar/example/ios/Podfile.lock +++ b/device_calendar/example/ios/Podfile.lock @@ -15,8 +15,8 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: device_calendar: 23b28a5f1ab3bf77e34542fb1167e1b8b29a98f5 - Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a + Flutter: 0e3d915762c693b495b44d77113d4970485de6ec PODFILE CHECKSUM: ea0518673586564c605fb6593d385c0e3708ff8d -COCOAPODS: 1.7.2 +COCOAPODS: 1.8.4 diff --git a/device_calendar/example/lib/presentation/event_item.dart b/device_calendar/example/lib/presentation/event_item.dart index f38b5a10..f2b40038 100644 --- a/device_calendar/example/lib/presentation/event_item.dart +++ b/device_calendar/example/lib/presentation/event_item.dart @@ -112,6 +112,26 @@ class EventItem extends StatelessWidget { SizedBox( height: 10.0, ), + Align( + alignment: Alignment.topLeft, + child: Row( + children: [ + Container( + width: _eventFieldNameWidth, + child: Text('URL'), + ), + Expanded( + child: Text( + _calendarEvent?.url?.data?.contentText ?? '', + overflow: TextOverflow.ellipsis, + ), + ) + ], + ), + ), + SizedBox( + height: 10.0, + ), Align( alignment: Alignment.topLeft, child: Row( diff --git a/device_calendar/example/lib/presentation/pages/calendar_event.dart b/device_calendar/example/lib/presentation/pages/calendar_event.dart index 62d1f3fa..d543fd99 100644 --- a/device_calendar/example/lib/presentation/pages/calendar_event.dart +++ b/device_calendar/example/lib/presentation/pages/calendar_event.dart @@ -232,6 +232,19 @@ class _CalendarEventPageState extends State { }, ), ), + Padding( + padding: const EdgeInsets.all(10.0), + child: TextFormField( + initialValue: _event.url?.data?.contentText ?? '', + decoration: const InputDecoration( + labelText: 'URL', + hintText: 'https://google.com'), + onSaved: (String value) { + var uri = Uri.dataFromString(value); + _event.url = uri; + }, + ), + ), GestureDetector( onTap: () async { List result = await Navigator.push( diff --git a/device_calendar/ios/Classes/SwiftDeviceCalendarPlugin.swift b/device_calendar/ios/Classes/SwiftDeviceCalendarPlugin.swift index 8b177a04..24e40dcb 100644 --- a/device_calendar/ios/Classes/SwiftDeviceCalendarPlugin.swift +++ b/device_calendar/ios/Classes/SwiftDeviceCalendarPlugin.swift @@ -29,6 +29,7 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin { let allDay: Bool let attendees: [Attendee] let location: String? + let url: String? let recurrenceRule: RecurrenceRule? let organizer: Attendee? let reminders: [Reminder] @@ -83,6 +84,7 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin { let eventStartDateArgument = "eventStartDate" let eventEndDateArgument = "eventEndDate" let eventLocationArgument = "eventLocation" + let eventURLArgument = "eventURL" let attendeesArgument = "attendees" let recurrenceRuleArgument = "recurrenceRule" let recurrenceFrequencyArgument = "recurrenceFrequency" @@ -221,6 +223,7 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin { allDay: ekEvent.isAllDay, attendees: attendees, location: ekEvent.location, + url: ekEvent.url?.absoluteString, recurrenceRule: recurrenceRule, organizer: convertEkParticipantToAttendee(ekParticipant: ekEvent.organizer), reminders: reminders @@ -387,6 +390,7 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin { let title = arguments[self.eventTitleArgument] as! String let description = arguments[self.eventDescriptionArgument] as? String let location = arguments[self.eventLocationArgument] as? String + let url = arguments[self.eventURLArgument] as? String let ekCalendar = self.eventStore.calendar(withIdentifier: calendarId) if (ekCalendar == nil) { self.finishWithCalendarNotFoundError(result: result, calendarId: calendarId) @@ -415,6 +419,16 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin { ekEvent!.endDate = endDate ekEvent!.calendar = ekCalendar! ekEvent!.location = location + + // Create and add URL object only when if the input string is not empty or nil + if let urlCheck = url, !urlCheck.isEmpty { + let iosUrl = URL(string: url ?? "") + ekEvent!.url = iosUrl + } + else { + ekEvent!.url = nil + } + ekEvent!.recurrenceRules = createEKRecurrenceRules(arguments) setAttendees(arguments, ekEvent) ekEvent!.alarms = createReminders(arguments) diff --git a/device_calendar/lib/src/device_calendar.dart b/device_calendar/lib/src/device_calendar.dart index 4ba56df5..1dc81cbf 100644 --- a/device_calendar/lib/src/device_calendar.dart +++ b/device_calendar/lib/src/device_calendar.dart @@ -186,6 +186,7 @@ class DeviceCalendarPlugin { 'eventStartDate': event.start.millisecondsSinceEpoch, 'eventEndDate': event.end.millisecondsSinceEpoch, 'eventLocation': event.location, + 'eventURL': event.url.data.contentText, 'recurrenceRule': event.recurrenceRule?.toJson(), 'attendees': event.attendees?.map((a) => a.toJson())?.toList(), 'reminders': event.reminders?.map((r) => r.toJson())?.toList() diff --git a/device_calendar/lib/src/models/event.dart b/device_calendar/lib/src/models/event.dart index 6e0d38b8..0cab693e 100644 --- a/device_calendar/lib/src/models/event.dart +++ b/device_calendar/lib/src/models/event.dart @@ -31,6 +31,9 @@ class Event { /// The location of this event String location; + /// An URL for this event + Uri url; + /// A list of attendees for this event List attendees; @@ -70,6 +73,15 @@ class Event { } allDay = json['allDay']; location = json['location']; + + var foundUrl = json['url']?.toString(); + if (foundUrl?.isEmpty ?? true) { + url = null; + } + else { + url = Uri.dataFromString(foundUrl); + } + if (json['attendees'] != null) { attendees = json['attendees'].map((decodedAttendee) { return Attendee.fromJson(decodedAttendee);