From 7f976cd6e7e1ebc545e21037d3344c19116c6a64 Mon Sep 17 00:00:00 2001 From: David Lin Date: Thu, 3 Nov 2022 20:58:14 +0100 Subject: [PATCH 1/2] Adding a new warning if not all permissions are granted. --- ...nPermissionsViewModel+PermissionType.swift | 12 +- .../Views/TokenPermissionsView.swift | 103 ++++++++++++------ 2 files changed, 73 insertions(+), 42 deletions(-) diff --git a/Campus-iOS/LoginComponent/ViewModel/TokenPermissionsViewModel+PermissionType.swift b/Campus-iOS/LoginComponent/ViewModel/TokenPermissionsViewModel+PermissionType.swift index 8423ed5e..67f97fa0 100644 --- a/Campus-iOS/LoginComponent/ViewModel/TokenPermissionsViewModel+PermissionType.swift +++ b/Campus-iOS/LoginComponent/ViewModel/TokenPermissionsViewModel+PermissionType.swift @@ -8,11 +8,11 @@ import Foundation extension TokenPermissionsViewModel { - enum PermissionType { - case grades - case calendar - case lectures - case tuitionFees - case identification + enum PermissionType: String { + case grades = "Grades" + case calendar = "Calendar" + case lectures = "Lectures" + case tuitionFees = "Tuition Fees" + case identification = "Identification (TUM ID and name)" } } diff --git a/Campus-iOS/LoginComponent/Views/TokenPermissionsView.swift b/Campus-iOS/LoginComponent/Views/TokenPermissionsView.swift index 478b7f87..7f72c05e 100644 --- a/Campus-iOS/LoginComponent/Views/TokenPermissionsView.swift +++ b/Campus-iOS/LoginComponent/Views/TokenPermissionsView.swift @@ -13,13 +13,21 @@ struct TokenPermissionsView: View { @Environment(\.dismiss) var dismiss @State var doneButton = false @State var showTUMOnline = false + @State var notAllPermissionsGranted = false + @State var permissionsWarning = "" var dismissWhenDone: Bool = false + let permissionTypes: [TokenPermissionsViewModel.PermissionType] = [.calendar, .lectures, .grades, .tuitionFees, .identification] + var body: some View { VStack() { - Text("You can change your permissions on TUMOnline") - .foregroundColor(.tumBlue) + HStack { + Spacer() + Text("You can change your permissions on TUMOnline") + .foregroundColor(.tumBlue) + Spacer() + } HStack { VStack(alignment: .leading) { Text("Calendar").padding() @@ -30,34 +38,12 @@ struct TokenPermissionsView: View { } Spacer() VStack { - if let currentState = viewModel.states[.calendar] { - check(state: currentState).padding() - } else { - Image(systemName: "questionmark.circle.fill").foregroundColor(.gray).padding() - } - - if let currentState = viewModel.states[.lectures] { - check(state: currentState).padding() - } else { - Image(systemName: "questionmark.circle.fill").foregroundColor(.gray).padding() - } - - if let currentState = viewModel.states[.grades] { - check(state: currentState).padding() - } else { - Image(systemName: "questionmark.circle.fill").foregroundColor(.gray).padding() - } - - if let currentState = viewModel.states[.tuitionFees] { - check(state: currentState).padding() - } else { - Image(systemName: "questionmark.circle.fill").foregroundColor(.gray).padding() - } - - if let currentState = viewModel.states[.identification] { - check(state: currentState).padding() - } else { - Image(systemName: "questionmark.circle.fill").foregroundColor(.gray).padding() + ForEach(permissionTypes, id: \.self) { permissionType in + if let currentState = viewModel.states[permissionType] { + check(state: currentState).padding() + } else { + Image(systemName: "questionmark.circle.fill").foregroundColor(.gray).padding() + } } } } @@ -100,13 +86,28 @@ struct TokenPermissionsView: View { } if doneButton { + // Insert the warning string and switch bool + Button { - if dismissWhenDone { - // Dismiss when view is opened from Profile/Settings. - dismiss() + if allPermissionsAreGranted() { + if dismissWhenDone { + // Dismiss when view is opened from Profile/Settings. + dismiss() + } else { + // Used when shown via the login process sheet. + self.viewModel.model.isLoginSheetPresented = false + } } else { - // Used when shown via the login process sheet. - self.viewModel.model.isLoginSheetPresented = false + // Not all permissions were granted + + permissionsWarning = "You have not granted the following permissions: \n\n" + for permission in notGrantedPermissions() { + self.permissionsWarning.append("\(permission.rawValue)\n ") + } + permissionsWarning.append("\nJust be aware that the app will not fully work without all permissions. You can change the permissions every time in TUMOnline.") + + notAllPermissionsGranted = true + } } label: { Text("Done") @@ -114,7 +115,7 @@ struct TokenPermissionsView: View { .font(.body) .frame(width: 200, height: 48, alignment: .center) .foregroundColor(.white) - .background(.green) + .background(allPermissionsAreGranted() ? .green : .tumBlue) .cornerRadius(10) .buttonStyle(.plain) } @@ -125,6 +126,36 @@ struct TokenPermissionsView: View { .sheet(isPresented: $showTUMOnline) { SFSafariViewWrapper(url: Constants.tokenManagementTUMOnlineUrl).edgesIgnoringSafeArea(.bottom) } + .alert(isPresented: $notAllPermissionsGranted) { + Alert(title: Text("Permissions Warning"), message: Text(permissionsWarning), primaryButton: Alert.Button.cancel(), secondaryButton: Alert.Button.destructive(Text("Continue anyways"), action: { + if dismissWhenDone { + // Dismiss when view is opened from Profile/Settings. + dismiss() + } else { + // Used when shown via the login process sheet. + self.viewModel.model.isLoginSheetPresented = false + } + })) + } + } + + func notGrantedPermissions() -> [TokenPermissionsViewModel.PermissionType] { + return permissionTypes.filter { permissionType in + if case .success = viewModel.states[permissionType] { + return false + } else { + return true + } + } + } + + func allPermissionsAreGranted() -> Bool { + for permissionType in permissionTypes { + if case .success = viewModel.states[permissionType] {} else { + return false + } + } + return true } @ViewBuilder From 5dfa6b99c49ad765a00492a59b1826ee2cb54e58 Mon Sep 17 00:00:00 2001 From: David Lin Date: Thu, 3 Nov 2022 21:32:17 +0100 Subject: [PATCH 2/2] Spacers and Localizables --- Campus-iOS/Campus-iOS/Base.lproj/Localizable.strings | 3 +++ Campus-iOS/Campus-iOS/de.lproj/Localizable.strings | 3 +++ .../LoginComponent/Views/TokenPermissionsView.swift | 8 ++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Campus-iOS/Campus-iOS/Base.lproj/Localizable.strings b/Campus-iOS/Campus-iOS/Base.lproj/Localizable.strings index cdfeebd5..4fca1aa8 100644 --- a/Campus-iOS/Campus-iOS/Base.lproj/Localizable.strings +++ b/Campus-iOS/Campus-iOS/Base.lproj/Localizable.strings @@ -102,6 +102,9 @@ "You can change your permissions on TUMOnline" = "You can change your permissions on TUMOnline"; "Identification (TUM ID and name)" = "Identification (TUM ID and name)"; "Check Permissions" = "Check Permissions"; +"You have not granted the following permissions: \n\n" = "You have not granted the following permissions: \n\n"; +"\nJust be aware that the app will not fully work without all permissions. You can change the permissions every time in TUMOnline." = "\nJust be aware that the app will not fully work without all permissions. You can change the permissions every time in TUMOnline."; +"Continue anyways" = "Continue anyways"; // ProfileView "Token Permissions" = "Token Permissions"; diff --git a/Campus-iOS/Campus-iOS/de.lproj/Localizable.strings b/Campus-iOS/Campus-iOS/de.lproj/Localizable.strings index d2bdb252..93714cd9 100644 --- a/Campus-iOS/Campus-iOS/de.lproj/Localizable.strings +++ b/Campus-iOS/Campus-iOS/de.lproj/Localizable.strings @@ -96,6 +96,9 @@ "You can change your permissions on TUMOnline" = "Du kannst deine Rechte auf TUMOnline anpassen"; "Identification (TUM ID and name)" = "Identifikation (TUM ID und Name)"; "Check Permissions" = "Rechte überprüfen"; +"You have not granted the following permissions: \n\n" = "Du hast nicht alle Rechte freigegeben: \n\n"; +"\nJust be aware that the app will not fully work without all permissions. You can change the permissions every time in TUMOnline." = "\nDadurch können nicht alle Features der App genutzt werden. Du kannst die Rechte jederzeit auf TUMOnline anpassen."; +"Continue anyways" = "Trotzdem weiter"; // ProfileView "Token Permissions" = "Token Rechte"; diff --git a/Campus-iOS/LoginComponent/Views/TokenPermissionsView.swift b/Campus-iOS/LoginComponent/Views/TokenPermissionsView.swift index 7f72c05e..2cd3cc67 100644 --- a/Campus-iOS/LoginComponent/Views/TokenPermissionsView.swift +++ b/Campus-iOS/LoginComponent/Views/TokenPermissionsView.swift @@ -21,12 +21,13 @@ struct TokenPermissionsView: View { let permissionTypes: [TokenPermissionsViewModel.PermissionType] = [.calendar, .lectures, .grades, .tuitionFees, .identification] var body: some View { - VStack() { + VStack(alignment: .center) { HStack { - Spacer() + Spacer(minLength: 10) Text("You can change your permissions on TUMOnline") .foregroundColor(.tumBlue) - Spacer() + .multilineTextAlignment(.center) + Spacer(minLength: 10) } HStack { VStack(alignment: .leading) { @@ -107,7 +108,6 @@ struct TokenPermissionsView: View { permissionsWarning.append("\nJust be aware that the app will not fully work without all permissions. You can change the permissions every time in TUMOnline.") notAllPermissionsGranted = true - } } label: { Text("Done")