Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add collection view for menu view #25

Merged
merged 3 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 32 additions & 6 deletions acai-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
03D2BBA4224305B200AC6F38 /* ActionTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D2BBA3224305B200AC6F38 /* ActionTabView.swift */; };
03D2BBA6224318D500AC6F38 /* BowlHeaderSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D2BBA5224318D500AC6F38 /* BowlHeaderSectionController.swift */; };
03D2BBA822431A3300AC6F38 /* EmptyItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D2BBA722431A3300AC6F38 /* EmptyItem.swift */; };
03D2BBAA22435D6600AC6F38 /* BowlHeaderCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D2BBA922435D6600AC6F38 /* BowlHeaderCollectionViewCell.swift */; };
03D2BBAC2244959700AC6F38 /* QuantitySectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D2BBAB2244959700AC6F38 /* QuantitySectionController.swift */; };
03D2BBAE2244A2BD00AC6F38 /* QuantitySelectionCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D2BBAD2244A2BD00AC6F38 /* QuantitySelectionCollectionViewCell.swift */; };
03D2BBB02244A83800AC6F38 /* QuantityItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D2BBAF2244A83800AC6F38 /* QuantityItem.swift */; };
20ACCC1D2244E9EF00AB782A /* MenuCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ACCC1C2244E9EF00AB782A /* MenuCollectionViewCell.swift */; };
20ACCC1F2244EA0700AB782A /* MenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ACCC1E2244EA0700AB782A /* MenuViewController.swift */; };
20ACCC212244EA0D00AB782A /* MenuListSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ACCC202244EA0C00AB782A /* MenuListSectionController.swift */; };
6D03FA3A2246D17500191558 /* UIColor+Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D03FA392246D17500191558 /* UIColor+Shared.swift */; };
6D03FA49224AC86A00191558 /* BowlHeaderCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D03FA48224AC86A00191558 /* BowlHeaderCollectionViewCell.swift */; };
6D03FA4B224AC87800191558 /* QuantitySelectionCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D03FA4A224AC87800191558 /* QuantitySelectionCollectionViewCell.swift */; };
6D10DE9E221CAD6800C46F75 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D10DE9D221CAD6800C46F75 /* AppDelegate.swift */; };
6D10DEA5221CAD6C00C46F75 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6D10DEA4221CAD6C00C46F75 /* Assets.xcassets */; };
6D10DEA8221CAD6C00C46F75 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6D10DEA6221CAD6C00C46F75 /* LaunchScreen.storyboard */; };
Expand Down Expand Up @@ -60,7 +63,13 @@
03D2BBAD2244A2BD00AC6F38 /* QuantitySelectionCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuantitySelectionCollectionViewCell.swift; sourceTree = "<group>"; };
03D2BBAF2244A83800AC6F38 /* QuantityItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuantityItem.swift; sourceTree = "<group>"; };
151798FE5404CF9E9CB7B4A7 /* Pods-appdev-demo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-appdev-demo.release.xcconfig"; path = "Target Support Files/Pods-appdev-demo/Pods-appdev-demo.release.xcconfig"; sourceTree = "<group>"; };
20ACCC1C2244E9EF00AB782A /* MenuCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuCollectionViewCell.swift; sourceTree = "<group>"; };
20ACCC1E2244EA0700AB782A /* MenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuViewController.swift; sourceTree = "<group>"; };
20ACCC202244EA0C00AB782A /* MenuListSectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuListSectionController.swift; sourceTree = "<group>"; };
6D03FA322246A62500191558 /* BowlHeaderSectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BowlHeaderSectionController.swift; sourceTree = "<group>"; };
6D03FA392246D17500191558 /* UIColor+Shared.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+Shared.swift"; sourceTree = "<group>"; };
6D03FA48224AC86A00191558 /* BowlHeaderCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BowlHeaderCollectionViewCell.swift; sourceTree = "<group>"; };
6D03FA4A224AC87800191558 /* QuantitySelectionCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuantitySelectionCollectionViewCell.swift; sourceTree = "<group>"; };
6D10DE9A221CAD6800C46F75 /* acai-ios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "acai-ios.app"; sourceTree = BUILT_PRODUCTS_DIR; };
6D10DE9D221CAD6800C46F75 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
6D10DEA4221CAD6C00C46F75 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -99,6 +108,8 @@
03D2BB5222317A4700AC6F38 /* SectionControllers */ = {
isa = PBXGroup;
children = (
20ACCC202244EA0C00AB782A /* MenuListSectionController.swift */,
6D03FA322246A62500191558 /* BowlHeaderSectionController.swift */,
03D2BB97223FFB9800AC6F38 /* HeaderListSectionController.swift */,
03D2BB88223BDA2000AC6F38 /* OrderCustomizationListSectionController.swift */,
03D2BBA5224318D500AC6F38 /* BowlHeaderSectionController.swift */,
Expand All @@ -110,11 +121,12 @@
03D2BB8722383F3200AC6F38 /* CollectionViewCells */ = {
isa = PBXGroup;
children = (
20ACCC1C2244E9EF00AB782A /* MenuCollectionViewCell.swift */,
6D03FA48224AC86A00191558 /* BowlHeaderCollectionViewCell.swift */,
03D2BB90223EA4EF00AC6F38 /* OptionHeaderCollectionViewCell.swift */,
03D2BB8E223EA4E100AC6F38 /* RadioSelectionCollectionViewCell.swift */,
6D03FA4A224AC87800191558 /* QuantitySelectionCollectionViewCell.swift */,
03D2BB92223EA50500AC6F38 /* MultiSelectionCollectionViewCell.swift */,
03D2BBA922435D6600AC6F38 /* BowlHeaderCollectionViewCell.swift */,
03D2BBAD2244A2BD00AC6F38 /* QuantitySelectionCollectionViewCell.swift */,
);
path = CollectionViewCells;
sourceTree = "<group>";
Expand All @@ -132,13 +144,23 @@
path = Models;
sourceTree = "<group>";
};
6D03FA47224AC84900191558 /* Recovered References */ = {
isa = PBXGroup;
children = (
03D2BBAD2244A2BD00AC6F38 /* QuantitySelectionCollectionViewCell.swift */,
03D2BBA922435D6600AC6F38 /* BowlHeaderCollectionViewCell.swift */,
);
name = "Recovered References";
sourceTree = "<group>";
};
6D10DE91221CAD6800C46F75 = {
isa = PBXGroup;
children = (
6D10DE9C221CAD6800C46F75 /* acai-ios */,
6D10DE9B221CAD6800C46F75 /* Products */,
D373E9E75C1FEDD56C03ABA5 /* Pods */,
0212C3C9219670DD1562783A /* Frameworks */,
6D03FA47224AC84900191558 /* Recovered References */,
);
sourceTree = "<group>";
};
Expand All @@ -160,6 +182,7 @@
6D10DEC0221EE81700C46F75 /* Endpoints.swift */,
6D10DEBE221EDF0F00C46F75 /* keys.generated.swift */,
031536F5222E15CE004FAF9F /* LoginViewController.swift */,
20ACCC1E2244EA0700AB782A /* MenuViewController.swift */,
6D36736D2226F7FA000F9917 /* HomeViewController.swift */,
03D2BB95223EB42C00AC6F38 /* BowlOrderDetailViewController.swift */,
03D2BBA3224305B200AC6F38 /* ActionTabView.swift */,
Expand Down Expand Up @@ -371,7 +394,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
03D2BBAE2244A2BD00AC6F38 /* QuantitySelectionCollectionViewCell.swift in Sources */,
6D03FA4B224AC87800191558 /* QuantitySelectionCollectionViewCell.swift in Sources */,
03D2BB9E2242B1C300AC6F38 /* BowlItem.swift in Sources */,
03D2BB98223FFB9800AC6F38 /* HeaderListSectionController.swift in Sources */,
031536F6222E15CE004FAF9F /* LoginViewController.swift in Sources */,
Expand All @@ -384,17 +407,20 @@
031536F8222EB3BA004FAF9F /* Acai.swift in Sources */,
03D2BBB02244A83800AC6F38 /* QuantityItem.swift in Sources */,
03D2BBA02242B1F000AC6F38 /* OrderCustomizationOption.swift in Sources */,
20ACCC1D2244E9EF00AB782A /* MenuCollectionViewCell.swift in Sources */,
03D2BB8D223C396000AC6F38 /* MenuItem.swift in Sources */,
03D2BB9A2240B5EB00AC6F38 /* UIFont+Shared.swift in Sources */,
03D2BBAA22435D6600AC6F38 /* BowlHeaderCollectionViewCell.swift in Sources */,
20ACCC1F2244EA0700AB782A /* MenuViewController.swift in Sources */,
03D2BB96223EB42C00AC6F38 /* BowlOrderDetailViewController.swift in Sources */,
6D3673722226F7FB000F9917 /* HomeViewController.swift in Sources */,
6D03FA3A2246D17500191558 /* UIColor+Shared.swift in Sources */,
03D2BB89223BDA2000AC6F38 /* OrderCustomizationListSectionController.swift in Sources */,
6D03FA49224AC86A00191558 /* BowlHeaderCollectionViewCell.swift in Sources */,
6D10DEBF221EDF0F00C46F75 /* keys.generated.swift in Sources */,
6D10DEC1221EE81700C46F75 /* Endpoints.swift in Sources */,
03D2BB93223EA50500AC6F38 /* MultiSelectionCollectionViewCell.swift in Sources */,
6D10DE9E221CAD6800C46F75 /* AppDelegate.swift in Sources */,
20ACCC212244EA0D00AB782A /* MenuListSectionController.swift in Sources */,
03D2BB8F223EA4E100AC6F38 /* RadioSelectionCollectionViewCell.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
2 changes: 1 addition & 1 deletion acai-ios/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func setupWindow() {
window = UIWindow()
window?.rootViewController = UINavigationController(rootViewController: HomeViewController())
window?.rootViewController = UINavigationController(rootViewController: MenuViewController())
window?.makeKeyAndVisible()
}

Expand Down
82 changes: 82 additions & 0 deletions acai-ios/CollectionViewCells/MenuCollectionViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// MenuCollectionViewCell.swift
// acai-ios
//
// Created by Jaewon Sim on 3/17/19.
// Copyright © 2019 Cornell AppDev. All rights reserved.
//

import UIKit
import SnapKit

class MenuCollectionViewCell: UICollectionViewCell {

// MARK: View vars
var imageView: UIImageView!
var titleLabel: UILabel!
var ingredientsLabel: UILabel!
var detailStackView: UIStackView! // include title and ingredients
var bottomSeparator: UIView!

// MARK: Lifecycle
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .white

imageView = UIImageView()
contentView.addSubview(imageView)

titleLabel = UILabel()
titleLabel.font = UIFont.avenirNextBold.withSize(17)
titleLabel.numberOfLines = 1
titleLabel.textColor = .acaiBlack

ingredientsLabel = UILabel()
ingredientsLabel.font = UIFont.avenirNextMedium.withSize(12)
ingredientsLabel.numberOfLines = 2
ingredientsLabel.lineBreakMode = .byWordWrapping
ingredientsLabel.textColor = .acaiBlack

detailStackView = UIStackView(arrangedSubviews: [titleLabel, ingredientsLabel])
detailStackView.axis = .vertical
detailStackView.alignment = .fill
detailStackView.distribution = .equalSpacing
contentView.addSubview(detailStackView)

bottomSeparator = UIView()
bottomSeparator.backgroundColor = .lineGray
contentView.addSubview(bottomSeparator)

setUpConstraints()
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: Constraint setup
private func setUpConstraints() {
let leadingOffset: CGFloat = 24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to put constants at the top along with view vars

let trailingInset: CGFloat = 72
let imageViewWidthHeight: CGFloat = 64
let imageViewStackViewHorizontalSpacing: CGFloat = 24
let bottomSeparatorHeight: CGFloat = 1.0

imageView.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.leading.equalToSuperview().inset(leadingOffset)
make.width.height.equalTo(imageViewWidthHeight)
}

detailStackView.snp.makeConstraints { make in
make.leading.equalTo(imageView.snp.trailing).offset(imageViewStackViewHorizontalSpacing)
make.centerY.equalToSuperview()
make.trailing.equalToSuperview().inset(trailingInset)
}

bottomSeparator.snp.makeConstraints { make in
make.leading.trailing.bottom.equalToSuperview()
make.height.equalTo(bottomSeparatorHeight)
}
}
}
117 changes: 117 additions & 0 deletions acai-ios/MenuViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//
// MenuViewController.swift
// acai-ios
//
// Created by Jaewon Sim on 3/13/19.
// Copyright © 2019 Cornell AppDev. All rights reserved.
//

import UIKit
import IGListKit
import SnapKit

protocol MenuSelectionDelegate: class {
func didSelect(_ item: MenuItem)
}

class MenuViewController: UIViewController {

// MARK: Models
var menu: [String: [MenuItem]] = [:]

// MARK: IGListKit Vars
var collectionView: UICollectionView!
var listAdapter: ListAdapter!

// MARK: Lifecycle
override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .white

title = "Good Morning, Jamie ☀️"
navigationController?.navigationBar.prefersLargeTitles = true
navigationController?.navigationBar.largeTitleTextAttributes = [
.font: UIFont.avenirNextMedium.withSize(24)
]
navigationController?.navigationBar.titleTextAttributes = [
.font: UIFont.avenirNextMedium.withSize(16)
]

let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .vertical
collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.backgroundColor = .white
collectionView.showsVerticalScrollIndicator = false
collectionView.alwaysBounceVertical = true
view.addSubview(collectionView)

listAdapter = ListAdapter(updater: ListAdapterUpdater(), viewController: self)
listAdapter.collectionView = collectionView
listAdapter.dataSource = self

setUpConstraints()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

loadMenu()
}

private func loadMenu() {
// TODO: get menu from endpoint
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ TODOs should be resolved (get menu from endpoint).
todo MenuViewController.swift:63


menu = [
"Bowls": [
MenuItem(title: "Crunchy", price: 10.00, orderCustomizationOptions: [], image: UIImage(named: "acaiBowl")!),
MenuItem(title: "Miami", price: 10.00, orderCustomizationOptions: [], image: UIImage(named: "acaiBowl")!)
],

"Smoothies": [
],

"Coffee": [
]
]

listAdapter.performUpdates(animated: false, completion: nil)
}

// MARK: Constraint setup
private func setUpConstraints() {
collectionView.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview()
make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
}
}
}

// MARK: List adapter data source
extension MenuViewController: ListAdapterDataSource {
func objects(for listAdapter: ListAdapter) -> [ListDiffable] {

let currentList = menu["Bowls"] ?? []

return currentList
}

func listAdapter(_ listAdapter: ListAdapter, sectionControllerFor object: Any) -> ListSectionController {
let menuController = MenuListSectionController()
menuController.delegate = self
return menuController
}

func emptyView(for listAdapter: ListAdapter) -> UIView? {
return nil
}
}

extension MenuViewController: MenuSelectionDelegate {

func didSelect(_ item: MenuItem) {
print("Selected \(item.title)")
}

}
37 changes: 37 additions & 0 deletions acai-ios/SectionControllers/MenuListSectionController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// MenuListSectionController.swift
// acai-ios
//
// Created by Jaewon Sim on 3/18/19.
// Copyright © 2019 Cornell AppDev. All rights reserved.
//

import UIKit
import IGListKit

class MenuListSectionController: ListSectionController {

var currentMenuItem: MenuItem!

weak var delegate: MenuSelectionDelegate?

override func sizeForItem(at index: Int) -> CGSize {
return CGSize(width: collectionContext!.containerSize.width, height: 107)
}

override func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext!.dequeueReusableCell(of: MenuCollectionViewCell.self, for: self, at: index) as! MenuCollectionViewCell
cell.imageView.image = currentMenuItem.image
cell.titleLabel.text = currentMenuItem.title
cell.ingredientsLabel.text = ["Granola", "Banana", "Kiwi", "Coconut Flaxseed"].joined(separator: ", ")
return cell
}

override func didUpdate(to object: Any) {
currentMenuItem = object as? MenuItem
}

override func didSelectItem(at index: Int) {
delegate?.didSelect(currentMenuItem)
}
}