From e7888393d83905266af677f4599b11d1cce5fe5b Mon Sep 17 00:00:00 2001 From: Shawn Huang Date: Mon, 15 Feb 2021 23:18:37 -0800 Subject: [PATCH] Change location option to environment (#266) * switch to quiet and collab * finish changing env --- berkeley-mobile.xcodeproj/project.pbxproj | 8 +- .../Assets/Colors/Colors+StudyPact.swift | 8 + .../API/Schema/ClassPreference.swift | 4 +- .../CreatePreferenceViewController.swift | 2 +- .../ReviewPreferencesViewController.swift | 5 +- .../SelectEnvironmentView.swift | 147 ++++++++++++++++++ .../CreatePreference/SelectLocationView.swift | 98 ------------ .../StudyPactPreference.swift | 2 +- 8 files changed, 166 insertions(+), 108 deletions(-) create mode 100644 berkeley-mobile/StudyPact/CreatePreference/SelectEnvironmentView.swift delete mode 100644 berkeley-mobile/StudyPact/CreatePreference/SelectLocationView.swift diff --git a/berkeley-mobile.xcodeproj/project.pbxproj b/berkeley-mobile.xcodeproj/project.pbxproj index 24c0b1eb9..2d6d359c6 100644 --- a/berkeley-mobile.xcodeproj/project.pbxproj +++ b/berkeley-mobile.xcodeproj/project.pbxproj @@ -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 */ @@ -376,7 +376,7 @@ FD3D6FFE25C2BB7D00579EF5 /* SelectPeopleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectPeopleView.swift; sourceTree = ""; }; FD3D700125C2BC7D00579EF5 /* CreatePreferenceFrameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePreferenceFrameViewController.swift; sourceTree = ""; }; FD6FB45825C616370045A03A /* SelectClassView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectClassView.swift; sourceTree = ""; }; - FD6FB45B25C62EB90045A03A /* SelectLocationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectLocationView.swift; sourceTree = ""; }; + FD6FB45B25C62EB90045A03A /* SelectEnvironmentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectEnvironmentView.swift; sourceTree = ""; }; FD6FB45E25C6A4B80045A03A /* StudyPactPreference.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudyPactPreference.swift; sourceTree = ""; }; FDE7CD9825BCE6DB00F65A13 /* CreatePreferenceViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePreferenceViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -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 */, @@ -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 */, diff --git a/berkeley-mobile/Assets/Colors/Colors+StudyPact.swift b/berkeley-mobile/Assets/Colors/Colors+StudyPact.swift index 0f2e24912..e45092dcc 100644 --- a/berkeley-mobile/Assets/Colors/Colors+StudyPact.swift +++ b/berkeley-mobile/Assets/Colors/Colors+StudyPact.swift @@ -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 { diff --git a/berkeley-mobile/StudyPact/API/Schema/ClassPreference.swift b/berkeley-mobile/StudyPact/API/Schema/ClassPreference.swift index 1e1d66b2d..8a8843c30 100644 --- a/berkeley-mobile/StudyPact/API/Schema/ClassPreference.swift +++ b/berkeley-mobile/StudyPact/API/Schema/ClassPreference.swift @@ -23,7 +23,7 @@ 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 @@ -31,7 +31,7 @@ struct AddPreferenceParams: Encodable { 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" } } diff --git a/berkeley-mobile/StudyPact/CreatePreference/CreatePreferenceViewController.swift b/berkeley-mobile/StudyPact/CreatePreference/CreatePreferenceViewController.swift index 81830742b..134a65322 100644 --- a/berkeley-mobile/StudyPact/CreatePreference/CreatePreferenceViewController.swift +++ b/berkeley-mobile/StudyPact/CreatePreference/CreatePreferenceViewController.swift @@ -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 diff --git a/berkeley-mobile/StudyPact/CreatePreference/ReviewPreferencesViewController.swift b/berkeley-mobile/StudyPact/CreatePreference/ReviewPreferencesViewController.swift index 2017fdcdb..efba3009c 100644 --- a/berkeley-mobile/StudyPact/CreatePreference/ReviewPreferencesViewController.swift +++ b/berkeley-mobile/StudyPact/CreatePreference/ReviewPreferencesViewController.swift @@ -81,7 +81,7 @@ 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 @@ -89,6 +89,7 @@ class ReviewPreferencesViewController: UIViewController { } 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" } } diff --git a/berkeley-mobile/StudyPact/CreatePreference/SelectEnvironmentView.swift b/berkeley-mobile/StudyPact/CreatePreference/SelectEnvironmentView.swift new file mode 100644 index 000000000..7cef5ec1d --- /dev/null +++ b/berkeley-mobile/StudyPact/CreatePreference/SelectEnvironmentView.swift @@ -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 + } +} diff --git a/berkeley-mobile/StudyPact/CreatePreference/SelectLocationView.swift b/berkeley-mobile/StudyPact/CreatePreference/SelectLocationView.swift deleted file mode 100644 index 0d2d83486..000000000 --- a/berkeley-mobile/StudyPact/CreatePreference/SelectLocationView.swift +++ /dev/null @@ -1,98 +0,0 @@ -// -// SelectLocationView.swift -// berkeley-mobile -// -// Created by Eashan Mathur on 1/30/21. -// Copyright © 2021 ASUC OCTO. All rights reserved. -// - -import UIKit - -class SelectLocationView: 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.isVirtual = button == virtualButton - } else { - isNextEnabled = false - } - } - } - var isNextEnabled: Bool = false { - didSet { - guard let preferenceVC = self.preferenceVC else { return } - preferenceVC.setNextEnabled() - } - } - - var virtualButton: UIButton! - var inPersonButton: UIButton! - 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.regular(16) - button.titleLabel?.textColor = Color.ActionButton.color - button.backgroundColor = .white - - button.setTitleColor(Color.blackText, for: .normal) - button.addTarget(self, action: #selector(toggleButton(sender:)), for: .touchUpInside) - - return button - } - - @objc func toggleButton(sender: ActionButton) { - if !sender.isSelected { - sender.backgroundColor = Color.ActionButton.background - sender.setTitleColor(.white, for: .normal) - sender.isSelected.toggle() - if let buttonSelected = self.buttonSelected { - buttonSelected.backgroundColor = .white - buttonSelected.isSelected.toggle() - buttonSelected.setTitleColor(Color.blackText, for: .normal) - } - self.buttonSelected = sender - } - } - - init(preferenceVC: CreatePreferenceViewController) { - self.preferenceVC = preferenceVC - super.init(frame: .zero) - self.virtualButton = createButton(title: "Virtual") - self.inPersonButton = createButton(title: "In Person") - setUpView() - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - func setUpView() { - let stack = UIStackView() - stack.axis = .vertical - stack.spacing = 25 - stack.distribution = .equalSpacing - addSubview(stack) - stack.addArrangedSubview(virtualButton) - stack.addArrangedSubview(inPersonButton) - - stack.translatesAutoresizingMaskIntoConstraints = false - virtualButton.translatesAutoresizingMaskIntoConstraints = false - inPersonButton.translatesAutoresizingMaskIntoConstraints = false - - stack.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true - stack.widthAnchor.constraint(equalToConstant: 155).isActive = true - stack.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true - virtualButton.heightAnchor.constraint(equalToConstant: 30).isActive = true - inPersonButton.heightAnchor.constraint(equalToConstant: 30).isActive = true - } -} diff --git a/berkeley-mobile/StudyPact/CreatePreference/StudyPactPreference.swift b/berkeley-mobile/StudyPact/CreatePreference/StudyPactPreference.swift index 3910deb2e..53ec00ad0 100644 --- a/berkeley-mobile/StudyPact/CreatePreference/StudyPactPreference.swift +++ b/berkeley-mobile/StudyPact/CreatePreference/StudyPactPreference.swift @@ -11,5 +11,5 @@ import Foundation struct StudyPactPreference { var className: String? var numberOfPeople: Int? - var isVirtual: Bool? + var isQuiet: Bool? }