Skip to content

Commit 488de1d

Browse files
authored
Detail Page (#275)
* Update gym hours in gym detail page (#271) * Update gym hours in gym detail page * Fix linebreaks * Implement Tabbed Controller (#272) * Implement tabbed controller * Move code to tabbedviewcontroller * Update styling * Add capacity to Gym Detail page (#273) * Add capacity view * Add linebreak * Complete primitive detail page (#274) * Complete primitive detail page * Address comments
1 parent 4cd1960 commit 488de1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1516
-1205
lines changed

Uplift.xcodeproj/project.pbxproj

Lines changed: 95 additions & 31 deletions
Large diffs are not rendered by default.

Uplift/AppDelegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2828
// Run ad hock unit test
2929
AdHockTest.runAllTests()
3030
#endif
31-
32-
FitnessCenterManager.shared.fetch()
31+
//
32+
GymManager.shared.fetch()
3333

3434
// TODO: - Add back onboarding
3535
// let defaults = UserDefaults.standard

Uplift/Controllers/ClassDetailViewController.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,19 @@ extension ClassDetailViewController: UICollectionViewDataSource, UICollectionVie
242242
// MARK: - Item Height Calculations
243243
extension ClassDetailViewController {
244244
func getTimeHeight() -> CGFloat {
245-
return Constraints.verticalPadding + Constraints.titleLabelHeight +
246-
ClassDetailTimeCell.Constants.timeLabelTopPadding + Constraints.titleLabelHeight +
245+
return GymDetailConstraints.verticalPadding + GymDetailConstraints.titleLabelHeight +
246+
ClassDetailTimeCell.Constants.timeLabelTopPadding + GymDetailConstraints.titleLabelHeight +
247247
ClassDetailTimeCell.Constants.addToCalendarButtonTopPadding +
248248
ClassDetailTimeCell.Constants.addToCalendarButtonHeight +
249249
ClassDetailTimeCell.Constants.addToCalendarLabelTopPadding +
250250
ClassDetailTimeCell.Constants.addToCalendarLabelHeight +
251-
Constraints.verticalPadding + Constraints.dividerViewHeight
251+
GymDetailConstraints.verticalPadding + GymDetailConstraints.dividerViewHeight
252252
}
253253

254254
func getFunctionHeight(width: CGFloat) -> CGFloat {
255-
let baseHeight = Constraints.verticalPadding + Constraints.titleLabelHeight +
255+
let baseHeight = GymDetailConstraints.verticalPadding + GymDetailConstraints.titleLabelHeight +
256256
ClassDetailFunctionCell.Constants.functionDescriptionLabelTopPadding +
257-
Constraints.verticalPadding + Constraints.dividerViewHeight
257+
GymDetailConstraints.verticalPadding + GymDetailConstraints.dividerViewHeight
258258

259259
let descriptionLabelWidth = width - CGFloat(ClassDetailFunctionCell.Constants.descriptionLabelHorizontalPadding * 2)
260260
let string = gymClassInstance.tags.map { $0.name }.joined(separator: " · ")
@@ -264,7 +264,7 @@ extension ClassDetailViewController {
264264
}
265265

266266
func getDescriptionHeight(width: CGFloat) -> CGFloat {
267-
let baseHeight = 2.0 * Constraints.verticalPadding + Constraints.dividerViewHeight
267+
let baseHeight = 2.0 * GymDetailConstraints.verticalPadding + GymDetailConstraints.dividerViewHeight
268268

269269
let descriptionTextViewWidth = width - CGFloat(ClassDetailDescriptionCell.Constants.descriptionTextViewHorizontalPadding * 2)
270270
let descriptionTextViewHeight = gymClassInstance.classDescription.height(withConstrainedWidth: descriptionTextViewWidth, font: UIFont._14MontserratLight!)
@@ -275,7 +275,7 @@ extension ClassDetailViewController {
275275
func getNextSessionsHeight(numberOfSessions: CGFloat) -> CGFloat {
276276
let nextSessionsCellHeight: CGFloat = 112
277277

278-
let baseHeight = Constraints.verticalPadding + Constraints.titleLabelHeight +
278+
let baseHeight = GymDetailConstraints.verticalPadding + GymDetailConstraints.titleLabelHeight +
279279
ClassDetailNextSessionsCell.Constants.collectionViewTopPadding +
280280
ClassDetailNextSessionsCell.Constants.collectionViewBottomPadding
281281

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
//
2+
// GymDetailViewController.swift
3+
// Uplift
4+
//
5+
// Created by Yana Sang on 5/22/19.
6+
// Copyright © 2019 Cornell AppDev. All rights reserved.
7+
//
8+
9+
import Crashlytics
10+
import UIKit
11+
12+
class GymDetailViewController: UIViewController {
13+
14+
// MARK: - Public view vars
15+
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: StretchyHeaderLayout())
16+
17+
// MARK: - Private data vars
18+
private var sections: [ItemType]!
19+
20+
// MARK: - Public data vars
21+
var gymDetail: Gym!
22+
23+
// MARK: - Private classes/enums
24+
25+
private enum ItemType {
26+
case hours
27+
case tabbedController
28+
}
29+
30+
// MARK: - Custom Initializer
31+
init(gym: Gym) {
32+
super.init(nibName: nil, bundle: nil)
33+
gymDetail = gym
34+
sections = [.tabbedController]
35+
}
36+
37+
required init?(coder aDecoder: NSCoder) {
38+
fatalError("init(coder:) has not been implemented")
39+
}
40+
41+
override func viewDidLoad() {
42+
super.viewDidLoad()
43+
updatesStatusBarAppearanceAutomatically = true
44+
view.backgroundColor = .white
45+
46+
// MARK: - Fabric
47+
// Answers.logCustomEvent(withName: "Checking Gym Details")
48+
49+
let edgeSwipe = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(back))
50+
edgeSwipe.edges = .left
51+
view.addGestureRecognizer(edgeSwipe)
52+
53+
setupViews()
54+
setupConstraints()
55+
}
56+
57+
override func viewWillAppear(_ animated: Bool) {
58+
navigationController?.isNavigationBarHidden = true
59+
}
60+
61+
// MARK: - Targets
62+
@objc func back() {
63+
navigationController?.popViewController(animated: true)
64+
}
65+
}
66+
67+
// MARK: - CollectionViewDataSource, CollectionViewDelegate, CollectionViewDelegateFlowLayout
68+
extension GymDetailViewController: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
69+
70+
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
71+
return self.sections.count
72+
}
73+
74+
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
75+
let itemType = sections[indexPath.item]
76+
77+
switch itemType {
78+
case .hours:
79+
// swiftlint:disable:next force_cast
80+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: GymDetailHoursCell.reuseId, for: indexPath) as! GymDetailHoursCell
81+
cell.configure(for: self, hours: gymDetail.hours, isDisclosed: gymDetail.hoursIsDisclosed)
82+
return cell
83+
84+
case .tabbedController:
85+
// swiftlint:disable:next force_cast
86+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: GymDetailTabbedControllerCell.reuseId, for: indexPath) as! GymDetailTabbedControllerCell
87+
cell.configure(fitnessCenters: gymDetail.fitnessCenters)
88+
cell.delegate = self
89+
return cell
90+
}
91+
}
92+
93+
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
94+
let height: CGFloat
95+
96+
switch sections[indexPath.item] {
97+
case .hours:
98+
height = GymDetailHoursCell.getHeight(isDisclosed: gymDetail.hoursIsDisclosed, numLines: gymDetail.hours.getNumHoursLines())
99+
case .tabbedController:
100+
height = GymDetailTabbedControllerCell.getHeight(fitnessCenters: gymDetail.fitnessCenters[gymDetail.currentDisplayedFitnessCenter], viewWidt: self.view.frame.width)
101+
}
102+
103+
return CGSize(width: collectionView.frame.width, height: height)
104+
}
105+
106+
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
107+
let headerView = collectionView.dequeueReusableSupplementaryView(
108+
ofKind: UICollectionView.elementKindSectionHeader,
109+
withReuseIdentifier: GymDetailHeaderView.reuseId,
110+
// swiftlint:disable:next force_cast
111+
for: indexPath) as! GymDetailHeaderView
112+
headerView.configure(for: self, for: gymDetail)
113+
return headerView
114+
}
115+
116+
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
117+
return CGSize(width: collectionView.frame.width, height: 300)
118+
}
119+
120+
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
121+
return 0
122+
}
123+
124+
}
125+
126+
// MARK: - Layout
127+
extension GymDetailViewController {
128+
129+
private func setupViews() {
130+
collectionView.backgroundColor = .white
131+
collectionView.showsVerticalScrollIndicator = false
132+
133+
collectionView.register(GymDetailHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: GymDetailHeaderView.reuseId)
134+
135+
collectionView.register(GymDetailHoursCell.self, forCellWithReuseIdentifier: GymDetailHoursCell.reuseId)
136+
collectionView.register(GymDetailTabbedControllerCell.self, forCellWithReuseIdentifier: GymDetailTabbedControllerCell.reuseId)
137+
138+
collectionView.delegate = self
139+
collectionView.dataSource = self
140+
view.addSubview(collectionView)
141+
}
142+
143+
private func setupConstraints() {
144+
collectionView.snp.makeConstraints { make in
145+
make.top.leading.trailing.equalToSuperview()
146+
make.bottom.equalTo(view.safeAreaLayoutGuide)
147+
}
148+
}
149+
150+
}
151+
152+
// MARK: - Extensions
153+
extension GymDetailViewController: GymDetailHoursCellDelegate {
154+
155+
func didDropHours(isDropped: Bool, completion: @escaping () -> Void) {
156+
gymDetail.hoursIsDisclosed.toggle()
157+
collectionView.performBatchUpdates({}, completion: nil)
158+
completion()
159+
}
160+
161+
}
162+
163+
extension GymDetailViewController: GymDetailTabbedControllerCellDelegate {
164+
165+
func didMoveTo(index: Int, completion: @escaping () -> Void) {
166+
gymDetail.currentDisplayedFitnessCenter = index
167+
collectionView.performBatchUpdates({}, completion: nil)
168+
completion()
169+
}
170+
171+
func didChangeSize(completion: @escaping () -> Void) {
172+
collectionView.performBatchUpdates({}, completion: nil)
173+
completion()
174+
}
175+
176+
}
177+
178+
extension GymDetailViewController: GymDetailHeaderViewDelegate {
179+
180+
func gymDetailHeaderViewBackButtonTapped() {
181+
back()
182+
}
183+
184+
}

Uplift/Controllers/GymDetailViewController+Extensions.swift

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)