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

Quick GSR Booking #560

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions PennMobile.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
123D017B2CB1CB53006A8916 /* quickBookingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123D017A2CB1CB53006A8916 /* quickBookingViewController.swift */; };
12A6DCED2CCC770600FDF591 /* GSRMappingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12A6DCEC2CCC770600FDF591 /* GSRMappingController.swift */; };
2108CF211F3F73FF00CEC3F4 /* ContactsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2108CF201F3F73FF00CEC3F4 /* ContactsTableViewController.swift */; };
2108CF231F3F762500CEC3F4 /* ContactCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2108CF221F3F762500CEC3F4 /* ContactCell.swift */; };
210AC14520684F9B0050D837 /* HomeCellProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 210AC14420684F9B0050D837 /* HomeCellProtocols.swift */; };
Expand Down Expand Up @@ -454,6 +456,8 @@

/* Begin PBXFileReference section */
059FD41D74734ECD9DE8209C /* Pods-PennMobile.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PennMobile.release.xcconfig"; path = "Target Support Files/Pods-PennMobile/Pods-PennMobile.release.xcconfig"; sourceTree = "<group>"; };
123D017A2CB1CB53006A8916 /* quickBookingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = quickBookingViewController.swift; sourceTree = "<group>"; };
12A6DCEC2CCC770600FDF591 /* GSRMappingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GSRMappingController.swift; sourceTree = "<group>"; };
2108CF201F3F73FF00CEC3F4 /* ContactsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactsTableViewController.swift; sourceTree = "<group>"; };
2108CF221F3F762500CEC3F4 /* ContactCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactCell.swift; sourceTree = "<group>"; };
210AC14420684F9B0050D837 /* HomeCellProtocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeCellProtocols.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1279,7 +1283,9 @@
EFAE454823F12185005C2286 /* GSRGroups */,
2189C0802027CDB800771C1F /* GSRBookable.swift */,
2138D55222597FCB00D67CA2 /* GSRLocationsController.swift */,
123D017A2CB1CB53006A8916 /* quickBookingViewController.swift */,
214E254822480818004CB9C4 /* GSRDeletable.swift */,
12A6DCEC2CCC770600FDF591 /* GSRMappingController.swift */,
2189C0822027CDB800771C1F /* GSRController.swift */,
21A6B6CF22162652003A357D /* GSRReservationsController.swift */,
2138D55422598AA800D67CA2 /* GSRTabController.swift */,
Expand Down Expand Up @@ -2591,6 +2597,7 @@
42D9237329E0C9AF00E9E18E /* FitnessViewController.swift in Sources */,
429EA1E02B8B96B200824455 /* SubletCandidatesView.swift in Sources */,
6C6FE1D327B9B8CB0093FD13 /* ProfilePageTableViewCell.swift in Sources */,
123D017B2CB1CB53006A8916 /* quickBookingViewController.swift in Sources */,
F206DDB328D78A85008F572F /* PreferencesView.swift in Sources */,
2189C0832027CDB800771C1F /* GSRBookable.swift in Sources */,
2189C09C2027CE4100771C1F /* GSRDateHandler.swift in Sources */,
Expand Down Expand Up @@ -2700,6 +2707,7 @@
21B653BB2245FFA3001A97C5 /* CampusExpressNetworkManager.swift in Sources */,
EFE2D6F3239B11050020F6BF /* CreateGroupCell.swift in Sources */,
2180D2302013F3B4008C94CF /* NotificationRequestable.swift in Sources */,
12A6DCED2CCC770600FDF591 /* GSRMappingController.swift in Sources */,
212B8359222A331D00F835D6 /* Post.swift in Sources */,
B67881D8211CBF2A000DA750 /* MenuTableView.swift in Sources */,
EFE2D700239B124D0020F6BF /* GSRGroupUser.swift in Sources */,
Expand Down
45 changes: 44 additions & 1 deletion PennMobile/GSR-Booking/Controllers/GSRLocationsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,45 @@ class GSRLocationsController: GenericViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.locations = GSRLocationModel.shared.getLocations()
setupButton()
setupTableView()
}

fileprivate func setupButton() {
let button = UIButton(type: .system)
button.setTitle("Quick Booking", for: .normal)
button.setTitleColor(.white, for: .normal)
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 18)

let gradientLayer = CAGradientLayer()
gradientLayer.colors = [UIColor.systemBlue.cgColor, UIColor.systemGreen.cgColor]
gradientLayer.frame = button.bounds
gradientLayer.cornerRadius = 10
button.layer.insertSublayer(gradientLayer, at: 0)

button.layer.cornerRadius = 10
button.layer.shadowColor = UIColor.black.cgColor
button.layer.shadowOpacity = 0.3
button.layer.shadowOffset = CGSize(width: 0, height: 2)
button.layer.shadowRadius = 4
button.addTarget(self, action: #selector(quickTapped), for: .touchUpInside)

view.addSubview(button)

button.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
button.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 16),
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
button.heightAnchor.constraint(equalToConstant: 44),
button.widthAnchor.constraint(equalToConstant: 200)
])
}

@objc private func quickTapped() {
let quickView = QuickBookingViewController()
navigationController?.pushViewController(quickView, animated: true)
}

override func setupNavBar() {
super.setupNavBar()
self.tabBarController?.title = "Study Room Booking"
Expand All @@ -44,7 +80,14 @@ extension GSRLocationsController {
tableView.delegate = self

view.addSubview(tableView)
_ = tableView.anchor(view.topAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: 0)

tableView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 72), // Adjust based on button height + margin
tableView.leftAnchor.constraint(equalTo: view.leftAnchor),
tableView.rightAnchor.constraint(equalTo: view.rightAnchor),
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])

tableView.register(GSRLocationCell.self, forCellReuseIdentifier: GSRLocationCell.identifier)
}
Expand Down
110 changes: 110 additions & 0 deletions PennMobile/GSR-Booking/Controllers/GSRMappingController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//
// GSRMappingController.swift
// PennMobile
//
// Created by Kaitlyn Kwan on 10/25/24.
// Copyright © 2024 PennLabs. All rights reserved.
//

import Foundation
import UIKit
import MapKit

class GSRMappingController: UIViewController {
var destinationCoordinate: CLLocationCoordinate2D? {
didSet {
if let coordinate = destinationCoordinate {
updateMapAnnotations()
drawRoute(to: coordinate)
}
}
}

private let mapView: MKMapView = {
let mapView = MKMapView()
mapView.translatesAutoresizingMaskIntoConstraints = false
mapView.showsUserLocation = true
return mapView
}()

override func viewDidLoad() {
super.viewDidLoad()
setupMapView()
updateMapAnnotations()
}

private func setupMapView() {
view.addSubview(mapView)
NSLayoutConstraint.activate([
mapView.topAnchor.constraint(equalTo: view.topAnchor),
mapView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
mapView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
mapView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])
}

private func updateMapAnnotations() {
guard let destinationCoordinate = destinationCoordinate else { return }

mapView.removeAnnotations(mapView.annotations)

if let userLocation = mapView.userLocation.location {
let currentAnnotation = MKPointAnnotation()
currentAnnotation.coordinate = userLocation.coordinate
currentAnnotation.title = "Current Location"
mapView.addAnnotation(currentAnnotation)
}

let destinationAnnotation = MKPointAnnotation()
destinationAnnotation.coordinate = destinationCoordinate
destinationAnnotation.title = "GSR Location"
mapView.addAnnotation(destinationAnnotation)

if let userLocation = mapView.userLocation.location {
let midpoint = CLLocationCoordinate2D(
latitude: (userLocation.coordinate.latitude + destinationCoordinate.latitude) / 2,
longitude: (userLocation.coordinate.longitude + destinationCoordinate.longitude) / 2
)
let coordinates = [userLocation.coordinate, destinationCoordinate]
let region = MKCoordinateRegion(center: midpoint, latitudinalMeters: 1000, longitudinalMeters: 1000)
mapView.setRegion(mapView.regionThatFits(region), animated: true)
}
}

private func drawRoute(to destinationCoordinate: CLLocationCoordinate2D) {
guard let userLocation = mapView.userLocation.location else { return }

let request = MKDirections.Request()
request.source = MKMapItem(placemark: MKPlacemark(coordinate: userLocation.coordinate))
request.destination = MKMapItem(placemark: MKPlacemark(coordinate: destinationCoordinate))
request.transportType = .automobile // Change as needed (automobile, walking, etc.)

let directions = MKDirections(request: request)
directions.calculate { [weak self] response, error in
guard let self = self, let response = response else {
if let error = error {
print("Error calculating directions: \(error.localizedDescription)")
}
return
}

self.mapView.removeOverlays(self.mapView.overlays)

for route in response.routes {
self.mapView.addOverlay(route.polyline, level: .aboveRoads)
}
}
}
}

extension GSRMappingController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if let polyline = overlay as? MKPolyline {
let renderer = MKPolylineRenderer(polyline: polyline)
renderer.strokeColor = .blue
renderer.lineWidth = 5
return renderer
}
return MKOverlayRenderer(overlay: overlay)
}
}
Loading