Skip to content

Commit 3ec4b87

Browse files
committed
Complete table refactor
Schedule auto updates based on time Bubble customized slightly Section headers impelmented to match design, still need to be autoset (See next commit)
1 parent b4eb157 commit 3ec4b87

2 files changed

Lines changed: 108 additions & 56 deletions

File tree

BrickHack-Mobile/Base.lproj/Main.storyboard

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
<objects>
177177
<tableViewController id="g8Z-Z9-XAz" customClass="ProfileTableViewController" customModule="BrickHack_Mobile" customModuleProvider="target" sceneMemberID="viewController">
178178
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" scrollEnabled="NO" dataMode="static" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="ha2-zv-jvi">
179-
<rect key="frame" x="0.0" y="0.0" width="375" height="78"/>
179+
<rect key="frame" x="0.0" y="0.0" width="375" height="80"/>
180180
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
181181
<color key="tintColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
182182
<sections>
@@ -248,7 +248,7 @@
248248
<objects>
249249
<viewController id="aXh-cU-cZb" sceneMemberID="viewController">
250250
<view key="view" contentMode="scaleToFill" id="4b2-aF-V9H">
251-
<rect key="frame" x="0.0" y="0.0" width="375" height="78"/>
251+
<rect key="frame" x="0.0" y="0.0" width="375" height="80"/>
252252
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
253253
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
254254
<viewLayoutGuide key="safeArea" id="hdK-Am-Svz"/>
@@ -262,18 +262,36 @@
262262
<scene sceneID="up2-D5-I0e">
263263
<objects>
264264
<tableViewController id="S2k-45-cUt" customClass="ScheduleTableViewController" customModule="BrickHack_Mobile" customModuleProvider="target" sceneMemberID="viewController">
265-
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="mcs-hP-1ut">
265+
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="mcs-hP-1ut">
266266
<rect key="frame" x="0.0" y="0.0" width="375" height="534"/>
267267
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
268+
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
268269
<prototypes>
269270
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="scheduleCell" id="FAE-qX-Ggn">
270-
<rect key="frame" x="0.0" y="28" width="375" height="43.666667938232422"/>
271+
<rect key="frame" x="0.0" y="55.333332061767578" width="375" height="43.666667938232422"/>
271272
<autoresizingMask key="autoresizingMask"/>
272273
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="FAE-qX-Ggn" id="jbf-8f-lNS">
273274
<rect key="frame" x="0.0" y="0.0" width="375" height="43.666667938232422"/>
274275
<autoresizingMask key="autoresizingMask"/>
275276
</tableViewCellContentView>
276277
</tableViewCell>
278+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="header" textLabel="ogD-ie-wQm" style="IBUITableViewCellStyleDefault" id="gu8-gt-lsi">
279+
<rect key="frame" x="0.0" y="99" width="375" height="43.666667938232422"/>
280+
<autoresizingMask key="autoresizingMask"/>
281+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="gu8-gt-lsi" id="F2q-6m-jcz">
282+
<rect key="frame" x="0.0" y="0.0" width="375" height="43.666667938232422"/>
283+
<autoresizingMask key="autoresizingMask"/>
284+
<subviews>
285+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="ogD-ie-wQm">
286+
<rect key="frame" x="16" y="0.0" width="343" height="43.666667938232422"/>
287+
<autoresizingMask key="autoresizingMask"/>
288+
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
289+
<color key="textColor" name="primaryColor"/>
290+
<nil key="highlightedColor"/>
291+
</label>
292+
</subviews>
293+
</tableViewCellContentView>
294+
</tableViewCell>
277295
</prototypes>
278296
<sections/>
279297
<connections>

BrickHack-Mobile/Controllers/ScheduleTableViewController.swift

Lines changed: 86 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -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("\nNEW 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

Comments
 (0)