Skip to content

Commit

Permalink
Merge pull request #570 from pennlabs/jhawk0224/warning-fixes-and-cod…
Browse files Browse the repository at this point in the history
…e-cleanup

Warning fixes and code cleanup
  • Loading branch information
JHawk0224 authored Nov 17, 2024
2 parents f8273aa + 597ad9e commit 93e9f65
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 104 deletions.
2 changes: 1 addition & 1 deletion PennMobile/Auth/OAuth2NetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ extension OAuth2NetworkManager {
let json = try decoder.decode(TokenResponse.self, from: data)
let expiration = Date().add(seconds: json.expiresIn)
let accessToken = AccessToken(value: json.accessToken, expiration: expiration)
let refreshToken = json.refreshToken
// let refreshToken = json.refreshToken

if let refreshToken = json.refreshToken {
saveRefreshToken(token: refreshToken)
Expand Down
2 changes: 1 addition & 1 deletion PennMobile/Clubs/Ticket Scanner/ScannerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum CameraState {
case ready
}

extension CVImageBuffer: @unchecked Sendable {}
extension CVImageBuffer: @unchecked @retroactive Sendable {}

extension CHHapticEngine {
func makePlayer(hapticName: String) throws -> CHHapticPatternPlayer {
Expand Down
6 changes: 3 additions & 3 deletions PennMobile/Dining/SwiftUI/DiningAnalyticsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ struct DiningAnalyticsView: View {
@State var notLoggedInAlertShowing = false
@State var showSettingsSheet = false
@Environment(\.colorScheme) var colorScheme
@Environment(\.presentationMode) var presentationMode
@Environment(\.dismiss) var dismiss
func showCorrectAlert() -> Alert {
if !Account.isLoggedIn {
return Alert(title: Text("You must log in to access this feature."), message: Text("Please login on the \"More\" tab."), dismissButton: .default(Text("Ok"), action: { presentationMode.wrappedValue.dismiss() }))
return Alert(title: Text("You must log in to access this feature."), message: Text("Please login on the \"More\" tab."), dismissButton: .default(Text("Ok"), action: { dismiss() }))
} else {
return Alert(title: Text("\"Penn Mobile\" requires you to login to Campus Express to use this feature."),
message: Text("Would you like to continue to campus express?"),
primaryButton: .default(Text("Continue"), action: {showDiningLoginView = true}),
secondaryButton: .cancel({ presentationMode.wrappedValue.dismiss() }))
secondaryButton: .cancel({ dismiss() }))
}
}
var body: some View {
Expand Down
2 changes: 1 addition & 1 deletion PennMobile/Dining/SwiftUI/DiningLoginNavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct DiningLoginNavigationView: View {
@EnvironmentObject var diningAnalyticsViewModel: DiningAnalyticsViewModel

var body: some View {
NavigationView {
NavigationStack {
DiningLoginViewSwiftUI(onDismiss: { dismiss() })
.navigationBarTitle(Text("Login"), displayMode: .inline)
.navigationBarItems(trailing: Button(action: {
Expand Down
62 changes: 18 additions & 44 deletions PennMobile/Dining/SwiftUI/DiningSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,36 @@ import PennMobileShared
struct DiningSettingsView: View {
@ObservedObject var viewModel: DiningAnalyticsViewModel

@Environment(\.presentationMode) var presentationMode
@Environment(\.dismiss) var dismiss
@State private var totalData = false
private let options = ["All data",
"Smart calculation",
"Weighted average"]

var body: some View {
if #available(iOS 16.0, *) {
NavigationView {
Form {
Picker(selection: $viewModel.selectedOptionIndex, label: Text("Slope Calculation")) {
ForEach(0..<options.count, id: \.self) { index in
Text(options[index]).tag(index)
}
NavigationStack {
Form {
Picker(selection: $viewModel.selectedOptionIndex, label: Text("Slope Calculation")) {
ForEach(0..<options.count, id: \.self) { index in
Text(options[index]).tag(index)
}
.pickerStyle(MenuPickerStyle())

// Toggle("Include guest swipes", isOn: $totalData)
}
.navigationBarTitle("Dining Analytics Settings", displayMode: .inline)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
presentationMode.wrappedValue.dismiss()
}) {
Text("Done")
}
}
}
.navigationViewStyle(StackNavigationViewStyle())
.pickerStyle(MenuPickerStyle())

// Toggle("Include guest swipes", isOn: $totalData)
}
.presentationDetents([.medium])
} else {
NavigationView {
Form {
Picker(selection: $viewModel.selectedOptionIndex, label: Text("Slope Calculation")) {
ForEach(0..<options.count, id: \.self) { index in
Text(options[index]).tag(index)
}
}
.pickerStyle(MenuPickerStyle())

// Toggle("Include guest swipes", isOn: $totalData)
}
.navigationBarTitle("Dining Analytics Settings", displayMode: .inline)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
presentationMode.wrappedValue.dismiss()
}) {
Text("Done")
}
.navigationBarTitle("Dining Analytics Settings", displayMode: .inline)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
dismiss()
}) {
Text("Done")
}
}
.navigationViewStyle(StackNavigationViewStyle())
}
.navigationViewStyle(StackNavigationViewStyle())
}
.presentationDetents([.medium])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ struct DiningVenueDetailView: View {
private let venue: DiningVenue
private let sectionTitle = ["Menu", "Hours", "Location"]

@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
@EnvironmentObject var diningVM: DiningViewModelSwiftUI
@State private var pickerIndex = 0
@State private var contentOffset: CGPoint = .zero
Expand Down
23 changes: 2 additions & 21 deletions PennMobile/Dining/SwiftUI/Views/Venue/DiningVenueView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ struct CustomHeader: View {
@State var showMissingDiningTokenAlert = false
@State var showDiningLoginView = false
@State var buttonAngle: Angle = .zero
@Environment(\.presentationMode) var presentationMode
@Environment(\.dismiss) var dismiss
@Environment(\.accessibilityReduceMotion) var reduceMotion
@EnvironmentObject var diningAnalyticsViewModel: DiningAnalyticsViewModel
func showCorrectAlert () -> Alert {
Expand All @@ -191,7 +191,7 @@ struct CustomHeader: View {
return Alert(title: Text("\"Penn Mobile\" requires you to login to Campus Express to use this feature."),
message: Text("Would you like to continue to campus express?"),
primaryButton: .default(Text("Continue"), action: {showDiningLoginView = true}),
secondaryButton: .cancel({ presentationMode.wrappedValue.dismiss() }))
secondaryButton: .cancel({ dismiss() }))
}
}

Expand Down Expand Up @@ -260,27 +260,8 @@ struct CustomHeader: View {
.onChange(of: isRefreshing) { refreshing in
animateButton(refreshing: refreshing)
}

// Note: The Alert view is soon to be deprecated, but .alert(_:isPresented:presenting:actions:message:) is available in iOS15+
.alert(isPresented: $showMissingDiningTokenAlert) {
showCorrectAlert()
}

// iOS 15+ implementation
/* .alert(Account.isLoggedIn ? "\"Penn Mobile\" requires you to login to Campus Express to use this feature." : "You must log in to access this feature.", isPresented: $showMissingDiningTokenAlert
) {
if (!Account.isLoggedIn) {
Button("OK") {}
} else {
Button("Continue") { showDiningLoginView = true }
Button("Cancel") { presentationMode.wrappedValue.dismiss() }
}
} message: {
if (!Account.isLoggedIn) {
Text("Please login on the \"More\" tab.")
} else {
Text("Would you like to continue to Campus Express?")
}
} */
}
}
2 changes: 1 addition & 1 deletion PennMobile/Events/Views/PennEventCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct PennEventCellView: View {
var body: some View {
ZStack {
if let imageUrl = event.imageUrl {
KFImage(event.imageUrl)
KFImage(imageUrl)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(height: 190)
Expand Down
2 changes: 1 addition & 1 deletion PennMobile/General/UserDefaults + Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ extension UserDefaults {
// MARK: - Current Dining Balance Object
extension UserDefaults {
@available(*, deprecated)
func setdiningBalance(_ diningBalance: DiningBalance) {
func setDiningBalance(_ diningBalance: DiningBalance) {
let encoder = JSONEncoder()
if let encoded = try? encoder.encode(diningBalance) {
UserDefaults.standard.set(encoded, forKey: UserDefaultsKeys.diningBalance.rawValue)
Expand Down
2 changes: 1 addition & 1 deletion PennMobile/Login/PathAtPennNetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ extension PathAtPennNetworkManager {
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpBody = twoFactorRequestBody

let (postData, postResponse) = try await URLSession.shared.data(for: request)
let (_, _) = try await URLSession.shared.data(for: request)

return try await getTokenWithoutReauthenticating()
} catch {
Expand Down
42 changes: 18 additions & 24 deletions PennMobile/Setup + Navigation/RootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,29 @@ class RootViewController: UIViewController, NotificationRequestable, ShowsAlert
view.addSubview(current.view)
current.didMove(toParent: self)

if #available(iOS 15, *) {
Task {
if let (data, _) = try? await URLSession.shared.data(from: URL(string: "https://itunes.apple.com/lookup?bundleId=org.pennlabs.PennMobile")!),
let data = try? JSON(data: data),
let version = data["results"][0]["version"].string,
let minimumOsVersion = data["results"][0]["minimumOsVersion"].int {
let appVersion = UserDefaults.standard.getAppVersion()
if appVersion.versionCompare(version) == .orderedAscending {
showOption(withMsg: "New version of PennMobile available for iOS version greater than \(minimumOsVersion). The app may not be fully functional on older versions.", title: "Update available", onAccept: {
guard let url = URL(string: "itms-apps://apps.apple.com/us/app/penn-mobile/id944829399") else { return }
UIApplication.shared.open(url)
}, onCancel: {
self.applicationWillEnterForeground()
})
} else {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.applicationWillEnterForeground()
}
}
Task {
if let (data, _) = try? await URLSession.shared.data(from: URL(string: "https://itunes.apple.com/lookup?bundleId=org.pennlabs.PennMobile")!),
let data = try? JSON(data: data),
let version = data["results"][0]["version"].string,
let minimumOsVersion = data["results"][0]["minimumOsVersion"].int {
let appVersion = UserDefaults.standard.getAppVersion()
if appVersion.versionCompare(version) == .orderedAscending {
showOption(withMsg: "New version of PennMobile available for iOS version greater than \(minimumOsVersion). The app may not be fully functional on older versions.", title: "Update available", onAccept: {
guard let url = URL(string: "itms-apps://apps.apple.com/us/app/penn-mobile/id944829399") else { return }
UIApplication.shared.open(url)
}, onCancel: {
self.applicationWillEnterForeground()
})
} else {
// No network request, simply go to home
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.applicationWillEnterForeground()
}
}
}
} else {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.applicationWillEnterForeground()
} else {
// No network request, simply go to home
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.applicationWillEnterForeground()
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions PennMobile/Setup + Navigation/TabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ final class TabBarController: UITabBarController {
tabBar.standardAppearance = appearance

// Required to prevent tab bar's appearance from switching between light and dark mode
if #available(iOS 15.0, *) {
tabBar.scrollEdgeAppearance = appearance
}
tabBar.scrollEdgeAppearance = appearance
}

override func viewWillAppear(_ animated: Bool) {
Expand Down
2 changes: 1 addition & 1 deletion PennMobileShared/General/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ public extension View {
}
}

extension CLLocationCoordinate2D: Identifiable {
extension CLLocationCoordinate2D: @retroactive Identifiable {
public var id: String {
return "\(latitude)-\(longitude)"
}
Expand Down
2 changes: 1 addition & 1 deletion Widget/Fitness/FitnessProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct IntentFitnessProvider<Intent: ConfigureFitnessWidgetIntent>: IntentTimeli

func getSnapshot(for intent: Intent, in context: Context, completion: @escaping (FitnessEntry<Intent.Configuration>) -> Void) {
Task {
let roomID = intent.configuration.complex.rawValue
let _ = intent.configuration.complex.rawValue
completion(await snapshot(configuration: intent.configuration, roomID: 7)) //getSnapshot is only called when widget is in drawer, and not when in home screen. Therefore, when in the drawer, set roomID to 7, which corresponds to 1st floor Fitness, to show a 'preview' of what the widget looks like. Then when the widget is actually placed on the home screen, it shows the instructions, because roomID is now set from getTimeline, where it defaults to 0 (which is the ID to show the instructions)
}
}
Expand Down

0 comments on commit 93e9f65

Please sign in to comment.