@@ -10,6 +10,7 @@ import UIKit
10
10
import XLPagerTabStrip
11
11
import TrySwiftData
12
12
13
+
13
14
class SessionsTableViewController : UITableViewController {
14
15
private lazy var needsToScrollToCurrentSession = Calendar . current. isDateInToday ( conferenceDay. date)
15
16
@@ -33,15 +34,15 @@ class SessionsTableViewController: UITableViewController {
33
34
super. viewDidLoad ( )
34
35
35
36
configureTableView ( )
36
-
37
+
37
38
if traitCollection. forceTouchCapability == . available {
38
39
registerForPreviewing ( with: self , sourceView: tableView)
39
40
}
40
41
}
41
-
42
+
42
43
override func viewDidAppear( _ animated: Bool ) {
43
44
super. viewDidAppear ( animated)
44
-
45
+
45
46
if needsToScrollToCurrentSession {
46
47
needsToScrollToCurrentSession = false
47
48
scrollToCurrentSession ( animated: false )
@@ -55,32 +56,32 @@ class SessionsTableViewController: UITableViewController {
55
56
let isCollapsed = splitViewController? . isCollapsed,
56
57
!isCollapsed,
57
58
!didShowDetail else { return }
58
-
59
+
59
60
didShowDetail = true
60
61
scheduleViewController? . performSegue ( withIdentifier: sessionDetailsSegue, sender: firstSelectableSessionVC)
61
62
}
62
63
}
63
64
64
65
// MARK: - Table view data source
65
66
extension SessionsTableViewController {
66
-
67
+
67
68
override func numberOfSections( in tableView: UITableView ) -> Int {
68
69
return conferenceDay. sessionBlocks. count
69
70
}
70
-
71
+
71
72
override func tableView( _ tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
72
73
return conferenceDay. sessionBlocks [ section] . sessions. count
73
74
}
74
-
75
+
75
76
override func tableView( _ tableView: UITableView , cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
76
77
let cell = tableView. dequeueReusableCell ( forIndexPath: indexPath) as SessionTableViewCell
77
-
78
+
78
79
let session = conferenceDay. sessionBlocks [ indexPath. section] . sessions [ indexPath. row]
79
80
cell. configure ( withSession: session)
80
-
81
+
81
82
return cell
82
83
}
83
-
84
+
84
85
override func tableView( _ tableView: UITableView , titleForHeaderInSection section: Int ) -> String ? {
85
86
let session = conferenceDay. sessionBlocks [ section]
86
87
let sessionDateFormatter = DateFormatter . sessionDateFormatter
@@ -108,33 +109,33 @@ extension SessionsTableViewController: IndicatorInfoProvider {
108
109
}
109
110
110
111
extension SessionsTableViewController : UIViewControllerPreviewingDelegate {
111
-
112
+
112
113
func previewingContext( _ previewingContext: UIViewControllerPreviewing , viewControllerForLocation location: CGPoint ) -> UIViewController ? {
113
114
guard let indexPath = tableView. indexPathForRow ( at: location) else { return nil }
114
115
// This will show the cell clearly and blur the rest of the screen for our peek.
115
116
previewingContext. sourceRect = tableView. rectForRow ( at: indexPath)
116
117
let session = conferenceDay. sessionBlocks [ indexPath. section] . sessions [ indexPath. row]
117
118
return viewController ( for: session)
118
119
}
119
-
120
+
120
121
func previewingContext( _ previewingContext: UIViewControllerPreviewing , commit viewControllerToCommit: UIViewController ) {
121
122
scheduleViewController? . performSegue ( withIdentifier: sessionDetailsSegue, sender: viewControllerToCommit)
122
123
}
123
124
}
124
125
125
126
extension SessionsTableViewController {
126
-
127
+
127
128
func configureTableView( ) {
128
-
129
+
129
130
tableView. register ( SessionTableViewCell . self)
130
-
131
+
131
132
tableView. estimatedRowHeight = 160
132
133
tableView. rowHeight = UITableViewAutomaticDimension
133
134
}
134
135
}
135
136
136
137
private extension SessionsTableViewController {
137
-
138
+
138
139
func viewController( for session: Session ) -> UIViewController ? {
139
140
switch session. type {
140
141
case . talk, . lightningTalk:
@@ -174,39 +175,39 @@ private extension SessionsTableViewController {
174
175
default :
175
176
return nil
176
177
}
177
-
178
+
178
179
return nil
179
180
}
180
-
181
+
181
182
func sessionDetails( _ presentation: Presentation , session: Session ) -> UIViewController {
182
183
let storyboard = UIStoryboard ( name: " Main " , bundle: nil )
183
184
let sessionDetailsVC = storyboard. instantiateViewController ( withIdentifier: String ( describing: SessionDetailsViewController . self) ) as! SessionDetailsViewController
184
185
sessionDetailsVC. session = session
185
186
sessionDetailsVC. presentation = presentation
186
187
return sessionDetailsVC
187
188
}
188
-
189
+
189
190
func officeHourDetails( _ speaker: Speaker , session: Session ) -> UIViewController {
190
191
let officeHoursVC = OfficeHoursDetailViewController ( )
191
192
officeHoursVC. speaker = speaker
192
193
officeHoursVC. session = session
193
194
return officeHoursVC
194
195
}
195
-
196
+
196
197
func webDisplay( _ event: Event ) -> UIViewController {
197
198
let webViewController = WebDisplayViewController ( )
198
199
webViewController. url = URL ( string: event. website!)
199
200
webViewController. displayTitle = event. title
200
201
return webViewController
201
202
}
202
-
203
+
203
204
func webDisplay( _ sponsor: Sponsor ) -> UIViewController {
204
205
let webViewController = WebDisplayViewController ( )
205
206
webViewController. url = URL ( string: sponsor. url!)
206
207
webViewController. displayTitle = sponsor. name
207
208
return webViewController
208
209
}
209
-
210
+
210
211
func venueDetails( _ venue: Venue ) -> UIViewController {
211
212
let venueDetailsVC = VenueTableViewController ( venue: venue)
212
213
venueDetailsVC. tableView. contentInset = UIEdgeInsets ( top: 80 , left: 0 , bottom: 0 , right: 0 )
@@ -224,15 +225,21 @@ private extension SessionsTableViewController {
224
225
}
225
226
226
227
extension SessionsTableViewController {
227
-
228
+
228
229
func scrollToCurrentSession( animated: Bool ) {
229
230
let secondsFromGMT = TimeZone . current. secondsFromGMT ( )
230
231
guard
231
232
let date = Date ( ) . changed ( second: secondsFromGMT) ,
232
233
let section = conferenceDay. sessionBlocks. index ( where: { date < $0. endTime } ) ,
233
234
!conferenceDay. sessionBlocks [ section] . sessions. isEmpty
234
235
else { return }
235
-
236
+
236
237
tableView. scrollToRow ( at: IndexPath ( row: 0 , section: section) , at: . top, animated: animated)
237
238
}
238
239
}
240
+
241
+ extension SessionsTableViewController : ScrollableToTop {
242
+ func scrollAfterTabTap( ) {
243
+ scrollToCurrentSession ( animated: true )
244
+ }
245
+ }
0 commit comments