Skip to content

Commit

Permalink
Change location option to environment (#266)
Browse files Browse the repository at this point in the history
* switch to quiet and collab

* finish changing env
  • Loading branch information
huangshawn1 authored Feb 16, 2021
1 parent 710ce31 commit e788839
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 108 deletions.
8 changes: 4 additions & 4 deletions berkeley-mobile.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
FD3D6FFF25C2BB7D00579EF5 /* SelectPeopleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD3D6FFE25C2BB7D00579EF5 /* SelectPeopleView.swift */; };
FD3D700225C2BC7D00579EF5 /* CreatePreferenceFrameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD3D700125C2BC7D00579EF5 /* CreatePreferenceFrameViewController.swift */; };
FD6FB45925C616370045A03A /* SelectClassView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD6FB45825C616370045A03A /* SelectClassView.swift */; };
FD6FB45C25C62EB90045A03A /* SelectLocationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD6FB45B25C62EB90045A03A /* SelectLocationView.swift */; };
FD6FB45C25C62EB90045A03A /* SelectEnvironmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD6FB45B25C62EB90045A03A /* SelectEnvironmentView.swift */; };
FD6FB45F25C6A4B90045A03A /* StudyPactPreference.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD6FB45E25C6A4B80045A03A /* StudyPactPreference.swift */; };
FDE7CD9925BCE6DB00F65A13 /* CreatePreferenceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE7CD9825BCE6DB00F65A13 /* CreatePreferenceViewController.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -376,7 +376,7 @@
FD3D6FFE25C2BB7D00579EF5 /* SelectPeopleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectPeopleView.swift; sourceTree = "<group>"; };
FD3D700125C2BC7D00579EF5 /* CreatePreferenceFrameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePreferenceFrameViewController.swift; sourceTree = "<group>"; };
FD6FB45825C616370045A03A /* SelectClassView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectClassView.swift; sourceTree = "<group>"; };
FD6FB45B25C62EB90045A03A /* SelectLocationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectLocationView.swift; sourceTree = "<group>"; };
FD6FB45B25C62EB90045A03A /* SelectEnvironmentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectEnvironmentView.swift; sourceTree = "<group>"; };
FD6FB45E25C6A4B80045A03A /* StudyPactPreference.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudyPactPreference.swift; sourceTree = "<group>"; };
FDE7CD9825BCE6DB00F65A13 /* CreatePreferenceViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePreferenceViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -793,7 +793,7 @@
FDE7CD9825BCE6DB00F65A13 /* CreatePreferenceViewController.swift */,
FD3D6FFE25C2BB7D00579EF5 /* SelectPeopleView.swift */,
FD6FB45825C616370045A03A /* SelectClassView.swift */,
FD6FB45B25C62EB90045A03A /* SelectLocationView.swift */,
FD6FB45B25C62EB90045A03A /* SelectEnvironmentView.swift */,
29EF1F0225C79111000C0F97 /* ReviewPreferencesViewController.swift */,
FD3D700125C2BC7D00579EF5 /* CreatePreferenceFrameViewController.swift */,
FD6FB45E25C6A4B80045A03A /* StudyPactPreference.swift */,
Expand Down Expand Up @@ -1265,7 +1265,7 @@
01B2502F2516C45800CBA459 /* EventCalendarEntry.swift in Sources */,
2925D5FA2529405500BBA266 /* CampusEventCellView.swift in Sources */,
5516088624392E5100B1E55B /* DiningViewController.swift in Sources */,
FD6FB45C25C62EB90045A03A /* SelectLocationView.swift in Sources */,
FD6FB45C25C62EB90045A03A /* SelectEnvironmentView.swift in Sources */,
29F09C3525D76EDF003FB69F /* StudyPactNewFeatureViewController.swift in Sources */,
01CDBBC725CA3B13006B93BD /* NetworkManager.swift in Sources */,
018B982825328200004C3B26 /* Colors+ActionButton.swift in Sources */,
Expand Down
8 changes: 8 additions & 0 deletions berkeley-mobile/Assets/Colors/Colors+StudyPact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ extension Color {
static var enabledNextButton: UIColor {
return UIColor(red: 0.3191883862, green: 0.4302733541, blue: 0.7476411462, alpha: 1)
}

static var grayText: UIColor {
return UIColor(displayP3Red: 103/255, green: 103/255, blue: 103/255, alpha: 1.0)
}

static var selectedBlue: UIColor {
return UIColor(displayP3Red: 119/255, green: 154/255, blue: 252/255, alpha: 1.0)
}
}

struct StudyGroups {
Expand Down
4 changes: 2 additions & 2 deletions berkeley-mobile/StudyPact/API/Schema/ClassPreference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ struct AddPreferenceParams: Encodable {
init?(email: String, cryptohash: String, prefs: StudyPactPreference) {
guard let className = prefs.className,
let numberOfPeople = prefs.numberOfPeople,
let isVirtual = prefs.isVirtual else {
let isQuiet = prefs.isQuiet else {
return nil
}
self.email = email
self.cryptohash = cryptohash
self.className = className
// backend wants us to send the preferred total people (including self)
self.size = numberOfPeople + 1
self.env = isVirtual ? "virtual" : "in-person"
self.env = isQuiet ? "quiet" : "collaborative"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class CreatePreferenceViewController: UIPageViewController, UIPageViewController
let initialPage = 0
let page1 = CreatePreferenceFrameViewController(labelText: "How many people do you want to study with?", containedView: SelectPeopleView(preferenceVC: self))
let page2 = CreatePreferenceFrameViewController(labelText: "What class do you want to study for?", containedView: SelectClassView(preferenceVC: self))
let page3 = CreatePreferenceFrameViewController(labelText: "Where do you want to study?", containedView: SelectLocationView(preferenceVC: self))
let page3 = CreatePreferenceFrameViewController(labelText: "What kind of study environment are you looking for?", containedView: SelectEnvironmentView(preferenceVC: self))
let page4 = ReviewPreferencesViewController(preferenceVC: self)
currentDelegate = page1.containedView as? EnableNextDelegate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ class ReviewPreferencesViewController: UIViewController {
guard let preferenceVC = self.preferenceVC,
let preferenceClass = preferenceVC.preference.className,
let preferenceNumber = preferenceVC.preference.numberOfPeople,
let preferenceVirtual = preferenceVC.preference.isVirtual else {
let preferenceQuiet = preferenceVC.preference.isQuiet else {
preferenceLabel.text = "There was an error with your selection."
lookingLabel.isHidden = true
reviewLabel.isHidden = true
return
}
lookingLabel.isHidden = false
reviewLabel.isHidden = false
preferenceLabel.text = "\(preferenceClass) study group\nwith \(preferenceNumber) people\nmeeting \(preferenceVirtual ? "virtually" : "in person")"
let peopleOrPerson = preferenceNumber == 1 ? "person" : "people"
preferenceLabel.text = "\(preferenceClass) study group\nwith \(preferenceNumber) other \(peopleOrPerson)\nin a \(preferenceQuiet ? "quiet" : "collaborative") setting"
}
}
147 changes: 147 additions & 0 deletions berkeley-mobile/StudyPact/CreatePreference/SelectEnvironmentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
//
// SelectEnvironmentView.swift
// berkeley-mobile
//
// Created by Eashan Mathur on 1/30/21.
// Copyright © 2021 ASUC OCTO. All rights reserved.
//

import UIKit

class SelectEnvironmentView: UIView, EnableNextDelegate {
weak var preferenceVC: CreatePreferenceViewController?
private var buttonSelected: UIButton? {
didSet {
if let button = buttonSelected {
isNextEnabled = true
guard let preferenceVC = self.preferenceVC else { return }
preferenceVC.preference.isQuiet = button == quietButton
} else {
isNextEnabled = false
}
}
}
var isNextEnabled: Bool = false {
didSet {
guard let preferenceVC = self.preferenceVC else { return }
preferenceVC.setNextEnabled()
}
}

var quietButton: UIButton!
let quietLabel: UILabel = {
let label = UILabel()
label.font = Font.medium(13)
label.text = "study alone, but keep each other accountable"
label.textAlignment = .center
label.textColor = Color.StudyPact.CreatePreference.grayText
label.translatesAutoresizingMaskIntoConstraints = false
label.numberOfLines = 0
label.adjustsFontSizeToFitWidth = true
return label
}()
var collaborativeButton: UIButton!
let collaborativeLabel: UILabel = {
let label = UILabel()
label.font = Font.medium(13)
label.text = "work together to finish tasks"
label.textAlignment = .center
label.textColor = Color.StudyPact.CreatePreference.grayText
label.translatesAutoresizingMaskIntoConstraints = false
label.numberOfLines = 0
label.adjustsFontSizeToFitWidth = true
return label
}()
private func createButton(title: String) -> UIButton {
let button = UIButton()
button.layer.cornerRadius = 12
button.layer.shadowRadius = 5
button.layer.shadowOpacity = 0.25
button.layer.shadowOffset = .zero
button.layer.shadowColor = UIColor.black.cgColor
button.layer.shadowPath = UIBezierPath(rect: button.layer.bounds.insetBy(dx: 4, dy: 4)).cgPath

button.setTitle(title, for: .normal)
button.titleLabel?.font = Font.medium(16)
button.backgroundColor = .white

button.setTitleColor(Color.StudyPact.CreatePreference.grayText, for: .normal)
button.addTarget(self, action: #selector(toggleButton(sender:)), for: .touchUpInside)
button.translatesAutoresizingMaskIntoConstraints = false
button.heightAnchor.constraint(equalToConstant: 30).isActive = true
button.widthAnchor.constraint(equalToConstant: 125).isActive = true

return button
}

@objc func toggleButton(sender: ActionButton) {
if !sender.isSelected {
sender.backgroundColor = Color.StudyPact.CreatePreference.selectedBlue
sender.setTitleColor(.white, for: .normal)
sender.isSelected.toggle()
if let buttonSelected = self.buttonSelected {
buttonSelected.backgroundColor = .white
buttonSelected.isSelected.toggle()
buttonSelected.setTitleColor(Color.StudyPact.CreatePreference.grayText, for: .normal)
switch buttonSelected {
case quietButton:
quietLabel.textColor = Color.StudyPact.CreatePreference.grayText
case collaborativeButton:
collaborativeLabel.textColor = Color.StudyPact.CreatePreference.grayText
default:
break
}
}
self.buttonSelected = sender
switch sender {
case quietButton:
quietLabel.textColor = Color.StudyPact.CreatePreference.selectedBlue
case collaborativeButton:
collaborativeLabel.textColor = Color.StudyPact.CreatePreference.selectedBlue
default:
break
}
}
}

init(preferenceVC: CreatePreferenceViewController) {
self.preferenceVC = preferenceVC
super.init(frame: .zero)
self.quietButton = createButton(title: "Quiet")
self.collaborativeButton = createButton(title: "Collaborative")
setUpView()
}

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

func setUpView() {
let stack = UIStackView()
stack.axis = .horizontal
stack.spacing = 15
stack.distribution = .equalSpacing
addSubview(stack)

stack.addArrangedSubview(buttonLabelVerticalPair(button: quietButton, label: quietLabel))
stack.addArrangedSubview(buttonLabelVerticalPair(button: collaborativeButton, label: collaborativeLabel))
stack.translatesAutoresizingMaskIntoConstraints = false
stack.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
stack.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
}

private func buttonLabelVerticalPair(button: UIButton, label: UILabel) -> UIView {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(button)
view.addSubview(label)
button.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
button.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
button.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
label.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 10).isActive = true
label.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -10).isActive = true
label.topAnchor.constraint(equalTo: button.bottomAnchor, constant: 15).isActive = true
label.bottomAnchor.constraint(lessThanOrEqualTo: view.bottomAnchor).isActive = true
return view
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import Foundation
struct StudyPactPreference {
var className: String?
var numberOfPeople: Int?
var isVirtual: Bool?
var isQuiet: Bool?
}

0 comments on commit e788839

Please sign in to comment.