Skip to content

Commit 46cee5c

Browse files
committed
Fix time, fix favorite button handling (mostly)
See the big comment for more info on why this mess had to be done
1 parent 32e26a3 commit 46cee5c

6 files changed

Lines changed: 81 additions & 26 deletions

File tree

BrickHack-Mobile.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
31C5F541219B29CD00E3E1AF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31C5F540219B29CD00E3E1AF /* AppDelegate.swift */; };
1515
31C5F546219B29CD00E3E1AF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 31C5F544219B29CD00E3E1AF /* Main.storyboard */; };
1616
31C5F548219B29CF00E3E1AF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 31C5F547219B29CF00E3E1AF /* Assets.xcassets */; };
17+
D750E81823DF67360075C639 /* FavoriteButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = D750E81723DF67360075C639 /* FavoriteButton.swift */; };
1718
D789978223D652ED0058060A /* ScheduleTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D789978123D652ED0058060A /* ScheduleTableViewController.swift */; };
1819
D789978523D6A4DC0058060A /* ProfileTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D789978423D6A4DC0058060A /* ProfileTableViewController.swift */; };
1920
D79AA2B823425DFA009C469D /* APIRoutes.swift in Sources */ = {isa = PBXBuildFile; fileRef = D79AA2B723425DFA009C469D /* APIRoutes.swift */; };
@@ -49,6 +50,7 @@
4950
31C5F54C219B29CF00E3E1AF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5051
31E39209219F765E00F7A3BE /* BrickHack-Mobile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "BrickHack-Mobile.entitlements"; sourceTree = "<group>"; };
5152
C029FC28202ED2177D811FF7 /* Pods-BrickHack-Mobile.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BrickHack-Mobile.debug.xcconfig"; path = "Pods/Target Support Files/Pods-BrickHack-Mobile/Pods-BrickHack-Mobile.debug.xcconfig"; sourceTree = "<group>"; };
53+
D750E81723DF67360075C639 /* FavoriteButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FavoriteButton.swift; path = "BrickHack-Mobile/Views/FavoriteButton.swift"; sourceTree = SOURCE_ROOT; };
5254
D789978123D652ED0058060A /* ScheduleTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScheduleTableViewController.swift; sourceTree = "<group>"; };
5355
D789978423D6A4DC0058060A /* ProfileTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ProfileTableViewController.swift; path = "/Users/peterkos/Code/Github/brickhack-mobile-ios/BrickHack-Mobile/Controllers/ProfileTableViewController.swift"; sourceTree = "<absolute>"; };
5456
D79AA2B723425DFA009C469D /* APIRoutes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIRoutes.swift; sourceTree = "<group>"; };
@@ -143,6 +145,7 @@
143145
D79AA2BB234268D2009C469D /* Views */ = {
144146
isa = PBXGroup;
145147
children = (
148+
D750E81723DF67360075C639 /* FavoriteButton.swift */,
146149
D7D4B036234813A70001DFC5 /* AlertMessage.swift */,
147150
);
148151
path = Views;
@@ -285,6 +288,7 @@
285288
D789978223D652ED0058060A /* ScheduleTableViewController.swift in Sources */,
286289
D7C07885233EDBA300089193 /* LoginViewController.swift in Sources */,
287290
D7C41E2523637D650091C480 /* MainTabBarController.swift in Sources */,
291+
D750E81823DF67360075C639 /* FavoriteButton.swift in Sources */,
288292
D7D4B037234813A70001DFC5 /* AlertMessage.swift in Sources */,
289293
D7C41E27236383300091C480 /* ResourcesViewController.swift in Sources */,
290294
D789978523D6A4DC0058060A /* ProfileTableViewController.swift in Sources */,

BrickHack-Mobile/AlertMessage.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ class MessageHandler {
8888
showAlertMessage(withTitle: "Parsing Error",
8989
body: "Error parsing user info from server.",
9090
type: .error)
91+
}
9192

93+
static func showInvalidFavoriteButtonError() {
94+
print("ERROR: Attempted to favorite a non-favorite-button cell.")
95+
showAlertMessage(withTitle: "Unable to favorite",
96+
body: "Please try again later.",
97+
type: .error)
9298
}
9399
}

BrickHack-Mobile/Controllers/ScheduleTableViewController.swift

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// FavoriteButton.swift
3+
// BrickHack-Mobile
4+
//
5+
// Created by Peter Kos on 1/27/20.
6+
// Copyright © 2020 codeRIT. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class FavoriteButton: UIButton {
12+
13+
var section: Int?
14+
var row: Int?
15+
16+
/*
17+
// Only override draw() if you perform custom drawing.
18+
// An empty implementation adversely affects performance during animation.
19+
override func draw(_ rect: CGRect) {
20+
// Drawing code
21+
}
22+
*/
23+
24+
}

Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ target 'BrickHack-Mobile' do
1313
pod "PromiseKit", "~> 6.8"
1414
pod 'PromiseKit/Foundation', '~> 6.0'
1515
pod 'TimelineTableViewCell', :git=>'https://github.com/peterkos/TimelineTableViewCell.git'
16+
#pod 'TimelineTableViewCell', :path=>'~/Code/Github/TimelineTableViewCell'
1617
end

Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ EXTERNAL SOURCES:
5151

5252
CHECKOUT OPTIONS:
5353
TimelineTableViewCell:
54-
:commit: c9a70bd88384c26b8503c538226b85a1bdc460a4
54+
:commit: d93f32e0caf1042fc88b43b5b0efb235a8e519f2
5555
:git: https://github.com/peterkos/TimelineTableViewCell.git
5656

5757
SPEC CHECKSUMS:
@@ -65,6 +65,6 @@ SPEC CHECKSUMS:
6565
TimelineTableViewCell: b2721a3c1f17c4a4950ae442f45cd4e8669a2750
6666
VYNFCKit: 86a9b711fd1f34f6f7128a2a883cd58dbd781b9d
6767

68-
PODFILE CHECKSUM: 6bbfd6c71fb7f410c10754d0ad20f126f4537919
68+
PODFILE CHECKSUM: 793dc90c3abfbf0f21ab7a8fc1372ab02f704d2e
6969

7070
COCOAPODS: 1.8.1

0 commit comments

Comments
 (0)