Skip to content

Commit

Permalink
Merge pull request #394 from thomassth/event-json
Browse files Browse the repository at this point in the history
old args convertor
  • Loading branch information
thomassth authored Dec 28, 2021
2 parents bfbc843 + a74ffc3 commit e9b16ea
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 23 deletions.
30 changes: 16 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

## [4.1.0](https://github.com/builttoroam/device_calendar/releases/tag/4.1.0)

- Fix: Event JSONs created are now readable.
- Fix: Compilable for Flutter 2.9+
- Fix: title, descriptions etc are now retrieved properly.
- Fix: Event JSONs created and are now readable. Previous (mislabeled) JSONs are also readable with warnings.
- Fix: removed depreceated plugins from Example.
- Fix: Integration tests are now working. Android instructions are ready.
- Integration tests are now working. Android instructions are ready.
- Gradle plug-ins are updated.
- Compiles with jvm 1.8, should be compilable for Flutter 2.9+
- Android: proper support for all day events, and multi-day all day events.

## [4.0.1](https://github.com/builttoroam/device_calendar/releases/tag/4.0.1)

- Fixes event time retrieved
- Fix: event time are now properly retrieved

## [4.0.0](https://github.com/builttoroam/device_calendar/releases/tag/4.0.0)

Expand All @@ -34,7 +36,7 @@

## 3.1.0 25th March 2020 - Bug fixes and new features

- Boolean variable `isDefault` added for issue [145](https://github.com/builttoroam/device_calendar/issues/145) (**NOTE**: This is not supported Android API 16 or lower, `isDefault` will always be false)
- Boolean variable `isDefault` added for issue [145](https://github.com/builttoroam/device_calendar/issues/145) (**NOTE**: This is not supported Android API 16 or lower, `isDefault` will always be false)
- Events with 'null' title now defaults to 'New Event', issue [126](https://github.com/builttoroam/device_calendar/issues/126)
- Updated property summaries for issues [121](https://github.com/builttoroam/device_calendar/issues/121) and [122](https://github.com/builttoroam/device_calendar/issues/122)
- Updated example documentation for issue [119](https://github.com/builttoroam/device_calendar/issues/119)
Expand All @@ -61,15 +63,15 @@

## 3.0.0 21st January 2020

- **BREAKING CHANGE** Properties for the attendee model in `attendee.dart` file have been changed:
- Boolean property `isRequired` has been replaced to `AttendeeRole` enum
- New arugment added for `AttendeeRole` property
- **BREAKING CHANGE** Package updates:
- [Android] Updated Gradle plugin to 3.5.2 and Gradle wrapper to 5.4.1
- [iOS] Updated Swift to 5
- `name` and `isOrganiser` (read-only) properties have been added
- Attendee UI update for the example app
- Ability to add, modify or remove an attendee
- **BREAKING CHANGE** Properties for the attendee model in `attendee.dart` file have been changed:
- Boolean property `isRequired` has been replaced to `AttendeeRole` enum
- New arugment added for `AttendeeRole` property
- **BREAKING CHANGE** Package updates:
- [Android] Updated Gradle plugin to 3.5.2 and Gradle wrapper to 5.4.1
- [iOS] Updated Swift to 5
- `name` and `isOrganiser` (read-only) properties have been added
- Attendee UI update for the example app
- Ability to add, modify or remove an attendee

## 2.0.0 17th January 2020

Expand Down
6 changes: 3 additions & 3 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Examples

Most of the APIs are covered in [calendar_event.dart](https://github.com/builttoroam/device_calendar/blob/master/example/lib/presentation/pages/calendar_event.dart) or [calendar_events.dart](https://github.com/builttoroam/device_calendar/blob/master/example/lib/presentation/pages/calendar_events.dart) files in the example app.
You'll be able to get a reference of how the APIs are used.
Most of the APIs are covered in [calendar_event.dart](https://github.com/builttoroam/device_calendar/blob/master/example/lib/presentation/pages/calendar_event.dart) or [calendar_events.dart](https://github.com/builttoroam/device_calendar/blob/master/example/lib/presentation/pages/calendar_events.dart) files in the example app.
You'll be able to get a reference of how the APIs are used.

For a full API reference, the documentation can be found at [pub.dev](https://pub.dev/documentation/device_calendar/latest/device_calendar/device_calendar-library.html).
For a full API reference, the documentation can be found at [pub.dev](https://pub.dev/documentation/device_calendar/latest/device_calendar/device_calendar-library.html).

## DayOfWeekGroup Enum

Expand Down
53 changes: 47 additions & 6 deletions lib/src/models/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ class Event {
/// Indicates if this event counts as busy time, tentative, unavaiable or is still free time
late Availability availability;

///Note for development:
///
///JSON field names are coded in dart, swift and kotlin to facilitate data exchange.
///Make sure all locations are updated if changes needed to be made.
///Swift:
///`ios/Classes/SwiftDeviceCalendarPlugin.swift`
///Kotlin:
///`android/src/main/kotlin/com/builttoroam/devicecalendar/models/Event.kt`
///`android/src/main/kotlin/com/builttoroam/devicecalendar/CalendarDelegate.kt`
///`android/src/main/kotlin/com/builttoroam/devicecalendar/DeviceCalendarPlugin.kt`
Event(this.calendarId,
{this.eventId,
this.title,
Expand All @@ -60,33 +70,60 @@ class Event {
this.url,
this.allDay = false});

///Get Event from JSON.
///
///Sample JSON:
///{calendarId: 00, eventId: 0000, eventTitle: Sample Event, eventDescription: This is a sample event, eventStartDate: 1563719400000, eventStartTimeZone: Asia/Hong_Kong, eventEndDate: 1640532600000, eventEndTimeZone: Asia/Hong_Kong, eventAllDay: false, eventLocation: Yuenlong Station, eventURL: null, availability: BUSY, attendees: [{name: commonfolk, emailAddress: total.loss@hong.com, role: 1, isOrganizer: false, attendanceStatus: 3}], reminders: [{minutes: 39}]}
Event.fromJson(Map<String, dynamic>? json) {
if (json == null) {
throw ArgumentError(ErrorMessages.fromJsonMapIsNull);
}
String? foundUrl;
String? startLocationName;
String? endLocationName;
int? startTimestamp;
int? endTimestamp;
bool legacyJSON = false;
var legacyName = {
title: 'title',
description: 'description',
startTimestamp: 'start',
endTimestamp: 'end',
startLocationName: 'startTimeZone',
endLocationName: 'endTimeZone',
allDay: 'allDay',
location: 'location',
foundUrl: 'url',
};
legacyName.forEach((key, value) {
if (json[value] != null) {
key = json[value];
legacyJSON = true;
}
});

eventId = json['eventId'];
calendarId = json['calendarId'];
title = json['eventTitle'];
description = json['eventDescription'];

final int? startTimestamp = json['eventStartDate'];
final String? startLocationName = json['eventStartTimeZone'];
startTimestamp = json['eventStartDate'];
startLocationName = json['eventStartTimeZone'];
var startTimeZone = timeZoneDatabase.locations[startLocationName];
startTimeZone ??= local;
start = startTimestamp != null
? TZDateTime.fromMillisecondsSinceEpoch(startTimeZone, startTimestamp)
: TZDateTime.now(local);

final int? endTimestamp = json['eventEndDate'];
final String? endLocationName = json['eventEndTimeZone'];
endTimestamp = json['eventEndDate'];
endLocationName = json['eventEndTimeZone'];
var endLocation = timeZoneDatabase.locations[endLocationName];
endLocation ??= startTimeZone;
end = endTimestamp != null
? TZDateTime.fromMillisecondsSinceEpoch(endLocation, endTimestamp)
: TZDateTime.now(local);
allDay = json['eventAllDay'] ?? false;
if (Platform.isAndroid && (allDay ?? false)){
if (Platform.isAndroid && (allDay ?? false)) {
// On Android, the datetime in an allDay event is adjusted to local
// timezone, which can result in the wrong day, so we need to bring the
// date back to midnight UTC to get the correct date
Expand All @@ -102,7 +139,7 @@ class Event {
location = json['eventLocation'];
availability = parseStringToAvailability(json['availability']);

var foundUrl = json['eventURL']?.toString();
foundUrl = json['eventURL']?.toString();
if (foundUrl?.isEmpty ?? true) {
url = null;
} else {
Expand Down Expand Up @@ -138,6 +175,10 @@ class Event {
return Reminder.fromJson(decodedReminder);
}).toList();
}
if (legacyJSON) {
throw FormatException(
'legacy JSON detected. Please update your current JSONs as they may not be supported later on.');
}
}

Map<String, dynamic> toJson() {
Expand Down

0 comments on commit e9b16ea

Please sign in to comment.