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 change-dining-slope
  • Loading branch information
JHawk0224 committed Jan 21, 2024
2 parents abd65ee + 92233c0 commit 791c3f0
Show file tree
Hide file tree
Showing 33 changed files with 1,252 additions and 235 deletions.
119 changes: 96 additions & 23 deletions PennMobile.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion PennMobile/Auth/OAuth2NetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class OAuth2NetworkManager: NSObject {
private var clientID = InfoPlistEnvironment.labsOauthClientId

private var currentAccessToken: AccessToken?

static let authQueue = DispatchQueue(label: "org.pennlabs.PennMobile.authqueue")
}

Expand Down
18 changes: 9 additions & 9 deletions PennMobile/Courses/Models/CoursesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ private func getTimeInt(pathAtPennString: String) -> Int? {
extension Course {
/// Initializes a course from Path@Penn data.
init(_ data: PathAtPennNetworkManager.CourseData) {
var crn = data.crn
var code = data.code
var title = data.title
var section = data.section
let crn = data.crn
let code = data.code
let title = data.title
let section = data.section

let instructorHTML = try? SwiftSoup.parse(data.instructordetail_html)
let divs = try? instructorHTML?.select("div")
var instructors = (try? divs?.map { try $0.text(trimAndNormaliseWhitespace: true) }) ?? []
let instructors = (try? divs?.map { try $0.text(trimAndNormaliseWhitespace: true) }) ?? []

let meetingHTML = try? SwiftSoup.parse(data.meeting_html)
let a = try? meetingHTML?.select("a").first()
var location = try? a?.text(trimAndNormaliseWhitespace: true)
let location = try? a?.text(trimAndNormaliseWhitespace: true)

struct PathAtPennMeetingTime: Decodable {
var meet_day: String
var start_time: String
var end_time: String
}

var meetingTimes: [MeetingTime]?
var startDate: Date?
var endDate: Date?
Expand Down Expand Up @@ -87,8 +87,8 @@ extension Course {
endDate = nil
meetingTimes = nil
}
self.init(crn: crn, code: code, title: title, section: section, instructors: instructors, startDate: startDate, endDate: endDate, meetingTimes: meetingTimes)

self.init(crn: crn, code: code, title: title, section: section, instructors: instructors, location: location, startDate: startDate, endDate: endDate, meetingTimes: meetingTimes)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ extension String {
// Crashes when you pass invalid pattern
let regex = try! NSRegularExpression(pattern: pattern)
let matches = regex.matches(in: self, range: NSRange(0..<utf16.count))
let ranges = [startIndex..<startIndex] + matches.map{Range($0.range, in: self)!} + [endIndex..<endIndex]
let ranges = [startIndex..<startIndex] + matches.map {Range($0.range, in: self)!} + [endIndex..<endIndex]
return (0...matches.count).map {String(self[ranges[$0].upperBound..<ranges[$0+1].lowerBound])}
}
}
Expand Down
99 changes: 0 additions & 99 deletions PennMobile/Dining/SwiftUI/Views/Venue/DiningVenueRow.swift

This file was deleted.

8 changes: 8 additions & 0 deletions PennMobile/General/Networking + Analytics/UserDBManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import UIKit
import SwiftyJSON
import PennMobileShared
import WidgetKit

class UserDBManager: NSObject, Requestable, SHA256Hashable {
static let shared = UserDBManager()
Expand Down Expand Up @@ -129,6 +130,13 @@ extension UserDBManager {
request.httpBody = try? JSON(["venues": venueIds]).rawData()
request.addValue("application/json", forHTTPHeaderField: "Content-Type")

// Cache a user's favorite dining halls for use by dining hours widget.
let diningVenues = DiningAPI.instance.getVenues(with: venueIds)
Storage.store(diningVenues, to: .groupCaches, as: DiningAPI.favoritesCacheFileName)
WidgetKind.diningHoursWidgets.forEach {
WidgetCenter.shared.reloadTimelines(ofKind: $0)
}

let task = URLSession.shared.dataTask(with: request)
task.resume()
}
Expand Down
5 changes: 3 additions & 2 deletions PennMobile/Home/Controllers/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,14 @@ extension HomeViewController: DiningCellSettingsDelegate {
func saveSelection(for venueIds: [Int]) {
guard let diningItem = self.tableViewModel.getItems(for: [HomeItemTypes.instance.dining]).first as? HomeDiningCellItem else { return }
if venueIds.count == 0 {
diningItem.venues = DiningAPI.instance.getVenues(with: DiningVenue.defaultVenueIds)
diningItem.venues = DiningAPI.instance.getVenues(with: DiningAPI.defaultVenueIds)
UserDBManager.shared.saveDiningPreference(for: DiningAPI.defaultVenueIds)
} else {
diningItem.venues = DiningAPI.instance.getVenues(with: venueIds)
UserDBManager.shared.saveDiningPreference(for: venueIds)
}

reloadItem(diningItem)
UserDBManager.shared.saveDiningPreference(for: venueIds)
}
}

Expand Down
53 changes: 0 additions & 53 deletions PennMobile/Home/Fitness/FitnessModel.swift

This file was deleted.

2 changes: 1 addition & 1 deletion PennMobile/Home/Fitness/FitnessRoomRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct FitnessRoomRow: View {
.foregroundColor(Color.labelSecondary)
.lineLimit(1)
}
FitnessGraph(room: room)
FitnessGraph(room: room, color: .blue)
}
.padding()
}
Expand Down
1 change: 1 addition & 0 deletions PennMobile/Home/Fitness/FitnessSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import SwiftUI
import Kingfisher
import PennMobileShared

struct FitnessSelectView: View {
@Binding var showFitnessSettings: Bool
Expand Down
1 change: 1 addition & 0 deletions PennMobile/Home/Fitness/FitnessView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import SwiftUI
import PennMobileShared

struct FitnessView: View {
@State var rooms: [FitnessRoom] = []
Expand Down
10 changes: 5 additions & 5 deletions PennMobile/Laundry/Cells/LaundryCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ extension LaundryCell {
// WashersDryersView
_ = washersDryersView.anchor(dividerLine.bottomAnchor, left: bgView.leftAnchor,
bottom: nil, right: bgView.rightAnchor,
topConstant: 16, leftConstant: 0, bottomConstant: 10, rightConstant: 0,
topConstant: 0, leftConstant: 0, bottomConstant: 10, rightConstant: 0,
widthConstant: 0, heightConstant: 200.0)

dividerLine.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor).isActive = true
Expand All @@ -326,9 +326,9 @@ extension LaundryCell {
widthConstant: 0, heightConstant: 0)

// Dryer View
_ = dryerView.anchor(nil, left: washersDryersView.leftAnchor,
bottom: washersDryersView.bottomAnchor, right: washersDryersView.rightAnchor,
topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0,
_ = dryerView.anchor(washerView.bottomAnchor, left: washersDryersView.leftAnchor,
bottom: nil, right: washersDryersView.rightAnchor,
topConstant: 8, leftConstant: 0, bottomConstant: 0, rightConstant: 0,
widthConstant: 0, heightConstant: 0)
dryerView.heightAnchor.constraint(
equalTo: washersDryersView.heightAnchor,
Expand All @@ -343,7 +343,7 @@ extension LaundryCell {
// Scrollable Graph View
_ = graphViewContainer.anchor(washersDryersView.bottomAnchor, left: bgView.leftAnchor,
bottom: bgView.bottomAnchor, right: bgView.rightAnchor,
topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0,
topConstant: 14, leftConstant: 0, bottomConstant: 0, rightConstant: 0,
widthConstant: 0, heightConstant: 0)
_ = scrollableGraphView!.anchor(graphViewContainer.topAnchor, left: graphViewContainer.leftAnchor,
bottom: graphViewContainer.bottomAnchor, right: graphViewContainer.rightAnchor,
Expand Down
18 changes: 18 additions & 0 deletions PennMobile/Laundry/Cells/LaundryMachineCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ class LaundryMachineCell: UICollectionViewCell {
iv.isHidden = true
return iv
}()

private let idLabel: UILabel = {
let label = UILabel()
label.text = ""
label.font = .secondaryInformationFont
label.textColor = .labelTertiary
label.layer.cornerRadius = 4
label.layer.masksToBounds = true
label.textAlignment = .center
return label
}()

private let timerLabel: UILabel = {
let label = UILabel()
Expand Down Expand Up @@ -67,6 +78,12 @@ class LaundryMachineCell: UICollectionViewCell {
self.addSubview(bellView)
bellView.centerYAnchor.constraint(equalTo: topAnchor).isActive = true
_ = bellView.anchor(nil, left: nil, bottom: nil, right: rightAnchor, topConstant: -8, leftConstant: 0, bottomConstant: 0, rightConstant: -8, widthConstant: 20, heightConstant: 20)

self.addSubview(idLabel)
_ = idLabel.anchor(bottomAnchor, left: leftAnchor,
bottom: bottomAnchor, right: rightAnchor,
topConstant: 0, leftConstant: 0, bottomConstant: -20, rightConstant: 0,
widthConstant: 0, heightConstant: 20)
}

func updateCell(with machine: LaundryMachine) {
Expand All @@ -89,6 +106,7 @@ class LaundryMachineCell: UICollectionViewCell {
} else {
timerLabel.text = ""
}
idLabel.text = "#\(machine.id)"

bellView.isHidden = !machine.isUnderNotification()
}
Expand Down
2 changes: 1 addition & 1 deletion PennMobile/More Tab/MoreViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class MoreViewController: GenericTableViewController, ShowsAlert {
PennLink(title: "Canvas", url: "https://canvas.upenn.edu"),
PennLink(title: "Path@Penn", url: "https://path.at.upenn.edu"),
PennLink(title: "PennPortal", url: "https://portal.apps.upenn.edu/penn_portal"),
PennLink(title: "Share Your Feedback", url: "https://airtable.com/shrS98E3rj5Nw1wy6")]
PennLink(title: "Share Your Feedback", url: "https://pennlabs.org/feedback/ios")]

}

Expand Down
11 changes: 11 additions & 0 deletions PennMobile/Setup + Navigation/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,24 @@ func migrateDataToGroupContainer() {
}
}

if Storage.migrate(fileName: DiningVenue.directory, of: [DiningVenue].self, from: .caches, to: .groupCaches) {
print("Migrated course data.")
}

if Storage.migrate(fileName: DiningAnalyticsViewModel.dollarHistoryDirectory, of: [DiningAnalyticsBalance].self, from: .documents, to: .groupDocuments) || Storage.migrate(fileName: DiningAnalyticsViewModel.swipeHistoryDirectory, of: [DiningAnalyticsBalance].self, from: .documents, to: .groupDocuments) {
print("Migrated dining analytics data.")
WidgetKind.diningAnalyticsWidgets.forEach {
WidgetCenter.shared.reloadTimelines(ofKind: $0)
}
}

if Storage.migrate(fileName: DiningAPI.favoritesCacheFileName, of: [DiningVenue].self, from: .caches, to: .groupCaches) {
print("Migrated dining favorites data.")
WidgetKind.diningHoursWidgets.forEach {
WidgetCenter.shared.reloadTimelines(ofKind: $0)
}
}

// Migrate dining balances if a dining balance file doesn't already exist.
if let diningBalance = (UserDefaults.standard as SwiftCompilerSilencing).getDiningBalance() {
if !Storage.fileExists(DiningBalance.directory, in: .groupCaches) {
Expand Down
1 change: 1 addition & 0 deletions PennMobile/Supporting_Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<array>
<string>ConfigureCoursesDayWidgetIntent</string>
<string>ConfigureDiningAnalyticsHomeWidgetIntent</string>
<string>ConfigureFitnessWidgetIntent</string>
</array>
<key>NSSupportsLiveActivities</key>
<true/>
Expand Down
Loading

0 comments on commit 791c3f0

Please sign in to comment.