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

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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 @@ -16,6 +16,8 @@
421824092CCEB1370028E510 /* PennEventCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 421824052CCEB1370028E510 /* PennEventCellView.swift */; };
4218240A2CCEB1370028E510 /* PennEventsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 421824062CCEB1370028E510 /* PennEventsView.swift */; };
4218240B2CCEB1370028E510 /* PennEventsViewerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 421824072CCEB1370028E510 /* PennEventsViewerView.swift */; };
423B40D42D42A2070035E12D /* GSRMappingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 423B40D32D42A2070035E12D /* GSRMappingController.swift */; };
423B40D82D42A2300035E12D /* quickBookingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 423B40D72D42A2300035E12D /* quickBookingViewController.swift */; };
42632C8F2CB9C77B0028CC31 /* ScannerDuplicate.ahap in Resources */ = {isa = PBXBuildFile; fileRef = 42632B0E2CB9C77B0028CC31 /* ScannerDuplicate.ahap */; };
42632C902CB9C77B0028CC31 /* ScannerError.ahap in Resources */ = {isa = PBXBuildFile; fileRef = 42632B0F2CB9C77B0028CC31 /* ScannerError.ahap */; };
42632C912CB9C77B0028CC31 /* ScannerInvalid.ahap in Resources */ = {isa = PBXBuildFile; fileRef = 42632B102CB9C77B0028CC31 /* ScannerInvalid.ahap */; };
Expand Down Expand Up @@ -443,6 +445,8 @@
421824052CCEB1370028E510 /* PennEventCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PennEventCellView.swift; sourceTree = "<group>"; };
421824062CCEB1370028E510 /* PennEventsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PennEventsView.swift; sourceTree = "<group>"; };
421824072CCEB1370028E510 /* PennEventsViewerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PennEventsViewerView.swift; sourceTree = "<group>"; };
423B40D32D42A2070035E12D /* GSRMappingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GSRMappingController.swift; sourceTree = "<group>"; };
423B40D72D42A2300035E12D /* quickBookingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = quickBookingViewController.swift; sourceTree = "<group>"; };
42632AF92CB9C77B0028CC31 /* OAuth2NetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OAuth2NetworkManager.swift; sourceTree = "<group>"; };
42632AFA2CB9C77B0028CC31 /* PennAuthRequestable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PennAuthRequestable.swift; sourceTree = "<group>"; };
42632AFB2CB9C77B0028CC31 /* PennLoginController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PennLoginController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1284,6 +1288,8 @@
42632B8F2CB9C77B0028CC31 /* GSRLocationsController.swift */,
42632B902CB9C77B0028CC31 /* GSRReservationsController.swift */,
42632B912CB9C77B0028CC31 /* GSRTabController.swift */,
423B40D32D42A2070035E12D /* GSRMappingController.swift */,
423B40D72D42A2300035E12D /* quickBookingViewController.swift */,
);
path = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -2432,6 +2438,7 @@
42632CF02CB9C77B0028CC31 /* FirebaseAnalyticsManager.swift in Sources */,
42632CF12CB9C77B0028CC31 /* ImageNetworkingManager.swift in Sources */,
42632CF22CB9C77B0028CC31 /* Networking.swift in Sources */,
423B40D42D42A2070035E12D /* GSRMappingController.swift in Sources */,
42632CF32CB9C77B0028CC31 /* UserDBManager.swift in Sources */,
42632CF42CB9C77B0028CC31 /* AlertModifier.swift in Sources */,
42632CF52CB9C77B0028CC31 /* BetaBadge.swift in Sources */,
Expand Down Expand Up @@ -2505,6 +2512,7 @@
42632D352CB9C77B0028CC31 /* HomeFeatureCellItem.swift in Sources */,
42632D362CB9C77B0028CC31 /* GSRGroupInviteCell.swift in Sources */,
42632D372CB9C77B0028CC31 /* HomeGroupInvitesCell.swift in Sources */,
423B40D82D42A2300035E12D /* quickBookingViewController.swift in Sources */,
42632D382CB9C77B0028CC31 /* HomeGroupInvitesCellItem.swift in Sources */,
42632D392CB9C77B0028CC31 /* BookingRowCell.swift in Sources */,
42632D3A2CB9C77B0028CC31 /* HomeGSRBookingButton.swift in Sources */,
Expand Down
11 changes: 9 additions & 2 deletions PennMobile/GSR-Booking/Controllers/GSRLocationsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GSRLocationsController: GenericViewController {
self.locations = GSRLocationModel.shared.getLocations()
setupTableView()
}

override func setupNavBar() {
super.setupNavBar()
self.tabBarController?.title = "Study Room Booking"
Expand All @@ -45,7 +45,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: 0),
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)
}
}
17 changes: 12 additions & 5 deletions PennMobile/GSR-Booking/Controllers/GSRTabController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ class GSRTabController: ButtonBarPagerTabStripViewController, LegacyToastPresent

override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let child1 = GSRLocationsController()
let child2 = GSRReservationsController()
let child2 = QuickBookingViewController()
let child3 = GSRReservationsController()

if UserDefaults.standard.gsrGroupsEnabled() {
let child3 = GSRGroupController()
// let child4 = GSRGroupController()
return [child1, child2, child3]
}

return [child1, child2]
return [child1, child2, child3]
}
}

Expand All @@ -96,8 +97,14 @@ extension GSRReservationsController: IndicatorInfoProvider {
}
}

extension GSRGroupController: IndicatorInfoProvider {
extension QuickBookingViewController: IndicatorInfoProvider {
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
return IndicatorInfo(title: "Groups")
return IndicatorInfo(title: "Quick Book")
}
}

//extension GSRGroupController: IndicatorInfoProvider {
// func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
// return IndicatorInfo(title: "Groups")
// }
//}
Loading