Skip to content

Commit 0e7427f

Browse files
committed
Current timeline parsing fixed!
TimelineEvents struct->class for modification in the timeline update logic Each section header now shows short name (e.g., “Sat 6:00pm”
1 parent 3d2b936 commit 0e7427f

2 files changed

Lines changed: 46 additions & 35 deletions

File tree

BrickHack-Mobile/Controllers/ScheduleTableViewController.swift

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import SwiftMessages
1212

1313
class 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

BrickHack-Mobile/Models/ScheduleParser.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct Event: CustomDebugStringConvertible {
2828
var time: Date
2929
var timeString: String {
3030
let dateFormatter = DateFormatter()
31-
dateFormatter.dateFormat = "hh:mm a"
31+
dateFormatter.dateFormat = "E hh:mm a"
3232
dateFormatter.timeZone = TimeZone(identifier: "UTC") // Already in ET, dont convert again
3333
return dateFormatter.string(from: time)
3434
}
@@ -200,7 +200,7 @@ class ScheduleParser {
200200
for columnIndex in 0..<rowData.columns.count {
201201

202202
// Skip section day header title ("Saturday", "Sunday").
203-
// "section" 0 is Saturday, 1 is sunday, etc.
203+
// "section" 0 is Saturday, 1 is sunday
204204
// Note that this is NOT the same as Table View sections -- remember, we are only in the model!
205205
// (and that's how it was named on the spreadsheet)
206206
if skip {
@@ -228,7 +228,7 @@ class ScheduleParser {
228228
currentEvent.section = dayIndex
229229
dayIndex += 1
230230

231-
// Skip the next iteration, whic just has the section day title.
231+
// Skip the next iteration, which just has the section day title.
232232
skip = true
233233
continue
234234

@@ -300,7 +300,7 @@ class ScheduleParser {
300300

301301
// Construct the proper day
302302
// 0: sat, 1: sun
303-
if sectionIndex == 0 {
303+
if dayIndex <= 0 {
304304
dateComponents.day = 8
305305
} else {
306306
dateComponents.day = 9

0 commit comments

Comments
 (0)