@@ -12,7 +12,6 @@ import SwiftMessages
1212
1313class ScheduleTableViewController : UITableViewController {
1414
15-
1615 // MARK: Ivars
1716 var scheduleTimer = Timer ( )
1817
@@ -24,7 +23,7 @@ class ScheduleTableViewController: UITableViewController {
2423 // Custom wrapper struct around an Event, to store additional UI parameters. Namely:
2524 // timelinePoint: whether or not the event has a dot to the left
2625 // allColor: a defined color for the timeline, for this event
27- struct TimelineEvent : CustomStringConvertible {
26+ class TimelineEvent : CustomStringConvertible {
2827 var timelinePoint : TimelinePoint ?
2928 var isFavorite : Bool
3029 var allColor : UIColor
@@ -37,16 +36,16 @@ class ScheduleTableViewController: UITableViewController {
3736 self . event = event
3837 }
3938
40- init ( allColor: UIColor , event: Event ) {
39+ convenience init ( allColor: UIColor , event: Event ) {
4140 self . init ( timelinePoint: nil , isFavorite: false , allColor: allColor, event: event)
4241 }
4342
44- init ( ) {
43+ convenience init ( ) {
4544 self . init ( timelinePoint: nil , isFavorite: false , allColor: UIColor . clear, event: Event ( ) )
4645 }
4746
4847 var description : String {
49- return " \( event. title ) | \( event . time ) | \( event . timeString ) | \( event . description ) "
48+ return " \( event) "
5049 }
5150 }
5251 var timelineEvents = [ TimelineEvent] ( )
@@ -81,6 +80,7 @@ class ScheduleTableViewController: UITableViewController {
8180 override func numberOfSections( in tableView: UITableView ) -> Int {
8281 // This property is stored in the ScheduleParser,
8382 // as this is pretty much the only time it's needed here.
83+ print ( " from sec num: \( ScheduleParser . sectionCount) " )
8484 return ScheduleParser . sectionCount
8585 }
8686
@@ -240,7 +240,6 @@ class ScheduleTableViewController: UITableViewController {
240240 // Otherwise set proper date
241241 cell. textLabel!. text = sectionDate
242242
243-
244243 return cell
245244
246245 }
@@ -263,45 +262,55 @@ class ScheduleTableViewController: UITableViewController {
263262
264263 // First, get an updated verison of the schedule
265264 // (Handles UI, threaded)
266- updateSchedule ( )
265+ updateSchedule ( ) {
267266
268- // @FIXME: Update to reflect new model
269- // Start at -1 as we look at the next index to see if the current is over yet
270- /*
271- for sectionIndex in -1..<ScheduleParser.sectionCount {
267+ // Don't parse if no sections available
268+ // (Sanity guard, shouldn't happen)
269+ guard ScheduleParser . sectionCount >= 1 else {
270+ print ( " nope " )
271+ return
272+ }
272273
273- // Grab the next section's date
274- let sectionDate = self.sampleData[sectionIndex + 1]!.first!.date
274+ // Start at -1 as we look at the next index to see if the current is over yet
275+ print ( " sectionCount: \( ScheduleParser . sectionCount) " )
276+ for sectionIndex in 0 ..< ScheduleParser . sectionCount {
275277
276- // If greater, STOP. We are at the current section.
277- if (sectionDate > Date(timeIntervalSinceNow: 0)) {
278- break
279- }
278+ // Grab the next section's date
279+ print ( self . timelineEvents)
280+ let events = self . timelineEvents. filter ( { $0. event. section == sectionIndex } )
281+ print ( events)
282+ let sectionDate = events. first!. event. time
283+
284+ // If greater, STOP. We are at the current section.
285+ if ( sectionDate > Date ( timeIntervalSinceNow: 0 ) ) {
286+ break
287+ }
280288
281- // Otherwise, go on to configure this current section as "passed"
282- var currentSection = self.sampleData[sectionIndex]!
283- for eventIndex in 0..<currentSection.count {
289+ // Otherwise, go on to configure this current section as "passed"
290+ self . timelineEvents. filter ( { $0. event. section == sectionIndex } ) . forEach { timelineEvent in
284291
285- currentSection[eventIndex].allColor = self.backColor
292+ print ( " updated \( timelineEvent) " )
293+ timelineEvent. allColor = self . backColor
286294
287- // Only "fill" timeline point if it's defined for that cell
288- if (currentSection[eventIndex] .timelinePoint != nil) {
289- currentSection[eventIndex].timelinePoint = TimelinePoint(color: self.backColor, filled: true)
295+ if timelineEvent . timelinePoint != nil {
296+ timelineEvent . timelinePoint = TimelinePoint ( color : self . backColor , filled : true )
297+ }
290298 }
299+
300+ // @TODO: Set the current event with a TimelinePoint
301+
291302 }
292- }
293- */
294303
304+ DispatchQueue . main. async {
305+ self . tableView. reloadData ( )
306+ }
295307
296- // And of course, reload the table.
297- DispatchQueue . main. async {
298- self . tableView. reloadData ( )
299308 }
300309
301310 }
302311
303312 // Updates the listing of events from the Google Sheet
304- func updateSchedule( ) {
313+ func updateSchedule( completion : @escaping ( ) -> ( ) ) {
305314
306315 // Create custom toast to use for alerting the user
307316 let toastView = MessageView . viewFromNib ( layout: . messageView)
@@ -336,14 +345,16 @@ class ScheduleTableViewController: UITableViewController {
336345 self . timelineEvents. append ( TimelineEvent ( allColor: self . frontColor, event: event) )
337346 }
338347
348+ completion ( )
349+
339350 // Finally, update the table now that our model is full
340351 DispatchQueue . main. async {
341352
342353 self . tableView. reloadData ( )
343354
344355 print ( " EVENTS AFTER REFRESH: " )
345356 for event in self . timelineEvents {
346- print ( event)
357+ // print(event)
347358 }
348359
349360 // Show toast to user
0 commit comments