Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/pennlabs/penn-mobile-ios in…
Browse files Browse the repository at this point in the history
…to polls-vc
  • Loading branch information
JHawk0224 committed Oct 8, 2023
2 parents 454d1f2 + f8df9da commit f680c6b
Show file tree
Hide file tree
Showing 37 changed files with 1,043 additions and 751 deletions.
122 changes: 50 additions & 72 deletions PennMobile.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions PennMobile/Dining/SwiftUI/DiningViewModelSwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import SwiftUI
import PennMobileShared

@MainActor
class DiningViewModelSwiftUI: ObservableObject {
static let instance = DiningViewModelSwiftUI()

Expand Down
2 changes: 2 additions & 0 deletions PennMobile/GSR-Booking/Controllers/GSRTabController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class GSRTabController: ButtonBarPagerTabStripViewController {
self.buttonBarView = self.barView
self.containerView = containerView
self.title = "Study Room Booking"
self.tabBarController?.title = "GSR"
self.tabBarItem.title = "GSR"

_ = barView.anchor(self.view.safeAreaLayoutGuide.topAnchor, left: self.view.leftAnchor, bottom: nil, right: self.view.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: 50)
_ = separatorLine.anchor(barView.bottomAnchor, left: self.view.leftAnchor, bottom: nil, right: self.view.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: 1)
Expand Down
49 changes: 49 additions & 0 deletions PennMobile/General/Networking + Analytics/UserDBManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,52 @@ extension UserDBManager {
}
}
}

// MARK: - Fitness
extension UserDBManager {

func saveFitnessPreferences(for rooms: [FitnessRoom]) {
let ids = rooms.map { $0.id }
saveFitnessPreferences(for: ids)
}

func saveFitnessPreferences(for ids: [Int]) {
let url = "https://pennmobile.org/api/fitness/preferences/"
let params = ["rooms": ids]

OAuth2NetworkManager.instance.getAccessToken { (token) in
let url = URL(string: url)!
var request = token != nil ? URLRequest(url: url, accessToken: token!) : URLRequest(url: url)
request.httpMethod = "POST"

request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSON(params).rawData()

let deviceID = getDeviceID()
request.setValue(deviceID, forHTTPHeaderField: "X-Device-ID")

let task = URLSession.shared.dataTask(with: request)
task.resume()
}
}

func getFitnessPreferences(_ callback: @escaping (_ rooms: [Int]?) -> Void) {
let url = "https://pennmobile.org/api/fitness/preferences/"
OAuth2NetworkManager.instance.getAccessToken { (token) in
let url = URL(string: url)!
var request = token != nil ? URLRequest(url: url, accessToken: token!) : URLRequest(url: url)

let deviceID = getDeviceID()
request.setValue(deviceID, forHTTPHeaderField: "X-Device-ID")

let task = URLSession.shared.dataTask(with: request) { (data, _, _) in
if let data = data, let rooms = JSON(data)["rooms"].arrayObject {
callback(rooms.compactMap { $0 as? Int })
return
}
callback(nil)
}
task.resume()
}
}
}
13 changes: 13 additions & 0 deletions PennMobile/General/UserDefaults + Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extension UserDefaults {
case controllerSettings
case sessionCount
case laundryPreferences
case fitnessPreferences
case isOnboarded
case appVersion
case cookies
Expand Down Expand Up @@ -133,6 +134,18 @@ extension UserDefaults {
}
}

// MARK: Fitness Preferences
extension UserDefaults {
func setFitnessPreferences(to ids: [Int]) {
set(ids, forKey: UserDefaultsKeys.fitnessPreferences.rawValue)
synchronize()
}

func getFitnessPreferences() -> [Int]? {
return array(forKey: UserDefaultsKeys.fitnessPreferences.rawValue) as? [Int]
}
}

// MARK: Onboarding Status
extension UserDefaults {
func setIsOnboarded(value: Bool) {
Expand Down
36 changes: 0 additions & 36 deletions PennMobile/Home/Fitness/Cells/FitnessHeaderView.swift

This file was deleted.

204 changes: 0 additions & 204 deletions PennMobile/Home/Fitness/Cells/FitnessHourCell.swift

This file was deleted.

Loading

0 comments on commit f680c6b

Please sign in to comment.