@@ -90,31 +90,25 @@ class ScheduleTableViewController: UITableViewController {
9090 * First point is ALWAYS filled. Rest is set in the timer closure on viewDidLoad.
9191 *
9292 * @TODO: Implement with pulled & parsed data from GSheets
93+ *
94+ * From Figma: (sample date 2/8/2020)
95+ * Sat, 9pm (2 things but only one stored),
96+ * Sun, 12am, 7am, 8am
9397 */
9498 self . sampleData = [
9599 // 9am sat
96100 0 : [
97- ( TimelinePoint ( color: backColor, filled: true ) , backColor, " 9am 1 " , " Description. " , true , Date ( timeIntervalSince1970: 1581195600 ) ) ,
98- ( nil , backColor, " 9am 2 " , " Description. " , false , Date ( timeIntervalSince1970: 1581195600 ) ) ] ,
101+ ( TimelinePoint ( color: backColor, filled: true ) , backColor, " 9am 1 " , " Description. " , true , Date ( timeIntervalSince1970: 1581170400 ) ) ,
102+ ( nil , backColor, " 9am 2 " , " Description. " , false , Date ( timeIntervalSince1970: 1581170400 ) ) ] ,
99103 // 12am sun
100104 1 : [
101- ( TimelinePoint ( ) , frontColor, " 12am " , " Description. " , false , Date ( timeIntervalSince1970: 1581206400 ) ) ] ,
105+ ( TimelinePoint ( ) , frontColor, " 12am " , " Description. " , false , Date ( timeIntervalSince1970: 1581224400 ) ) ] ,
102106 // 7am sun
103107 2 : [
104- ( TimelinePoint ( ) , frontColor, " 7am " , " Description. " , false , Date ( timeIntervalSince1970: 1581231600 ) ) ] ,
108+ ( TimelinePoint ( ) , frontColor, " 7am " , " Description. " , false , Date ( timeIntervalSince1970: 1581249600 ) ) ] ,
105109 // 8am sun
106110 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
117-
111+ ( TimelinePoint ( ) , frontColor, " 8am " , " Description. " , false , Date ( timeIntervalSince1970: 1581253200 ) ) ] ]
118112 }
119113
120114 override func viewWillDisappear( _ animated: Bool ) {
@@ -138,6 +132,7 @@ class ScheduleTableViewController: UITableViewController {
138132 let cell = tableView. dequeueReusableCell ( withIdentifier: " TimelineTableViewCell " , for: indexPath) as! TimelineTableViewCell
139133
140134 // Grab from our custom config
135+ // Description unused for now
141136 let ( timelinePoint, allColor, title, description, isFavorite, date) = sampleData [ indexPath. section] ![ indexPath. row]
142137
143138
@@ -176,7 +171,7 @@ class ScheduleTableViewController: UITableViewController {
176171 cell. titleLabel. text = title
177172
178173 let dateFormatter = DateFormatter ( )
179- dateFormatter. dateFormat = " HH "
174+ dateFormatter. dateFormat = " hh:mm a "
180175 cell. descriptionLabel. text = dateFormatter. string ( from: date)
181176
182177
@@ -189,11 +184,20 @@ class ScheduleTableViewController: UITableViewController {
189184 }
190185
191186 // Configure favorite accessory
192- if isFavorite {
193- cell. accessoryView = UIImageView ( image: UIImage ( named: " filledStar " ) )
194- } else {
195- cell. accessoryView = UIImageView ( image: UIImage ( named: " emptyStar " ) )
196- }
187+
188+ // @TODO: Set toggle functionality
189+ // if isFavorite {
190+ // cell.accessoryView = UIImageView(image: UIImage(named: "filledStar"))
191+
192+ let favButton = FavoriteButton ( type: . custom)
193+ favButton. setImage ( UIImage ( named: " filledStar " ) , for: . normal)
194+ favButton. addTarget ( self , action: #selector( favoriteTapped ( sender: ) ) , for: . touchUpInside)
195+ favButton. tag = indexPath. row
196+ cell. accessoryView = favButton
197+ // Set custom properties
198+ favButton. section = indexPath. section
199+ favButton. row = indexPath. row
200+ favButton. sizeToFit ( )
197201
198202 // Confgure bubble
199203 cell. bubbleColor = UIColor . clear
@@ -210,18 +214,34 @@ class ScheduleTableViewController: UITableViewController {
210214 return cell
211215 }
212216
213- override func tableView( _ tableView: UITableView , accessoryButtonTappedForRowWith indexPath: IndexPath ) {
217+
218+ // Because of the Wonderful Way UIKit works (https://stackoverflow.com/a/12810613/1431900),
219+ // we have to define our own UIButton + handler for this accessoryView.
220+ // To get two points of data (section + row) instead of just one `tag`,
221+ // we use a subclassed UIButton, FavoriteButton, so we know what exact
222+ // event was pressed. (row is section-dependent)
223+ @objc func favoriteTapped( sender: UIButton ) {
224+ guard let favButton = sender as? FavoriteButton else {
225+ MessageHandler . showInvalidFavoriteButtonError ( )
226+ return
227+ }
228+ print ( " Tapped star at section \( favButton. section!) , \( favButton. row!) " )
229+
214230 // @TODO: Obvs read/write to/from server, but also:
215231 // @TODO: Change local data model, look for a table view delegate
216232 // @TODO: Check if margin updates when using forked TimelineTableViewCell eventually
217233 }
218234
235+ override func tableView( _ tableView: UITableView , accessoryButtonTappedForRowWith indexPath: IndexPath ) {
236+ print ( " defualt accButtonTapped: \( indexPath) " )
237+ }
238+
239+
240+
219241 // MARK: Section headers and view configuration
220242
221243 override func tableView( _ tableView: UITableView , viewForHeaderInSection section: Int ) -> UIView ? {
222244
223- print ( " Header for section \( section) " )
224-
225245 // Get our dummy cell from IB
226246 let cell = tableView. dequeueReusableCell ( withIdentifier: " header " ) !
227247
0 commit comments