Skip to content

Commit

Permalink
rewriting the home view
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Astorga authored and Austin Astorga committed Oct 3, 2018
1 parent 2b99c5a commit 4f12b1b
Show file tree
Hide file tree
Showing 21 changed files with 474 additions and 284 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
@@ -1,6 +1,7 @@
disabled_rules: # rule identifiers to exclude from running
- variable_name
- nesting
- line_length
- function_parameter_count
opt_in_rules: # some rules are only opt-in
- control_statement
Expand Down
8 changes: 6 additions & 2 deletions Fitness.xcodeproj/project.pbxproj
Expand Up @@ -63,6 +63,7 @@
C7EBD5AE2062E73C00D76A8B /* ClassListHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7EBD5AD2062E73C00D76A8B /* ClassListHeaderView.swift */; };
C7EBD5B02062F14D00D76A8B /* Montserrat-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = C7EBD5AF2062F14D00D76A8B /* Montserrat-Regular.ttf */; };
C7EBD5B32062FDEB00D76A8B /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7EBD5B22062FDEB00D76A8B /* SearchBar.swift */; };
D91565C92165686400BCA466 /* tagQueries.graphql in Resources */ = {isa = PBXBuildFile; fileRef = D91565C82165686400BCA466 /* tagQueries.graphql */; };
D94BD3082159DA9200C9214E /* classQueries.graphql in Resources */ = {isa = PBXBuildFile; fileRef = D94BD3072159DA9200C9214E /* classQueries.graphql */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -128,6 +129,7 @@
C7EBD5AD2062E73C00D76A8B /* ClassListHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClassListHeaderView.swift; sourceTree = "<group>"; };
C7EBD5AF2062F14D00D76A8B /* Montserrat-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Montserrat-Regular.ttf"; sourceTree = "<group>"; };
C7EBD5B22062FDEB00D76A8B /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = "<group>"; };
D91565C82165686400BCA466 /* tagQueries.graphql */ = {isa = PBXFileReference; lastKnownFileType = text; path = tagQueries.graphql; sourceTree = "<group>"; };
D94BD3072159DA9200C9214E /* classQueries.graphql */ = {isa = PBXFileReference; lastKnownFileType = text; path = classQueries.graphql; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -326,6 +328,7 @@
children = (
D94BD3072159DA9200C9214E /* classQueries.graphql */,
8D6B2A18215B23DC00807544 /* gymQueries.graphql */,
D91565C82165686400BCA466 /* tagQueries.graphql */,
);
path = graphql;
sourceTree = "<group>";
Expand All @@ -348,11 +351,11 @@
buildPhases = (
9BD15CB1CD033C4DBE57E681 /* [CP] Check Pods Manifest.lock */,
0C3AC6132155BF5100761495 /* Generate Apollo GraphQL API */,
1CEB3B0B21503E5100BB5B61 /* Run SwiftLint */,
C7DFABC7204206E000545B0B /* Sources */,
C7DFABC8204206E000545B0B /* Frameworks */,
C7DFABC9204206E000545B0B /* Resources */,
7B68B6796476F8A7F1E6B485 /* [CP] Embed Pods Frameworks */,
1CEB3B0B21503E5100BB5B61 /* Run SwiftLint */,
8D29EFD320431FCA005B1CC8 /* Run Fabric build */,
);
buildRules = (
Expand Down Expand Up @@ -404,6 +407,7 @@
buildActionMask = 2147483647;
files = (
D94BD3082159DA9200C9214E /* classQueries.graphql in Resources */,
D91565C92165686400BCA466 /* tagQueries.graphql in Resources */,
8D26DB0B2072C31500144BFC /* Lato-Black.ttf in Resources */,
8D5EA47B208ED6E700E98E6C /* Lato-Bold.ttf in Resources */,
C7EBD5B02062F14D00D76A8B /* Montserrat-Regular.ttf in Resources */,
Expand Down Expand Up @@ -449,7 +453,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
7B68B6796476F8A7F1E6B485 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
109 changes: 109 additions & 0 deletions Fitness/API.swift
Expand Up @@ -349,6 +349,115 @@ public final class AllClassNamesQuery: GraphQLQuery {
}
}

public final class GetTagsQuery: GraphQLQuery {
public let operationDefinition =
"query GetTags {\n classes {\n __typename\n details {\n __typename\n tags\n }\n }\n}"

public init() {
}

public struct Data: GraphQLSelectionSet {
public static let possibleTypes = ["Query"]

public static let selections: [GraphQLSelection] = [
GraphQLField("classes", type: .list(.object(Class.selections))),
]

public private(set) var resultMap: ResultMap

public init(unsafeResultMap: ResultMap) {
self.resultMap = unsafeResultMap
}

public init(classes: [Class?]? = nil) {
self.init(unsafeResultMap: ["__typename": "Query", "classes": classes.flatMap { (value: [Class?]) -> [ResultMap?] in value.map { (value: Class?) -> ResultMap? in value.flatMap { (value: Class) -> ResultMap in value.resultMap } } }])
}

public var classes: [Class?]? {
get {
return (resultMap["classes"] as? [ResultMap?]).flatMap { (value: [ResultMap?]) -> [Class?] in value.map { (value: ResultMap?) -> Class? in value.flatMap { (value: ResultMap) -> Class in Class(unsafeResultMap: value) } } }
}
set {
resultMap.updateValue(newValue.flatMap { (value: [Class?]) -> [ResultMap?] in value.map { (value: Class?) -> ResultMap? in value.flatMap { (value: Class) -> ResultMap in value.resultMap } } }, forKey: "classes")
}
}

public struct Class: GraphQLSelectionSet {
public static let possibleTypes = ["ClassType"]

public static let selections: [GraphQLSelection] = [
GraphQLField("__typename", type: .nonNull(.scalar(String.self))),
GraphQLField("details", type: .object(Detail.selections)),
]

public private(set) var resultMap: ResultMap

public init(unsafeResultMap: ResultMap) {
self.resultMap = unsafeResultMap
}

public init(details: Detail? = nil) {
self.init(unsafeResultMap: ["__typename": "ClassType", "details": details.flatMap { (value: Detail) -> ResultMap in value.resultMap }])
}

public var __typename: String {
get {
return resultMap["__typename"]! as! String
}
set {
resultMap.updateValue(newValue, forKey: "__typename")
}
}

public var details: Detail? {
get {
return (resultMap["details"] as? ResultMap).flatMap { Detail(unsafeResultMap: $0) }
}
set {
resultMap.updateValue(newValue?.resultMap, forKey: "details")
}
}

public struct Detail: GraphQLSelectionSet {
public static let possibleTypes = ["ClassDetailType"]

public static let selections: [GraphQLSelection] = [
GraphQLField("__typename", type: .nonNull(.scalar(String.self))),
GraphQLField("tags", type: .list(.scalar(String.self))),
]

public private(set) var resultMap: ResultMap

public init(unsafeResultMap: ResultMap) {
self.resultMap = unsafeResultMap
}

public init(tags: [String?]? = nil) {
self.init(unsafeResultMap: ["__typename": "ClassDetailType", "tags": tags])
}

public var __typename: String {
get {
return resultMap["__typename"]! as! String
}
set {
resultMap.updateValue(newValue, forKey: "__typename")
}
}

public var tags: [String?]? {
get {
return resultMap["tags"] as? [String?]
}
set {
resultMap.updateValue(newValue, forKey: "tags")
}
}
}
}
}
}

public final class AllGymsQuery: GraphQLQuery {
public let operationDefinition =
"query AllGyms {\n gyms {\n __typename\n name\n id\n description\n popular\n times {\n __typename\n day\n startTime\n endTime\n }\n }\n}"
Expand Down
2 changes: 1 addition & 1 deletion Fitness/AppDelegate.swift
Expand Up @@ -16,8 +16,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
static let networkManager = NetworkManager()


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = TabBarController()
Expand Down
30 changes: 15 additions & 15 deletions Fitness/Controllers/ClassDetailViewController.swift
Expand Up @@ -89,7 +89,7 @@ class ClassDetailViewController: UIViewController {
make.top.equalToSuperview()
make.bottom.equalTo(view.snp.bottom)
}

// HEADER
setupHeader()

Expand Down Expand Up @@ -191,55 +191,55 @@ class ClassDetailViewController: UIViewController {
}
}
}

func setupHeader() {
classImageView.contentMode = UIViewContentMode.scaleAspectFill
classImageView.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(classImageView)

imageFilterView = UIView()
imageFilterView.backgroundColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 0.6)
contentView.addSubview(imageFilterView)

semicircleView = UIImageView(image: #imageLiteral(resourceName: "semicircle"))
semicircleView.contentMode = UIViewContentMode.scaleAspectFit
semicircleView.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(semicircleView)

titleLabel = UILabel()
titleLabel.text = gymClassInstance.classDescription.name
titleLabel.font = ._48Bebas
titleLabel.textAlignment = .center
titleLabel.textColor = .white
titleLabel.sizeToFit()
contentView.addSubview(titleLabel)

locationLabel.font = ._14MontserratLight
locationLabel.textAlignment = .center
locationLabel.textColor = .white
locationLabel.sizeToFit()
contentView.addSubview(locationLabel)

instructorLabel = UILabel()
instructorLabel.text = gymClassInstance.instructor.name
instructorLabel.font = ._18Bebas
instructorLabel.textAlignment = .center
instructorLabel.textColor = .white
instructorLabel.sizeToFit()
contentView.addSubview(instructorLabel)

durationLabel.font = ._18Bebas
durationLabel.textAlignment = .center
durationLabel.textColor = .fitnessBlack
durationLabel.sizeToFit()
contentView.addSubview(durationLabel)

backButton = UIButton()
backButton.setImage(#imageLiteral(resourceName: "back-arrow"), for: .normal)
backButton.sizeToFit()
backButton.addTarget(self, action: #selector(self.back), for: .touchUpInside)
contentView.addSubview(backButton)

starButton = UIButton()
starButton.setImage(#imageLiteral(resourceName: "white-star"), for: .normal)
starButton.sizeToFit()
Expand Down Expand Up @@ -403,23 +403,23 @@ class ClassDetailViewController: UIViewController {
// TODO: Replace with favorite functionality
print("favorite")
}
@objc func addToCalendar(){

@objc func addToCalendar() {
let store = EKEventStore()
store.requestAccess(to: .event) {(granted, error) in
if !granted { return }

let event = EKEvent(eventStore: store)
event.title = self.gymClassInstance.classDescription.name
event.startDate = Date.getDateFromTime(time: self.gymClassInstance.startTime)
event.endDate = event.startDate.addingTimeInterval(TimeInterval(Date.getMinutesFromDuration(duration: self.gymClassInstance.duration)*60))
event.location = self.location
event.calendar = store.defaultCalendarForNewEvents

let alert = UIAlertController(title: "\(self.gymClassInstance.classDescription.name) added to calendar", message: "Get ready to get sweaty", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Dismiss calendar alert"), style: .default))
self.present(alert, animated: true, completion: nil)

do {
try store.save(event, span: .thisEvent, commit: true)
} catch {
Expand Down
29 changes: 15 additions & 14 deletions Fitness/Controllers/FilterViewController.swift
Expand Up @@ -120,7 +120,7 @@ class FilterViewController: UIViewController {
classTypeDropdownData = DropdownData(dropStatus: .up, titles: [], completed: false)

AppDelegate.networkManager.getClassNames { (classNames) in

self.classTypeDropdownData.titles.append(contentsOf: classNames)

self.classTypeDropdownData.completed = true
Expand Down Expand Up @@ -149,7 +149,7 @@ class FilterViewController: UIViewController {
instructorDropdownData = DropdownData(dropStatus: .up, titles: [], completed: false)

AppDelegate.networkManager.getInstructors { (instructors) in

self.instructorDropdownData.titles.append(contentsOf: instructors)

self.instructorDropdownData.completed = true
Expand All @@ -171,15 +171,15 @@ class FilterViewController: UIViewController {
titleView.text = "Refine Search"
titleView.font = ._14LatoBlack
self.navigationItem.titleView = titleView

let doneBarButton = UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(done))
doneBarButton.tintColor = .fitnessBlack
self.navigationItem.rightBarButtonItem = doneBarButton

let resetBarButton = UIBarButtonItem(title: "Reset", style: .plain, target: self, action: #selector(reset))
resetBarButton.tintColor = .fitnessBlack
self.navigationItem.leftBarButtonItem = resetBarButton

//SCROLL VIEW
scrollView = UIScrollView()
scrollView.showsVerticalScrollIndicator = false
Expand All @@ -190,48 +190,49 @@ class FilterViewController: UIViewController {
scrollView.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}

contentView = UIView()
scrollView.addSubview(contentView)
contentView.snp.makeConstraints {make in
make.left.right.equalTo(view)
make.top.equalToSuperview()
make.bottom.equalTo(view.snp.bottom)
}

//COLLECTION VIEW
collectionViewTitle = UILabel()
collectionViewTitle.font = ._12LatoBlack
collectionViewTitle.textColor = .fitnessDarkGrey
collectionViewTitle.text = "FITNESS CENTER"
contentView.addSubview(collectionViewTitle)

let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0 )
layout.minimumInteritemSpacing = 1
layout.minimumLineSpacing = 0

gymCollectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
gymCollectionView.allowsMultipleSelection = true
gymCollectionView.backgroundColor = .fitnessLightGrey
gymCollectionView.isScrollEnabled = true
gymCollectionView.showsHorizontalScrollIndicator = false
gymCollectionView.bounces = false

gymCollectionView.delegate = self
gymCollectionView.dataSource = self
gymCollectionView.register(GymFilterCell.self, forCellWithReuseIdentifier: GymFilterCell.identifier)
contentView.addSubview(gymCollectionView)

gyms = []

AppDelegate.networkManager.getGymNames { (gyms) in

self.gyms = gyms
self.gymCollectionView.reloadData()
}
}

// MARK: - CONSTRAINTS
func setupConstraints() {
//COLLECTION VIEW SECTION
Expand Down Expand Up @@ -625,7 +626,7 @@ extension FilterViewController: UITableViewDataSource {
} else if tableView == classTypeDropdown {
if indexPath.row < classTypeDropdownData.titles.count {
cell.titleLabel.text = classTypeDropdownData.titles[indexPath.row]

if selectedClasses.contains(classTypeDropdownData.titles[indexPath.row]) {
cell.checkBoxColoring.backgroundColor = .fitnessYellow
}
Expand Down

0 comments on commit 4f12b1b

Please sign in to comment.