Browse Source

Calendar alerts in compact mode!

pull/92/head
Abhishek 5 years ago
parent
commit
0ca2f22cef
  1. 34
      Clocker/Events and Reminders/CalendarHandler.swift
  2. 34
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  3. 3
      Clocker/Preferences/Calendar/CalendarViewController.swift

34
Clocker/Events and Reminders/CalendarHandler.swift

@ -53,6 +53,40 @@ extension EventCenter {
return sourcesAndCalendars return sourcesAndCalendars
} }
func separateFormat(event: EKEvent) -> (String, String)? {
guard let truncateLength = DataStore.shared().retrieve(key: CLTruncateTextLength) as? NSNumber, let eventTitle = event.title else {
return nil
}
let seconds = event.startDate.timeIntervalSinceNow
var formattedTitle: String = CLEmptyString
if eventTitle.count > truncateLength.intValue {
let truncateIndex = eventTitle.index(eventTitle.startIndex, offsetBy: truncateLength.intValue)
let truncatedTitle = String(eventTitle[..<truncateIndex])
formattedTitle.append(truncatedTitle)
formattedTitle.append("...")
} else {
formattedTitle.append(eventTitle)
}
var menubarText: String = CLEmptyString
let minutes = seconds / 60
if minutes > 2 {
let suffix = String(format: " in %0.f mins", minutes)
menubarText.append(suffix)
} else if minutes == 1 {
let suffix = String(format: " in %0.f min", minutes)
menubarText.append(suffix)
} else {
menubarText.append(" starts now.")
}
return (formattedTitle, menubarText)
}
func format(event: EKEvent) -> String { func format(event: EKEvent) -> String {
guard let truncateLength = DataStore.shared().retrieve(key: CLTruncateTextLength) as? NSNumber, let eventTitle = event.title else { guard let truncateLength = DataStore.shared().retrieve(key: CLTruncateTextLength) as? NSNumber, let eventTitle = event.title else {
return CLEmptyString return CLEmptyString

34
Clocker/Panel/Data Layer/TimezoneDataOperations.swift

@ -33,7 +33,37 @@ extension TimezoneDataOperations {
return dateFormatter.string(from: newDate) return dateFormatter.string(from: newDate)
} }
private func checkForUpcomingEvents() -> (String, String)? {
if DataStore.shared().shouldDisplay(.showMeetingInMenubar) {
let filteredDates = EventCenter.sharedCenter().eventsForDate
let autoupdatingCal = EventCenter.sharedCenter().autoupdatingCalendar
guard let events = filteredDates[autoupdatingCal.startOfDay(for: Date())] else {
return nil
}
for event in events {
if event.event.startDate.timeIntervalSinceNow > 0, !event.isAllDay {
let timeForEventToStart = event.event.startDate.timeIntervalSinceNow / 60
if timeForEventToStart > 30 {
print("Our next event: \(event.event.title ?? "Error") starts in \(timeForEventToStart) mins")
continue
}
return EventCenter.sharedCenter().separateFormat(event: event.event)
}
}
}
return nil
}
func compactMenuTitle() -> String { func compactMenuTitle() -> String {
if let upcomingEvent = checkForUpcomingEvents() {
return upcomingEvent.0
}
var subtitle = CLEmptyString var subtitle = CLEmptyString
let shouldDayBeShown = DataStore.shared().shouldShowDayInMenubar() let shouldDayBeShown = DataStore.shared().shouldShowDayInMenubar()
@ -54,6 +84,10 @@ extension TimezoneDataOperations {
} }
func compactMenuSubtitle() -> String { func compactMenuSubtitle() -> String {
if let upcomingEvent = checkForUpcomingEvents() {
return upcomingEvent.1
}
var subtitle = CLEmptyString var subtitle = CLEmptyString
let shouldDayBeShown = DataStore.shared().shouldShowDayInMenubar() let shouldDayBeShown = DataStore.shared().shouldShowDayInMenubar()

3
Clocker/Preferences/Calendar/CalendarViewController.swift

@ -87,9 +87,6 @@ class CalendarViewController: ParentViewController {
} else { } else {
showSegmentedControl.selectedSegment = 1 showSegmentedControl.selectedSegment = 1
} }
// If the menubar mode is compact, we can't show meetings in the menubar. So disable toggling that option.
showNextMeetingInMenubarControl.isEnabled = !DataStore.shared().shouldDisplay(.menubarCompactMode)
} }
private func verifyCalendarAccess() { private func verifyCalendarAccess() {

Loading…
Cancel
Save