Skip to content

Commit

Permalink
Merge pull request #155 from timroesner/135-Add-pass-UI
Browse files Browse the repository at this point in the history
Add Clipper Pass UI
  • Loading branch information
timroesner authored Apr 18, 2019
2 parents f1b0add + 885162b commit 0b9f7a9
Show file tree
Hide file tree
Showing 33 changed files with 487 additions and 60 deletions.
62 changes: 51 additions & 11 deletions BayPass.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion BayPass/Assets.xcassets/BART.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
3 changes: 2 additions & 1 deletion BayPass/Assets.xcassets/Bike.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
5 changes: 3 additions & 2 deletions BayPass/Assets.xcassets/Bus.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
"images" : [
{
"idiom" : "universal",
"filename" : "iconBus.pdf"
"filename" : "bus.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
Binary file not shown.
3 changes: 2 additions & 1 deletion BayPass/Assets.xcassets/CalTrain.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"preserves-vector-representation" : true
}
}
3 changes: 2 additions & 1 deletion BayPass/Assets.xcassets/MapMarker.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
3 changes: 2 additions & 1 deletion BayPass/Assets.xcassets/Plane.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
3 changes: 2 additions & 1 deletion BayPass/Assets.xcassets/Scooter.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
3 changes: 2 additions & 1 deletion BayPass/Assets.xcassets/Tram.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
3 changes: 2 additions & 1 deletion BayPass/Assets.xcassets/Walking.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
66 changes: 66 additions & 0 deletions BayPass/Controller/Clipper/CPCollectionView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// CPCollectionView.swift
// BayPass
//
// Created by Zhe Li on 4/15/19.
// Copyright © 2019 Tim Roesner. All rights reserved.
//

import UIKit

extension ClipperPassViewController: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection _: Int) -> Int {
if collectionView == clipperPassCollectionView {
return agencies.count
} else {
return UserManager.shared.getValidPasses().count
}
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView == clipperPassCollectionView {
let cell = clipperPassCollectionView.dequeueReusableCell(withReuseIdentifier: clipperPassCollectionViewCellID, for: indexPath) as! ClipperPassCollectionViewCell
cell.setup(with: Pass(name: agencies[indexPath.row].stringValue,
duration: DateInterval(start: Date(timeIntervalSinceNow: -470_482.0), end: Date(timeIntervalSinceNow: 470_482.0)),
price: 0.0,
validOnAgency: agencies[indexPath.row]))
return cell
} else {
let cell = recentlyPurchasedClipperPassCollectionView.dequeueReusableCell(withReuseIdentifier: recentlyPurchasedClipperPassCollectionViewCellID, for: indexPath) as! ClipperPassCollectionViewCell
cell.setup(with: UserManager.shared.getValidPasses()[indexPath.row])
return cell
}
}

func collectionView(_ collectionView: UICollectionView, layout _: UICollectionViewLayout, insetForSectionAt _: Int) -> UIEdgeInsets {
if collectionView == clipperPassCollectionView {
return UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
} else {
return UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 15)
}
}

func collectionView(_: UICollectionView, layout _: UICollectionViewLayout, minimumInteritemSpacingForSectionAt _: Int) -> CGFloat {
return 10
}

func collectionView(_ collectionView: UICollectionView, layout _: UICollectionViewLayout, sizeForItemAt _: IndexPath) -> CGSize {
if collectionView == clipperPassCollectionView {
return CGSize(width: 160, height: 85)
} else {
return CGSize(width: 250, height: 140)
}
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if collectionView == clipperPassCollectionView {
let clipperPassCheckoutViewController = ClipperPassCheckoutViewController()
clipperPassCheckoutViewController.agency = agencies[indexPath.row]
navigationController?.pushViewController(clipperPassCheckoutViewController, animated: true)
} else if collectionView == recentlyPurchasedClipperPassCollectionView {
let clipperPassCheckoutViewController = ClipperPassCheckoutViewController()
clipperPassCheckoutViewController.agency = UserManager.shared.getValidPasses()[indexPath.row].validOnAgency
navigationController?.pushViewController(clipperPassCheckoutViewController, animated: true)
}
}
}
68 changes: 68 additions & 0 deletions BayPass/Controller/Clipper/ClipperPassCheckoutViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// ClipperPassCheckoutViewController.swift
// BayPass
//
// Created by Zhe Li on 4/15/19.
// Copyright © 2019 Tim Roesner. All rights reserved.
//

import UIKit

class ClipperPassCheckoutViewController: UIViewController {
var agency = Agency.zero
var dropDownOptions: [(title: String, values: [String])] = [
(title: "Ticket Type", values: ["Day Pass", "3 Day Pass", "Monthly Pass"]),
(title: "Payment Method", values: PaymentMethod.allCases.map { $0.rawValue }),
]
private var stackedViews = [UIView]()

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white

title = agency.stringValue
navigationController?.navigationBar.prefersLargeTitles = false
setUpTicketView(newTicketView: TicketView(agency: agency, icon: agency.getIcon(), cornerRadius: 12))
setupDropDowns()
}

func setUpTicketView(newTicketView: TicketView) {
view.addSubview(newTicketView)
newTicketView.snp.makeConstraints { (make) -> Void in
make.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(25).priority(.low)
make.left.right.equalToSuperview().inset(16)
make.height.equalTo(newTicketView.snp.width).multipliedBy(0.6)
}
newTicketView.layoutIfNeeded()
stackedViews.append(newTicketView)
}

func setupDropDowns() {
for option in dropDownOptions {
let dropDown = DropDownMenu(title: option.title, items: option.values)
view.addSubview(dropDown)
dropDown.snp.makeConstraints { (make) -> Void in
make.top.equalTo(stackedViews.last!.snp.bottom).offset(25)
make.left.right.equalToSuperview().inset(12)
}
stackedViews.append(dropDown)
}
setUpButton(color: agency.getColor())
}

func setUpButton(color: UIColor) {
let payButton = BayPassButton(title: "Pay $xx.xx", color: color)
payButton.addTarget(self, action: #selector(pay), for: .touchUpInside)
view.addSubview(payButton)
payButton.snp.makeConstraints { (make) -> Void in
make.top.greaterThanOrEqualTo(stackedViews.last!.snp.bottom).offset(25)
make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom).inset(20)
make.right.left.equalToSuperview().inset(16)
make.height.equalTo(50)
}
}

@objc func pay() {
print("pay")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import UIKit
class ClipperPassCollectionViewCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .white
}

override func prepareForReuse() {
let _ = contentView.subviews.map{$0.removeFromSuperview()}
}

func setup(with pass: Pass) {
Expand Down Expand Up @@ -38,7 +43,7 @@ class ClipperPassCollectionViewCell: UICollectionViewCell {
let iconView = UIImageView()
iconView.tintColor = .white
iconView.image = #imageLiteral(resourceName: "Add")
addSubview(iconView)
contentView.addSubview(iconView)
iconView.snp.makeConstraints { make in
make.right.bottom.equalToSuperview()
make.width.height.equalTo(50)
Expand Down
103 changes: 103 additions & 0 deletions BayPass/Controller/Clipper/ClipperPassViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// ClipperPassViewController.swift
// BayPass
//
// Created by Zhe Li on 4/15/19.
// Copyright © 2019 Tim Roesner. All rights reserved.
//

import SnapKit
import UIKit

class ClipperPassViewController: UIViewController {
let agenciesLbl = UILabel()
let recentlyPurchasedLbl = UILabel()

let clipperPassCollectionViewCellID = "clipperPassCollectionViewCellID"
let clipperPassCollectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let collection = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
collection.backgroundColor = UIColor.white
collection.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 20, right: 0)
collection.isScrollEnabled = true
collection.showsVerticalScrollIndicator = false
return collection
}()

let recentlyPurchasedClipperPassCollectionViewCellID = "recentlyPurchasedClipperPassCollectionViewCellID"
let recentlyPurchasedClipperPassCollectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let collection = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
layout.scrollDirection = .horizontal
collection.backgroundColor = UIColor.white
collection.isScrollEnabled = true
collection.showsHorizontalScrollIndicator = false
return collection
}()

let agencies = Agency.allCases.filter{$0.rawValue != "0"}

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
title = "Add Pass"
navigationController?.navigationBar.prefersLargeTitles = false

clipperPassCollectionView.delegate = self
clipperPassCollectionView.dataSource = self
clipperPassCollectionView.register(ClipperPassCollectionViewCell.self, forCellWithReuseIdentifier: clipperPassCollectionViewCellID)

recentlyPurchasedClipperPassCollectionView.delegate = self
recentlyPurchasedClipperPassCollectionView.dataSource = self
recentlyPurchasedClipperPassCollectionView.register(ClipperPassCollectionViewCell.self, forCellWithReuseIdentifier: recentlyPurchasedClipperPassCollectionViewCellID)

setupView()
}

func setupView() {
view.addSubview(agenciesLbl)
agenciesLbl.text = "Agencies"
agenciesLbl.textColor = UIColor.black
agenciesLbl.font = UIFont.systemFont(ofSize: 24, weight: .bold)

view.addSubview(clipperPassCollectionView)
clipperPassCollectionView.snp.makeConstraints { (make) -> Void in
make.leading.equalToSuperview().offset(10)
make.trailing.equalToSuperview().inset(10)
make.top.equalTo(agenciesLbl.snp.bottom).offset(10)
make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
}

if UserManager.shared.getValidPasses().count > 0 {
view.addSubview(recentlyPurchasedLbl)
recentlyPurchasedLbl.text = "Recently Purchased"
recentlyPurchasedLbl.textColor = UIColor.black
recentlyPurchasedLbl.font = UIFont.systemFont(ofSize: 26, weight: .bold)
recentlyPurchasedLbl.snp.makeConstraints { (make) -> Void in
make.leading.equalToSuperview().offset(20)
make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(20)
}

view.addSubview(recentlyPurchasedClipperPassCollectionView)
recentlyPurchasedClipperPassCollectionView.snp.makeConstraints { (make) -> Void in
make.leading.equalToSuperview().offset(0)
make.trailing.equalToSuperview().offset(0)
make.top.equalTo(recentlyPurchasedLbl.snp.bottom).offset(10)
make.height.equalTo(140)
}

agenciesLbl.snp.makeConstraints { (make) -> Void in
make.leading.equalToSuperview().offset(20)
make.top.equalTo(recentlyPurchasedClipperPassCollectionView.snp.bottom).offset(15)
}
} else {
agenciesLbl.snp.makeConstraints { (make) -> Void in
make.leading.equalToSuperview().offset(20)
make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(15)
}

}

}

}
1 change: 1 addition & 0 deletions BayPass/Controller/Clipper/ClipperViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ClipperViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setupRegularView()
collectionView?.reloadData()
navigationController?.navigationBar.prefersLargeTitles = true
}

Expand Down
2 changes: 1 addition & 1 deletion BayPass/Controller/Clipper/CollectionViewCVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension ClipperViewController: UICollectionViewDelegate, UICollectionViewDataS
func collectionView(_: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if indexPath.row == 0 {
// present add pass UI
navigationController?.pushViewController(ClipperAddCashViewController(), animated: true)
navigationController?.pushViewController(ClipperPassViewController(), animated: true)
} else {
// present pass details with selected pass
let pass = UserManager.shared.getValidPasses()[indexPath.row - 1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TicketCheckoutViewController: UIViewController {
}
stackedViews.append(dropDown)
}
setUpButton(color: UIColor(named: "dark\(agency.stringValue.replacingOccurrences(of: " ", with: ""))") ?? UIColor.black)
setUpButton(color: agency.getColor())
}

func setUpButton(color: UIColor) {
Expand Down
Loading

0 comments on commit 0b9f7a9

Please sign in to comment.