@@ -22,7 +22,9 @@ class ScheduleTableViewController: UITableViewController {
2222
2323 // Section 0 represents the previous and current events, colored backColor (except current)
2424 // Section 1 represents future events, colored frontColor.
25- var sampleData : [ Int : [ ( TimelinePoint ? , UIColor , String , String , Bool ) ] ] = [ : ]
25+ // timelinePoint, allColor, title, description, favorite
26+ var sampleData : [ Int : [ ( timelinePoint: TimelinePoint ? ,
27+ allColor: UIColor , title: String , description: String , isFavorite: Bool , date: Date ) ] ] = [ : ]
2628
2729 override func viewDidLoad( ) {
2830 super. viewDidLoad ( )
@@ -37,85 +39,81 @@ class ScheduleTableViewController: UITableViewController {
3739
3840 // Set timer for timeline refresh function,
3941 // which runs each minute (while the screen is visible) and updates the timeline view if necessary.
42+ // @TODO: Change from 5s to change on every hour, effectively caching the result
43+ // (or maybe don't bother with cache and do it every time the view is loaded / minimal persistance)
4044 scheduleTimer = Timer . scheduledTimer ( withTimeInterval: 5.0 , repeats: true , block: { timer in
4145
42- print ( " -------------- " )
43- print ( " OLD DATA FOR SECTION 0 " )
44- print ( self . sampleData [ 0 ] ? . last as Any )
46+ // Determine which section is currently active
47+ // (by default, 0)
4548
46- let dateFormatter = DateFormatter ( )
47- dateFormatter. dateFormat = " HH:mm "
48-
49- // Don't attempt to convert until data exists
50- guard self . sampleData [ 1 ] ? . first? . 2 != nil else {
49+ guard ( !self . sampleData. isEmpty) else {
5150 return
5251 }
5352
54- // Convert our date string into a date object
55- let dateString = dateFormatter. date ( from: self . sampleData [ 1 ] !. first!. 2 )
53+ for sectionIndex in - 1 ..< self . sampleData. count {
5654
57- guard dateString != nil else {
58- return
59- }
55+ // Grab the next section's date
56+ let sectionDate = self . sampleData [ sectionIndex + 1 ] !. first!. date
6057
61- // Do the comparison
62- if ( Date . init ( timeIntervalSinceNow: 0 ) >= dateString!) {
58+ // If greater, STOP. We are at the current section.
59+ if ( sectionDate > Date ( timeIntervalSinceNow: 0 ) ) {
60+ break
61+ }
6362
64- // Goal: If we have passed the current date, move the first item in section 1 to section 0.
63+ // Otherwise, go on to configure this current section as "passed"
64+ var currentSection = self . sampleData [ sectionIndex] !
65+ for eventIndex in 0 ..< currentSection. count {
6566
66- // Move first element of section 1 to end of section 0,
67- // and update color to show "completed"
68- var newCurrent = self . sampleData [ 1 ] !. first!
69- newCurrent. 1 = self . backColor
67+ currentSection [ eventIndex] . allColor = self . backColor
7068
71- // Only "fill" timeline point if it's defined for that cell
72- if ( newCurrent. 0 != nil ) {
73- newCurrent. 0 = TimelinePoint ( color: self . backColor, filled: true )
69+ // Only "fill" timeline point if it's defined for that cell
70+ if ( currentSection [ eventIndex] . timelinePoint != nil ) {
71+ currentSection [ eventIndex] . timelinePoint = TimelinePoint ( color: self . backColor, filled: true )
72+ }
7473 }
75-
76- // Reassign to first section
77- // @TODO: Why??
78- self . sampleData [ 1 ] !. removeFirst ( )
79- self . sampleData [ 0 ] !. append ( newCurrent)
8074 }
8175
8276 // And of course, reload the table.
8377 DispatchQueue . main. async {
8478 self . tableView. reloadData ( )
8579 }
8680
87- print ( " \n NEW DATA FOR SECTION 0 " )
88- print ( self . sampleData [ 0 ] !. last!)
8981 } )
9082
9183 scheduleTimer. fire ( )
9284
9385 /*
9486 * Static sample data to use.
9587 * Some notes:
96- * a) Set nil point to have smooth, continuous line past that event
97- * b) Section 0 (up to last event, which is current item) will be HIGHLIGHTED in primary color.
88+ * Each section corresponds to a time block. The header of each section will dictate the time.
89+ * An event is set to be the current event on a section-by-section basis in viewDidLoad
90+ * First point is ALWAYS filled. Rest is set in the timer closure on viewDidLoad.
9891 *
9992 * @TODO: Implement with pulled & parsed data from GSheets
10093 */
10194 self . sampleData = [
95+ // 9am sat
10296 0 : [
103- ( TimelinePoint ( color: backColor, filled: true ) , backColor, " 12:30 " , " Description. " , true ) ,
104- ( nil , backColor, " 15:30 " , " Description. " , false ) ,
105- ( TimelinePoint ( color: backColor, filled: true ) , backColor, " 16:30 " , " Description. " , false ) , // Current item
106- ] , 1 : [
107- ( TimelinePoint ( ) , frontColor, " 19:00 " , " Description. " , false ) ,
108- ( nil , frontColor, " 08:30 " , " Description. " , false ) ,
109- ( nil , frontColor, " 09:30 " , " Description. " , false ) ,
110- ( nil , frontColor, " 10:00 " , " Description. " , true ) ,
111- ( TimelinePoint ( ) , frontColor, " 11:30 " , " Description. " , false ) ,
112- ( TimelinePoint ( ) , frontColor, " 12:30 " , " Description. " , false ) ,
113- ( TimelinePoint ( ) , frontColor, " 13:00 " , " Description. " , false ) ,
114- ( TimelinePoint ( ) , frontColor, " 15:00 " , " Description. " , false ) ,
115- ( TimelinePoint ( ) , frontColor, " 17:30 " , " Description. " , false ) ,
116- ( TimelinePoint ( ) , frontColor, " 18:30 " , " Description. " , false ) ,
117- ( TimelinePoint ( ) , frontColor, " 19:30 " , " Description. " , false ) ,
118- ( TimelinePoint ( ) , frontColor, " 20:00 " , " Description. " , false ) ] ]
97+ ( TimelinePoint ( color: backColor, filled: true ) , backColor, " 9am 1 " , " Description. " , true , Date ( timeIntervalSince1970: 1581195600 ) ) ,
98+ ( nil , backColor, " 9am 2 " , " Description. " , false , Date ( timeIntervalSince1970: 1581195600 ) ) ] ,
99+ // 12am sun
100+ 1 : [
101+ ( TimelinePoint ( ) , frontColor, " 12am " , " Description. " , false , Date ( timeIntervalSince1970: 1581206400 ) ) ] ,
102+ // 7am sun
103+ 2 : [
104+ ( TimelinePoint ( ) , frontColor, " 7am " , " Description. " , false , Date ( timeIntervalSince1970: 1581231600 ) ) ] ,
105+ // 8am sun
106+ 3 : [
107+ ( TimelinePoint ( ) , frontColor, " 8am " , " Description. " , false , Date ( timeIntervalSince1970: 1581235200 ) ) ] ]
108+
109+ // Static data sample to use for sections.
110+ // From Figma: (sample date 2/8/2020)
111+ // Sat, 9pm (2 things but only one stored),
112+ // Sun, 12am, 7am, 8am
113+ // self.sectionMapping = [0: Date(timeIntervalSince1970: 1581195600), // 9am
114+ // 1: Date(timeIntervalSince1970: 1581206400), // 12am
115+ // 2: Date(timeIntervalSince1970: 1581231600), // 7am
116+ // 3: Date(timeIntervalSince1970: 1581235200)] // 8am
119117
120118 }
121119
@@ -140,7 +138,7 @@ class ScheduleTableViewController: UITableViewController {
140138 let cell = tableView. dequeueReusableCell ( withIdentifier: " TimelineTableViewCell " , for: indexPath) as! TimelineTableViewCell
141139
142140 // Grab from our custom config
143- let ( timelinePoint, allColor, title, description, favorite ) = sampleData [ indexPath. section] ![ indexPath. row]
141+ let ( timelinePoint, allColor, title, description, isFavorite , date ) = sampleData [ indexPath. section] ![ indexPath. row]
144142
145143
146144 /*
@@ -177,7 +175,11 @@ class ScheduleTableViewController: UITableViewController {
177175
178176 // Text content
179177 cell. titleLabel. text = title
180- cell. descriptionLabel. text = description
178+
179+ let dateFormatter = DateFormatter ( )
180+ dateFormatter. dateFormat = " HH "
181+ cell. descriptionLabel. text = dateFormatter. string ( from: date)
182+
181183
182184 // Set label color properly depending on dark mode, or no dark mode option.
183185 // Only change if bubble is not enableld to preserve contrast. Might need tweaking.
@@ -188,16 +190,22 @@ class ScheduleTableViewController: UITableViewController {
188190 }
189191
190192 // Configure favorite accessory
191- if favorite {
193+ if isFavorite {
192194 cell. accessoryView = UIImageView ( image: UIImage ( named: " filledStar " ) )
193195 } else {
194196 cell. accessoryView = UIImageView ( image: UIImage ( named: " emptyStar " ) )
195197 }
196198
199+ // Confgure bubble
200+ cell. bubbleColor = UIColor . clear
201+ cell. bubbleWidth = 20.0
202+ cell. bubbleBorderColor = UIColor ( named: " primaryColor " ) !
203+
197204 // Disable selection per cell
198205 cell. selectionStyle = . none
199206
200207 // Layout adjustment
208+ // (Accessory adjustment is done in @peterkos/TimelineTableViewCell)
201209 cell. timeline. leftMargin = 30.0
202210
203211 return cell
@@ -209,4 +217,30 @@ class ScheduleTableViewController: UITableViewController {
209217 // @TODO: Check if margin updates when using forked TimelineTableViewCell eventually
210218 }
211219
220+ // MARK: Section headers and view configuration
221+
222+ override func tableView( _ tableView: UITableView , viewForHeaderInSection section: Int ) -> UIView ? {
223+ // @TODO:
224+ // Implement header design, timeframes in each section in data model,
225+ // make Description font bigger, move accessory margin (- instead of + in TimelineTableViewCell),
226+ // Remove nasty bubble -- ask Chris about a good indicator to use for "active block".
227+ // (maybe make bar bigger?)
228+ return tableView. dequeueReusableCell ( withIdentifier: " header " )
229+
230+
231+ }
232+
233+ override func tableView( _ tableView: UITableView , heightForFooterInSection section: Int ) -> CGFloat {
234+ //@TODO
235+ return 44
236+ }
237+
238+ override func tableView( _ tableView: UITableView , titleForHeaderInSection section: Int ) -> String ? {
239+ switch section {
240+ case 0 : return " 9am "
241+ case 1 : return " 10am "
242+ default : return " Unknown "
243+ }
244+ }
245+
212246}
0 commit comments