Commit cb85b540 by Daniel Dahan

renamed the Reminders subspec to Events and updated the Reminders API based on…

renamed the Reminders subspec to Events and updated the Reminders API based on the latest rework concepts
parent 510173b2
......@@ -31,9 +31,8 @@ Pod::Spec.new do |s|
photos.dependency 'Material/Core'
end
s.subspec 'Reminders' do |reminders|
reminders.source_files = 'Sources/iOS/Reminders/*.swift'
reminders.dependency 'Material/Core'
s.subspec 'Events' do |events|
events.source_files = 'Sources/iOS/Events/*.swift'
events.dependency 'Material/Core'
end
end
......@@ -34,16 +34,14 @@
961E6BDF1DDA2A95004E6C93 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961E6BDE1DDA2A95004E6C93 /* Application.swift */; };
961E6BE21DDA2AF3004E6C93 /* Screen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961E6BE11DDA2AF3004E6C93 /* Screen.swift */; };
96328B7A1E020A41009A4C90 /* CollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96328B791E020A41009A4C90 /* CollectionViewController.swift */; };
96328B911E05B6B5009A4C90 /* Reminders.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96328B901E05B6B5009A4C90 /* Reminders.swift */; };
96328B931E05B6E5009A4C90 /* RemindersController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96328B921E05B6E5009A4C90 /* RemindersController.swift */; };
96328B971E05C0BB009A4C90 /* TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96328B961E05C0BB009A4C90 /* TableView.swift */; };
96328B991E05C0CE009A4C90 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96328B981E05C0CE009A4C90 /* TableViewController.swift */; };
96328B9B1E05C24E009A4C90 /* CollectionViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96328B791E020A41009A4C90 /* CollectionViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96328B9C1E05C24E009A4C90 /* Reminders.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96328B901E05B6B5009A4C90 /* Reminders.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96328B9D1E05C24E009A4C90 /* RemindersController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96328B921E05B6E5009A4C90 /* RemindersController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96328B9E1E05C24E009A4C90 /* TableView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96328B961E05C0BB009A4C90 /* TableView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96328B9F1E05C24E009A4C90 /* TableViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96328B981E05C0CE009A4C90 /* TableViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96334EF61C8B84660083986B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96334EF51C8B84660083986B /* Assets.xcassets */; };
9639526C1EC3882F004BA9DE /* Reminders.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9639526A1EC3882F004BA9DE /* Reminders.swift */; };
9639526D1EC3882F004BA9DE /* RemindersController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9639526B1EC3882F004BA9DE /* RemindersController.swift */; };
965E80CC1DD4C50600D61E4B /* Bar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7981CB40DC500C806FE /* Bar.swift */; };
965E80CD1DD4C50600D61E4B /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7701CB40DC500C806FE /* Button.swift */; };
965E80CE1DD4C50600D61E4B /* FABButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB75F1CB40DC500C806FE /* FABButton.swift */; };
......@@ -204,12 +202,12 @@
9628645E1D540AF300690B69 /* DynamicFontType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DynamicFontType.swift; sourceTree = "<group>"; };
9631A7C01D95E3AC00CFB109 /* PresenterCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresenterCard.swift; sourceTree = "<group>"; };
96328B791E020A41009A4C90 /* CollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewController.swift; sourceTree = "<group>"; };
96328B901E05B6B5009A4C90 /* Reminders.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Reminders.swift; path = Reminders/Reminders.swift; sourceTree = "<group>"; };
96328B921E05B6E5009A4C90 /* RemindersController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RemindersController.swift; path = Reminders/RemindersController.swift; sourceTree = "<group>"; };
96328B961E05C0BB009A4C90 /* TableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableView.swift; sourceTree = "<group>"; };
96328B981E05C0CE009A4C90 /* TableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = "<group>"; };
96334EF51C8B84660083986B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
963832361B88DFD80015F710 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Material.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9639526A1EC3882F004BA9DE /* Reminders.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reminders.swift; sourceTree = "<group>"; };
9639526B1EC3882F004BA9DE /* RemindersController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemindersController.swift; sourceTree = "<group>"; };
963FBEFC1D669510008F8512 /* Snackbar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Snackbar.swift; sourceTree = "<group>"; };
965532281E47E388005C2792 /* SpringAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpringAnimation.swift; sourceTree = "<group>"; };
9658F2161CD6FA4700B902C1 /* IconButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IconButton.swift; sourceTree = "<group>"; };
......@@ -372,15 +370,6 @@
name = BottomTabBar;
sourceTree = "<group>";
};
96328B8F1E05B69A009A4C90 /* Reminders */ = {
isa = PBXGroup;
children = (
96328B901E05B6B5009A4C90 /* Reminders.swift */,
96328B921E05B6E5009A4C90 /* RemindersController.swift */,
);
name = Reminders;
sourceTree = "<group>";
};
96328B9A1E05C135009A4C90 /* Data */ = {
isa = PBXGroup;
children = (
......@@ -405,6 +394,15 @@
name = Products;
sourceTree = "<group>";
};
963952691EC3882F004BA9DE /* Events */ = {
isa = PBXGroup;
children = (
9639526A1EC3882F004BA9DE /* Reminders.swift */,
9639526B1EC3882F004BA9DE /* RemindersController.swift */,
);
path = Events;
sourceTree = "<group>";
};
963FBEFB1D6694E8008F8512 /* Snackbar */ = {
isa = PBXGroup;
children = (
......@@ -510,6 +508,7 @@
96328B9A1E05C135009A4C90 /* Data */,
96BCB80B1CB410CC00C806FE /* Device */,
96230AB61D6A51FD00AF47DC /* Divider */,
963952691EC3882F004BA9DE /* Events */,
96BCB80A1CB410A100C806FE /* Extension */,
963FBF021D6696D0008F8512 /* FABMenu */,
96BCB8071CB4101C00C806FE /* Font */,
......@@ -522,7 +521,6 @@
96BCB8011CB40F1700C806FE /* Navigation */,
961E6BEF1DDA4B04004E6C93 /* NavigationDrawer */,
96717B151DBE6B1800DA84DB /* Photos */,
96328B8F1E05B69A009A4C90 /* Reminders */,
9626CA951DAB5370003E2611 /* Root */,
961E6BE01DDA2ADD004E6C93 /* Screen */,
963FBF031D6696EF008F8512 /* SearchBar */,
......@@ -819,8 +817,6 @@
9617B0901DFCA8CF00410F8F /* Toolbar.swift in Headers */,
9617B0911DFCA8CF00410F8F /* ToolbarController.swift in Headers */,
96328B9B1E05C24E009A4C90 /* CollectionViewController.swift in Headers */,
96328B9C1E05C24E009A4C90 /* Reminders.swift in Headers */,
96328B9D1E05C24E009A4C90 /* RemindersController.swift in Headers */,
96328B9E1E05C24E009A4C90 /* TableView.swift in Headers */,
96328B9F1E05C24E009A4C90 /* TableViewController.swift in Headers */,
961409B01E43D15C00E7BA99 /* CollectionViewCard.swift in Headers */,
......@@ -936,14 +932,14 @@
965E81161DD4D5C800D61E4B /* DisplayStyle.swift in Sources */,
965E81171DD4D5C800D61E4B /* RootController.swift in Sources */,
965E81181DD4D5C800D61E4B /* Snackbar.swift in Sources */,
96328B911E05B6B5009A4C90 /* Reminders.swift in Sources */,
965E81191DD4D5C800D61E4B /* SnackbarController.swift in Sources */,
965E811A1DD4D5C800D61E4B /* StatusBarController.swift in Sources */,
965E811B1DD4D5C800D61E4B /* Switch.swift in Sources */,
96328B931E05B6E5009A4C90 /* RemindersController.swift in Sources */,
9639526C1EC3882F004BA9DE /* Reminders.swift in Sources */,
965E811C1DD4D5C800D61E4B /* TabBar.swift in Sources */,
965E811D1DD4D5C800D61E4B /* TableViewCell.swift in Sources */,
965E811E1DD4D5C800D61E4B /* TextField.swift in Sources */,
9639526D1EC3882F004BA9DE /* RemindersController.swift in Sources */,
965E811F1DD4D5C800D61E4B /* ErrorTextField.swift in Sources */,
965E81211DD4D5C800D61E4B /* TextStorage.swift in Sources */,
965E81221DD4D5C800D61E4B /* TextView.swift in Sources */,
......
......@@ -28,7 +28,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import EventKit
@objc(RemindersAuthorizationStatus)
......@@ -110,32 +109,84 @@ open class Reminders: NSObject {
open weak var delegate: RemindersDelegate?
open func requestAuthorization(_ completion: ((RemindersAuthorizationStatus) -> Void)? = nil) {
eventStore.requestAccess(to: .reminder) { [weak self, completion = completion] (permission, _) in
eventStore.requestAccess(to: .reminder) { [weak self, completion = completion] (isAuthorized, _) in
DispatchQueue.main.async { [weak self, completion = completion] in
guard let s = self else {
return
}
if permission {
s.delegate?.reminders?(reminders: s, status: .authorized)
s.delegate?.reminders?(authorized: s)
completion?(.authorized)
} else {
guard isAuthorized else {
completion?(.denied)
s.delegate?.reminders?(reminders: s, status: .denied)
s.delegate?.reminders?(denied: s)
completion?(.denied)
return
}
completion?(.authorized)
s.delegate?.reminders?(reminders: s, status: .authorized)
s.delegate?.reminders?(authorized: s)
}
}
}
}
// List CRUD operations
extension Reminders {
/**
Creates a predicate for the reminders Array of calendars.
- Parameter in calendars: An optional Array of EKCalendars.
*/
open func predicateForReminders(in calendars: [EKCalendar]) -> NSPredicate {
return eventStore.predicateForReminders(in: calendars)
}
/**
A method for creating new Reminder lists
- Parameter list title: the name of the list
- Parameter completion: optional completion call back
A method for retrieving reminder calendars in alphabetical order.
- Parameter completion: A completion call back
*/
open func calendars(completion: @escaping ([EKCalendar]) -> Void) {
DispatchQueue.global(qos: .default).async { [weak self, completion = completion] in
guard let s = self else {
return
}
let calendar = s.eventStore.calendars(for: .reminder).sorted(by: { (a, b) -> Bool in
return a.title < b.title
})
DispatchQueue.main.async { [calendar = calendar, completion = completion] in
completion(calendar)
}
}
}
/**
A method for retrieving events with a predicate in date sorted order.
- Parameter predicate: A NSPredicate.
- Parameter completion: A completion call back.
*/
open func reminders(matching predicate: NSPredicate, completion: @escaping ([EKReminder]) -> Void) {
eventStore.fetchReminders(matching: predicate, completion: { [completion = completion] (reminders) in
DispatchQueue.main.async { [completion = completion] in
completion(reminders ?? [])
}
})
}
/**
Fetch all the reminders in a given Array of calendar.
- Parameter in calendars: An Array of EKCalendars.
- Parameter completion: A completion call back.
*/
open func reminders(in calendars: [EKCalendar], completion: @escaping ([EKReminder]) -> Void) {
reminders(matching: predicateForReminders(in: calendars), completion: completion)
}
}
extension Reminders {
/**
A method for creating new Reminder calendar.
- Parameter list title: the name of the list.
- Parameter completion: An optional completion call back.
*/
open func create(list title: String, completion: ((Bool, Error?) -> Void)? = nil) {
DispatchQueue.global(qos: .default).async { [weak self, completion = completion] in
......@@ -173,9 +224,9 @@ extension Reminders {
}
/**
A method for deleting existing Reminder lists
- Parameter list identifier: the name of the list
- Parameter completion: optional completion call back
A method for deleting existing Reminder lists,
- Parameter list identifier: the name of the list.
- Parameter completion: An optional completion call back.
*/
open func delete(list identifier: String, completion: ((Bool, Error?) -> Void)? = nil) {
DispatchQueue.global(qos: .default).async { [weak self, completion = completion] in
......@@ -207,99 +258,83 @@ extension Reminders {
}
}
}
/**
A method for retrieving reminder lists
- Parameter completion: completion call back
*/
public func fetchLists(completion: ([EKCalendar]) -> Void) {
completion(eventStore.calendars(for: .reminder))
}
}
// Reminder list CRUD operations
extension Reminders {
/**
A method for retrieving reminders from an optionally existing list.
if the list does not exist the reminders will be retrieved from the default reminders list
- Parameter list: An optional EKCalendar.
- Parameter completion: completion call back
*/
open func fetchReminders(list: EKCalendar, completion: @escaping ([EKReminder]) -> Void) {
var lists = [EKCalendar]()
lists.append(list)
eventStore.fetchReminders(matching: eventStore.predicateForReminders(in: lists), completion: { [completion = completion] (reminders) in
DispatchQueue.main.async { [completion = completion] in
completion(reminders ?? [])
}
})
}
// FIX ME: Should we use the calendar identifier here instead of the title for finding the right cal?
/**
A method for adding a new reminder to an optionally existing list.
if the list does not exist it will be added to the default reminders list.
- Parameter completion: optional completion call back
*/
open func create(title: String, dateComponents: DateComponents, in list: EKCalendar? = nil, completion: ((Error?) -> Void)? = nil) {
var reminderCal = [EKCalendar]()
if list != nil {
fetchLists(completion: { (calendars) in
for calendar in calendars {
if calendar.title == list!.title {
reminderCal.append(calendar)
}
}
})
}
let reminder = EKReminder(eventStore: eventStore)
reminder.title = title
reminder.dueDateComponents = dateComponents
reminder.calendar = reminderCal.last!
var created: Bool = false
var error: Error?
do {
try eventStore.save(reminder, commit: true)
created = true
} catch let e {
error = e
}
DispatchQueue.main.async { [weak self] in
guard let s = self else {
return
}
s.delegate?.reminders?(reminders: s, created: created)
if let c = completion {
c(error)
}
}
}
// FIX ME: Should we use the calendar identifier here instead of the title for finding the right cal?
/**
A method for adding a new reminder to an optionally existing list.
if the list does not exist it will be added to the default reminders list.
- Parameter completion: optional completion call back
*/
open func delete(reminder: EKReminder, completion: ((Error?) -> Void)? = nil) {
var deleted: Bool = false
var error: Error?
do {
try eventStore.remove(reminder, commit: true)
deleted = true
} catch let e {
error = e
}
DispatchQueue.main.async { [weak self] in
guard let s = self else {
return
}
s.delegate?.reminders?(reminders: s, deleted: deleted)
if let c = completion {
c(error)
}
}
}
// // FIX ME: Should we use the calendar identifier here instead of the title for finding the right cal?
// /**
// A method for adding a new reminder to an optionally existing list.
// if the list does not exist it will be added to the default reminders list.
// - Parameter completion: optional A completion call back
// */
// open func create(title: String, dateComponents: DateComponents, in calendar: EKCalendar? = nil, completion: ((Error?) -> Void)? = nil) {
// var reminderCal = [EKCalendar]()
//
// if calendar != nil {
// calendars(completion: { (calendars) in
// for v in calendars {
// if v.title == calendar!.title {
// reminderCal.append(calendar)
// }
// }
// })
// }
//
// let reminder = EKReminder(eventStore: eventStore)
// reminder.title = title
// reminder.dueDateComponents = dateComponents
// reminder.calendar = reminderCal.last!
//
// var created: Bool = false
// var error: Error?
//
// do {
// try eventStore.save(reminder, commit: true)
// created = true
// } catch let e {
// error = e
// }
//
// DispatchQueue.main.async { [weak self] in
// guard let s = self else {
// return
// }
//
// s.delegate?.reminders?(reminders: s, created: created)
//
// if let c = completion {
// c(error)
// }
// }
// }
//
// // FIX ME: Should we use the calendar identifier here instead of the title for finding the right cal?
// /**
// A method for adding a new reminder to an optionally existing list.
// if the list does not exist it will be added to the default reminders list.
// - Parameter completion: An optional completion call back.
// */
// open func delete(reminder: EKReminder, completion: ((Error?) -> Void)? = nil) {
// var deleted: Bool = false
// var error: Error?
//
// do {
// try eventStore.remove(reminder, commit: true)
// deleted = true
// } catch let e {
// error = e
// }
//
// DispatchQueue.main.async { [weak self] in
// guard let s = self else {
// return
// }
//
// s.delegate?.reminders?(reminders: s, deleted: deleted)
//
// if let c = completion {
// c(error)
// }
// }
// }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment