Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

[fix/swift-5.8] Code adjustments for Swift 5.8 compiler #542

Merged
merged 8 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions Campus-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
36108BE727A304B5007DC62D /* MenuViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BD427A304B5007DC62D /* MenuViewModel.swift */; };
36108BE927A304B5007DC62D /* MenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BD627A304B5007DC62D /* MenuView.swift */; };
36108BEB27A304B6007DC62D /* CafeteriaRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BD927A304B5007DC62D /* CafeteriaRowView.swift */; };
36108BED27A304B6007DC62D /* MapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BDB27A304B5007DC62D /* MapView.swift */; };
36108BEF27A304B6007DC62D /* MapContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BDD27A304B5007DC62D /* MapContentView.swift */; };
36108BF027A304B6007DC62D /* PanelContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BDE27A304B5007DC62D /* PanelContentView.swift */; };
36108BFA27A30517007DC62D /* Movie.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BF327A30516007DC62D /* Movie.swift */; };
Expand Down Expand Up @@ -486,7 +485,6 @@
36108BD427A304B5007DC62D /* MenuViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuViewModel.swift; sourceTree = "<group>"; };
36108BD627A304B5007DC62D /* MenuView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuView.swift; sourceTree = "<group>"; };
36108BD927A304B5007DC62D /* CafeteriaRowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CafeteriaRowView.swift; sourceTree = "<group>"; };
36108BDB27A304B5007DC62D /* MapView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapView.swift; sourceTree = "<group>"; };
36108BDD27A304B5007DC62D /* MapContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapContentView.swift; sourceTree = "<group>"; };
36108BDE27A304B5007DC62D /* PanelContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PanelContentView.swift; sourceTree = "<group>"; };
36108BF327A30516007DC62D /* Movie.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Movie.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1151,7 +1149,6 @@
children = (
3654F382285171F6008AD5DC /* StudyRooms */,
36108BD127A304B5007DC62D /* Cafeterias */,
36108BDB27A304B5007DC62D /* MapView.swift */,
1FAF9F0B284D2ABC000ABE93 /* MapScreenView.swift */,
36108BDD27A304B5007DC62D /* MapContentView.swift */,
36108BDE27A304B5007DC62D /* PanelContentView.swift */,
Expand Down Expand Up @@ -2194,7 +2191,6 @@
3654F38628517BB4008AD5DC /* CafeteriaView.swift in Sources */,
36BB6F8D27B3F25A00F224AB /* NSMutableString+Extensions.swift in Sources */,
1F04F175297AD4280085F273 /* CalendarScreen.swift in Sources */,
36108BED27A304B6007DC62D /* MapView.swift in Sources */,
36AF61E827A2FD7800FEBD98 /* AlertErrorHandler.swift in Sources */,
36BB6F5327AFCCB500F224AB /* PersonDetailedView.swift in Sources */,
3654F37E2851710E008AD5DC /* RoomFinderDetailsView.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Campus-iOS/AnalyticsComponent/AnalyticsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct AnalyticsController {
print("Info: app usage data upload is disabled.")
return

/*
if !didOptIn {
return
}
Expand Down Expand Up @@ -89,5 +90,6 @@ struct AnalyticsController {
request.setValue(postToken, forHTTPHeaderField: "Authorization")

let (_, _) = try await URLSession.shared.data(for: request)
*/
}
}
33 changes: 12 additions & 21 deletions Campus-iOS/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,19 @@ struct CampusApp: App {
.environmentObject(model)
.environment(\.managedObjectContext, persistenceController.container.viewContext)
.task {
if model.loginController.credentials == Credentials.noTumID {
guard let credentials = model.loginController.credentials else {
model.isUserAuthenticated = false
} else {
await model.loginController.confirmToken() { result in
switch result {
case .success:
#if !targetEnvironment(macCatalyst)
Analytics.logEvent("token_confirmed", parameters: nil)
#endif
DispatchQueue.main.async {
model.isLoginSheetPresented = false
model.isUserAuthenticated = true
}

// model.loadProfile()
case .failure(_):
model.isUserAuthenticated = false
if !model.showProfile {
model.isLoginSheetPresented = true
}
}
}
model.isLoginSheetPresented = true
return
}

switch credentials {
case .noTumID:
model.isUserAuthenticated = false
model.isLoginSheetPresented = false
case .tumID(tumID: _, token: _), .tumIDAndKey(tumID: _, token: _, key: _):
model.isUserAuthenticated = true
model.isLoginSheetPresented = false
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Campus-iOS/Base/Networking/APIs/TUMCabeAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum TUMCabeAPI: API {
case .newsSources: return "news/sources"
case .newsAlert: return "news/alert"
case .roomSearch(let room): return "roomfinder/room/search/\(room.addingPercentEncoding(withAllowedCharacters: .afURLQueryAllowed) ?? "")"
case .roomMaps(let room): return "roomfinder/room/availableMaps/\(room)"
case .roomMaps(let room): return "roomfinder/room/availableMaps/\(room.addingPercentEncoding(withAllowedCharacters: .afURLQueryAllowed) ?? "")"
case .roomCoordinates(let room): return "roomfinder/room/coordinates/\(room)"
case .defaultMap(let room): return "roomfinder/room/defaultMap/\(room)"
case .mapImage(let room, let id): return "roomfinder/room/map/\(room)/\(id)"
Expand Down
2 changes: 1 addition & 1 deletion Campus-iOS/Campus-iOS/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"No Links" = "No Links";
"Cafeteria Map" = "Cafeteria Map";
"Search Rooms" = "Search Rooms";
"Room Finder" = "Room Finder";
"Roomfinder" = "Roomfinder";
"Unable to find room" = "Unable to find room '%@'";
"No Menu" = "No Menu";
"List View" = "List View";
Expand Down
4 changes: 2 additions & 2 deletions Campus-iOS/Campus-iOS/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"No Links" = "Keine Links";
"Cafeteria Map" = "Mensa Landkarte";
"Search Rooms" = "Räume suchen";
"Room Finder" = "Room Finder";
"Roomfinder" = "Roomfinder";
"Unable to find room" = "Raum '%@' konnte nicht gefunden werden";
"No Menu" = "Kein Menü";
"List View" = "Listenansicht";
Expand Down Expand Up @@ -163,7 +163,7 @@
"Unknown" = "Unbekannt";

// Roomfinder
"Roomfinder" = "Raum Finder";
"Roomfinder" = "Roomfinder";
"Building" = "Gebäude";
"Room" = "Raum";
"Detail" = "Detail";
Expand Down
39 changes: 13 additions & 26 deletions Campus-iOS/HelperViews/ImageFullScreenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,21 @@ import SwiftUI
struct ImageFullScreenView: View {

@State var image: Image
@State var zoomScale: CGFloat = 1.0
@State private var lastScale: CGFloat = 1.0
@State var scale: CGFloat = 1.0
@State var viewState = CGSize.zero

var body: some View {
GeometryReader { imageWrapper in
self.image
.resizable()
.aspectRatio(contentMode: .fit)
.scaleEffect(self.zoomScale)
.animation(.spring(), value: self.viewState)

.offset(x: self.viewState.width, y: self.viewState.height)
.gesture(DragGesture().onChanged { val in
self.viewState = val.translation
})
.gesture(MagnificationGesture()
.onChanged { val in
let delta = val / self.lastScale
self.lastScale = val
if delta > 0.94 { // if statement to minimize jitter
let newScale = self.zoomScale * delta
self.zoomScale = newScale
}
}
.onEnded { _ in
self.lastScale = 1.0})
}
self.image
.resizable()
.aspectRatio(contentMode: .fit)
.offset(x: self.viewState.width, y: self.viewState.height)
.scaleEffect(self.scale)
.gesture(DragGesture().onChanged { val in
self.viewState = val.translation
})
.gesture(MagnificationGesture().onChanged { val in
self.scale = val.magnitude
})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ struct LectureDetailsEventInfoView: View {
)
HStack {
Spacer()
NavigationLink(destination: RoomFinderView(model: viewModel.model, viewModel: RoomFinderViewModel(), searchText: extract(room: self.location))) {
NavigationLink(destination: NavigaTumView(model: viewModel.model, searchText: extract(room: self.location))
.navigationTitle(Text("Roomfinder"))
.navigationBarTitleDisplayMode(.large)) {
HStack {
Text("Open in RoomFinder")
Image(systemName: "arrow.right.circle")
Expand Down
29 changes: 16 additions & 13 deletions Campus-iOS/LoginComponent/Service/AuthenticationHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AuthenticationHandler {
do {
let tokenName = "TCA - \(await UIDevice.current.name)"

let token: Token = try await MainAPI.makeRequest(endpoint: TUMOnlineAPI.tokenRequest(tumID: tumID, tokenName: tokenName))
let token: Token = try await MainAPI.makeRequest(endpoint: TUMOnlineAPI.tokenRequest(tumID: tumID, tokenName: tokenName), forcedRefresh: true)
print(token.value)
self.credentials = Credentials.tumID(tumID: tumID, token: token.value)
completion(.success(token.value))
Expand All @@ -75,32 +75,35 @@ class AuthenticationHandler {

}

func confirmToken(callback: @escaping (Result<Bool,Error>) -> Void) async {
if let credentials = credentials {
switch credentials {
case .noTumID: callback(.failure(LoginError.missingToken))
case .tumID(tumID: _, token: let token),
.tumIDAndKey(tumID: _, token: let token, key: _):
func confirmToken() async -> Result<Bool, Error> {
guard let credentials else {
return .failure(TUMOnlineAPIError.invalidToken)
}

switch credentials {
case .noTumID:
return .failure(LoginError.missingToken)
case .tumID(tumID: _, token: let token), .tumIDAndKey(tumID: _, token: let token, key: _):
do {
let confirmation: Confirmation = try await MainAPI.makeRequest(endpoint: TUMOnlineAPI.tokenConfirmation, token: token)
let confirmation: Confirmation = try await MainAPI.makeRequest(endpoint: TUMOnlineAPI.tokenConfirmation, token: token, forcedRefresh: true)

if confirmation.value {
callback(.success(true))
return .success(true)
} else {
callback(.failure(TUMOnlineAPIError.tokenNotConfirmed))
return .failure(TUMOnlineAPIError.tokenNotConfirmed)
}
} catch {
print(error.localizedDescription)
callback(.failure(LoginError.serverError(message: error.localizedDescription)))
return .failure(LoginError.serverError(message: error.localizedDescription))
}
}
}
}

func logout() {
#if !targetEnvironment(macCatalyst)
Analytics.logEvent("logout", parameters: nil)
#endif
// deletes uthenticationHandler.keychain[data: "credentials"]
// deletes authenticationHandler.keychain[data: "credentials"]
credentials = nil
}

Expand Down
12 changes: 5 additions & 7 deletions Campus-iOS/LoginComponent/ViewModel/LoginViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,23 @@ class LoginViewModel: ObservableObject {
}

func checkAuthorization(callback: @escaping (Result<Bool,Error>) -> Void) async {
await loginController.confirmToken { result in
switch result {
switch await model.loginController.confirmToken() {
case .success:
#if !targetEnvironment(macCatalyst)
Analytics.logEvent("token_confirmed", parameters: nil)
#endif
//wself?.model?.isLoginSheetPresented = false

DispatchQueue.main.async {
self.model.isUserAuthenticated = true
self.model.showProfile = false
}
// self.model?.loadProfile()


callback(.success(true))
case let .failure(error):
case .failure(let error):
self.model.isUserAuthenticated = false
self.alertMessage = error.localizedDescription

callback(.failure(error))
}
}
}
}
22 changes: 10 additions & 12 deletions Campus-iOS/LoginComponent/Views/TokenConfirmationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct TokenConfirmationView: View {
if !tokenPermissionButton {
Button(action: {
Task {
await self.viewModel.checkAuthorization() { result in
await self.viewModel.checkAuthorization() { result in
switch result {
case .success:
withAnimation {
Expand Down Expand Up @@ -178,17 +178,15 @@ struct TokenConfirmationView: View {
}
}
case .active:
if let model = self.viewModel.model {
NavigationLink(destination: TokenPermissionsView(viewModel: TokenPermissionsViewModel(model: model)).navigationTitle("Check Permissions"), isActive: $isActive) {
Text("Next")
.lineLimit(1)
.font(.body)
.frame(width: 200, height: 48, alignment: .center)
.foregroundColor(.white)
.background(.green)
.cornerRadius(10)
.buttonStyle(.plain)
}
NavigationLink(destination: TokenPermissionsView(viewModel: TokenPermissionsViewModel(model: self.viewModel.model)).navigationTitle("Check Permissions"), isActive: $isActive) {
Text("Next")
.lineLimit(1)
.font(.body)
.frame(width: 200, height: 48, alignment: .center)
.foregroundColor(.white)
.background(.green)
.cornerRadius(10)
.buttonStyle(.plain)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Campus-iOS/LoginComponent/Views/TokenPermissionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct TokenPermissionsView: View {
.padding()

VStack {
HStack (){
HStack {
Button {
self.showTUMOnline = true
self.doneButton = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ struct CafeteriaWidgetView: View {
WidgetLoadingView(text: "Searching nearby cafeteria")
default:
if let cafeteria = viewModel.cafeteria,
let title = cafeteria.title,
let coordinate = cafeteria.coordinate {
let title = cafeteria.title {
CafeteriaWidgetContent(
size: size,
cafeteria: title,
dishes: viewModel.menu?.getDishes() ?? [],
coordinate: coordinate
coordinate: cafeteria.coordinate
)
} else {
TextWidgetView(text: "There was an error getting the menu from the nearest cafeteria.")
Expand Down
6 changes: 5 additions & 1 deletion Campus-iOS/MapComponent/View/Cafeterias/MealPlanView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ struct MealPlanView: View {
}
.padding(.horizontal, 5.0)

MenuView(menu: selectedMenu)

/*
if let menu = selectedMenu {
MenuView(menu: menu)

} else {
Spacer().frame(height: 20)
Text("No Menu available today").foregroundColor(colorScheme == .dark ? .init(UIColor.lightGray) : .init(UIColor.darkGray))
}
*/
}
} else {
Text("No Menus available")
Expand Down
28 changes: 0 additions & 28 deletions Campus-iOS/MapComponent/View/MapView.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct StudyRoomDetailsScreen: View {
Spacer()
LoadingView(text: "Fetching RoomImages")
Spacer()
}.task {
await vm.getRoomImageMapping(for: room)
}
case .failed(let error):
VStack {
Expand All @@ -45,8 +47,6 @@ struct StudyRoomDetailsScreen: View {
.padding()
}
}
}.task {
await vm.getRoomImageMapping(for: self.room)
}.alert(
"Error while fetching Room Images",
isPresented: $vm.hasError,
Expand Down
Loading