Skip to content

Commit

Permalink
Merge pull request #492 from pennlabs/anli/09-17-refactor
Browse files Browse the repository at this point in the history
Refactor the core of the app using SwiftUI
  • Loading branch information
anli5005 committed Jan 21, 2024
2 parents d19c818 + 9ed39ca commit b321d5a
Show file tree
Hide file tree
Showing 68 changed files with 2,058 additions and 585 deletions.
78 changes: 64 additions & 14 deletions PennMobile.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions PennMobile/About/Privacy/PrivacyPreference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ enum PrivacyOption: String, CaseIterable {

var cellTitle: String {
switch self {
case .anonymizedCourseSchedule: return "Anonymized course schedule"
case .diningBalanceAndHistory: return "Dining balance & transaction history"
case .collegeHouse: return "College house"
case .academicIdentity: return "Academic identity"
case .anonymizedCourseSchedule: return "Anonymized Course Schedule"
case .diningBalanceAndHistory: return "Dining Balance & Transaction History"
case .collegeHouse: return "College House"
case .academicIdentity: return "Academic Identity"
}
}

Expand Down
6 changes: 3 additions & 3 deletions PennMobile/Assets.xcassets/Color/UI Palette/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "204",
"green" : "138",
"red" : "11"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "221",
"green" : "142",
"red" : "26"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "206",
"green" : "120",
"red" : "31"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Dining - Gray.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Dining - Gray@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Dining - Gray@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Fitness_Grey.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Fitness_Grey@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Fitness_Grey@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "GSR - Gray.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "GSR - Gray@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "GSR - Gray@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Home - Gray.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Home - Gray@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Home - Gray@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Laundry - Gray.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Laundry - Gray@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Laundry - Gray@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "More - Gray.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "More - Gray@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "More - Gray@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
19 changes: 16 additions & 3 deletions PennMobile/Auth/OAuth2NetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class OAuth2NetworkManager: NSObject {
private var clientID = InfoPlistEnvironment.labsOauthClientId

private var currentAccessToken: AccessToken?
var isRefreshingToken = false
var accessTokenCallbacks = [(AccessToken?) -> Void]()

static let authQueue = DispatchQueue(label: "org.pennlabs.PennMobile.authqueue")
}
Expand Down Expand Up @@ -90,8 +92,11 @@ extension OAuth2NetworkManager {
if let accessToken = self.currentAccessToken, Date() < accessToken.expiration {
callback(accessToken)
} else {
self.currentAccessToken = nil
self.refreshAccessToken(callback)
self.accessTokenCallbacks.append(callback)
if !self.isRefreshingToken {
self.currentAccessToken = nil
self.refreshAccessToken()
}
}
}
}
Expand All @@ -110,7 +115,12 @@ extension OAuth2NetworkManager {
}
}

fileprivate func refreshAccessToken(_ callback: @escaping (_ accessToken: AccessToken?) -> Void ) {
fileprivate func refreshAccessToken() {
func callback(_ token: AccessToken?) {
accessTokenCallbacks.forEach { $0(token) }
accessTokenCallbacks.removeAll()
}

guard let refreshToken = self.getRefreshToken() else {
callback(nil)
return
Expand All @@ -127,9 +137,12 @@ extension OAuth2NetworkManager {

request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpBody = String.getPostString(params: params).data(using: String.Encoding.utf8)

isRefreshingToken = true

let task = URLSession.shared.dataTask(with: request) { (data, response, _) in
OAuth2NetworkManager.authQueue.async {
self.isRefreshingToken = false
if let httpResponse = response as? HTTPURLResponse, let data = data {
if httpResponse.statusCode == 200 {
let json = JSON(data)
Expand Down
2 changes: 1 addition & 1 deletion PennMobile/Dining/SwiftUI/DiningAnalyticsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct DiningAnalyticsView: View {
DiningLoginNavigationView()
.environmentObject(diningAnalyticsViewModel)
}
.navigationTitle("Analytics")
.navigationTitle(Text("Dining Analytics"))
.sheet(isPresented: $showSettingsSheet) {
DiningSettingsView(viewModel: diningAnalyticsViewModel) // Replace with your settings view
}
Expand Down
Loading

0 comments on commit b321d5a

Please sign in to comment.