From 8e40e4a99b37c1722b0a2909f4ee5857581df6c0 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Mon, 9 Aug 2021 22:27:07 -0500 Subject: [PATCH] Update UpcomingEventsDataSource.swift --- .../UpcomingEventsDataSource.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift b/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift index 9cfd543..ee5c68b 100644 --- a/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift +++ b/Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift @@ -4,11 +4,13 @@ import Foundation class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollectionViewDelegateFlowLayout { private var upcomingEvents: [EventInfo] = [] + private var eventCenter: EventCenter! private weak var delegate: UpcomingEventPanelDelegate? - init(_ panelDelegate: UpcomingEventPanelDelegate?) { + init(_ panelDelegate: UpcomingEventPanelDelegate?, _ center: EventCenter) { super.init() delegate = panelDelegate + eventCenter = center } func updateEventsDataSource(_ events: [EventInfo]) { @@ -16,7 +18,7 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti } func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int { - if upcomingEvents.isEmpty { + if eventCenter.calendarAccessDenied() || eventCenter.calendarAccessNotDetermined() || upcomingEvents.isEmpty { return 1 } return upcomingEvents.count @@ -24,8 +26,13 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem { let item = collectionView.makeItem(withIdentifier: UpcomingEventViewItem.reuseIdentifier, for: indexPath) as! UpcomingEventViewItem + if eventCenter.calendarAccessNotDetermined() { + item.setupUndeterminedState(delegate) + return item + } + if upcomingEvents.isEmpty { - item.setupUndeterminedState(delegate) + item.setupEmptyState() return item } @@ -37,7 +44,7 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti } func collectionView(_ collectionView: NSCollectionView, layout _: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize { - if upcomingEvents.isEmpty { + if upcomingEvents.isEmpty || eventCenter.calendarAccessNotDetermined() { return NSSize(width: collectionView.frame.width - 20, height: 50) }