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

Brettl/add url #136

Merged
merged 6 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -122,6 +123,7 @@ class DeviceCalendarPlugin() : MethodCallHandler {
event.start = call.argument<Long>(EVENT_START_DATE_ARGUMENT)!!
event.end = call.argument<Long>(EVENT_END_DATE_ARGUMENT)!!
event.location = call.argument<String>(EVENT_LOCATION_ARGUMENT)
event.url = call.argument<String>(EVENT_URL_ARGUMENT)

if (call.hasArgument(RECURRENCE_RULE_ARGUMENT) && call.argument<Map<String, Any>>(RECURRENCE_RULE_ARGUMENT) != null) {
val recurrenceRule = parseRecurrenceRuleArgs(call)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = arrayOf(
CalendarContract.Instances.EVENT_ID,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Attendee> = mutableListOf()
var recurrenceRule: RecurrenceRule? = null
var organizer: Attendee? = null
Expand Down
4 changes: 2 additions & 2 deletions device_calendar/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions device_calendar/example/lib/presentation/event_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '',
overflow: TextOverflow.ellipsis,
),
)
],
),
),
SizedBox(
height: 10.0,
),
Align(
alignment: Alignment.topLeft,
child: Row(
Expand Down
12 changes: 12 additions & 0 deletions device_calendar/example/lib/presentation/pages/calendar_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@ class _CalendarEventPageState extends State<CalendarEventPage> {
},
),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: TextFormField(
initialValue: _event.url,
decoration: const InputDecoration(
labelText: 'URL',
hintText: 'https://google.com'),
onSaved: (String value) {
_event.url = value;
},
),
),
GestureDetector(
onTap: () async {
List<Attendee> result = await Navigator.push(
Expand Down
14 changes: 14 additions & 0 deletions device_calendar/ios/Classes/SwiftDeviceCalendarPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions device_calendar/lib/src/device_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class DeviceCalendarPlugin {
'eventStartDate': event.start.millisecondsSinceEpoch,
'eventEndDate': event.end.millisecondsSinceEpoch,
'eventLocation': event.location,
'eventURL': event.url,
'recurrenceRule': event.recurrenceRule?.toJson(),
'attendees': event.attendees?.map((a) => a.toJson())?.toList(),
'reminders': event.reminders?.map((r) => r.toJson())?.toList()
Expand Down
4 changes: 4 additions & 0 deletions device_calendar/lib/src/models/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class Event {
/// The location of this event
String location;

/// An URL for this event
String url;
nickrandolph marked this conversation as resolved.
Show resolved Hide resolved

/// A list of attendees for this event
List<Attendee> attendees;

Expand Down Expand Up @@ -70,6 +73,7 @@ class Event {
}
allDay = json['allDay'];
location = json['location'];
url = json['url'];
if (json['attendees'] != null) {
attendees = json['attendees'].map<Attendee>((decodedAttendee) {
return Attendee.fromJson(decodedAttendee);
Expand Down