diff --git a/DHBW-Service.xcodeproj/project.pbxproj b/DHBW-Service.xcodeproj/project.pbxproj index 285cd09..be72445 100644 --- a/DHBW-Service.xcodeproj/project.pbxproj +++ b/DHBW-Service.xcodeproj/project.pbxproj @@ -551,7 +551,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_ASSET_PATHS = "\"DHBW-Service/Preview Content\""; - DEVELOPMENT_TEAM = HS7KNT4MZ2; + DEVELOPMENT_TEAM = G3TRS8UHWN; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = "DHBW-Service/Supporting Files/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 14.0; @@ -573,7 +573,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_ASSET_PATHS = "\"DHBW-Service/Preview Content\""; - DEVELOPMENT_TEAM = HS7KNT4MZ2; + DEVELOPMENT_TEAM = G3TRS8UHWN; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = "DHBW-Service/Supporting Files/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 14.0; diff --git a/DHBW-Service/Supporting Files/l10n/en.lproj/General.strings b/DHBW-Service/Supporting Files/l10n/en.lproj/General.strings index 69266d5..3e95653 100644 --- a/DHBW-Service/Supporting Files/l10n/en.lproj/General.strings +++ b/DHBW-Service/Supporting Files/l10n/en.lproj/General.strings @@ -8,3 +8,5 @@ "name" = "Name"; "course" = "Course"; "director" = "Director"; +"filledAuto" = "filled automatically"; +"welcomeText" = "Please enter your data in the following fields."; diff --git a/DHBW-Service/Views/Other/FirstOpeningSettings.swift b/DHBW-Service/Views/Other/FirstOpeningSettings.swift index dc39d0e..c0efed4 100644 --- a/DHBW-Service/Views/Other/FirstOpeningSettings.swift +++ b/DHBW-Service/Views/Other/FirstOpeningSettings.swift @@ -13,27 +13,44 @@ struct FirstOpeningSettings: View { @State private var name = "" @State private var course = "" @State private var director = "" + @State private var invalidInputName = false + @State private var invalidInputCourse = false var body: some View { VStack { + + Text("welcomeText".localized(tableName: "General", plural: false)) TextField("name".localized(tableName: "General", plural: false), text: self.$name) + + .overlay(RoundedRectangle(cornerRadius: 10).stroke(invalidInputCourse ? Color.red : Color.secondary, lineWidth: 1)) + .foregroundColor(invalidInputName ? .red : .primary) .textContentType(.name) .textFieldStyle(RoundedBorderTextFieldStyle()) .frame(minWidth: 200, idealWidth: nil, maxWidth: 500, minHeight: nil, idealHeight: nil, maxHeight: nil, alignment: .center) .padding(.horizontal) - TextField("course".localized(tableName: "General", plural: false), text: self.$course) - .textContentType(.name) - .textFieldStyle(RoundedBorderTextFieldStyle()) - .frame(minWidth: 200, idealWidth: nil, maxWidth: 500, minHeight: nil, idealHeight: nil, maxHeight: nil, alignment: .center) - .padding(.horizontal) - TextField("director".localized(tableName: "General", plural: false), text: self.$director) + + TextField("course".localized(tableName: "General", plural: false), + text: self.$course) + .overlay(RoundedRectangle(cornerRadius: 10).stroke(invalidInputCourse ? Color.red : Color.secondary, lineWidth: 1)) + .onChange(of: course, perform: { value in + self.setDirector() + }) + .foregroundColor(invalidInputCourse ? .red : .primary) + .textContentType(.name) + .disableAutocorrection(true) + .textFieldStyle(RoundedBorderTextFieldStyle()) + .frame(minWidth: 200, idealWidth: nil, maxWidth: 500, minHeight: nil, idealHeight: nil, maxHeight: nil, alignment: .center) + .padding(.horizontal) + + TextField("director".localized(tableName: "General", plural: false) + " (" + "filledAuto".localized(tableName: "General", plural: false) + ")", text: self.$director) + .foregroundColor(.primary) .textContentType(.name) .textFieldStyle(RoundedBorderTextFieldStyle()) .frame(minWidth: 200, idealWidth: nil, maxWidth: 500, minHeight: nil, idealHeight: nil, maxHeight: nil, alignment: .center) .padding(.horizontal) + .disabled(true) Button(action: { - self.settings.isFirstOpening = !self.settings.isFirstOpening self.saveToCoreData() }){ Text("Confirm") @@ -47,7 +64,32 @@ struct FirstOpeningSettings: View { } extension FirstOpeningSettings{ + func setDirector() { + if (course == "TINF19B4") { + director = "Jörn Eisenbiegler" + } else { + director = "" + } + } + + func checkInput() -> Bool { + let nameRegex = try! NSRegularExpression(pattern: "[a-zA-ZÄÖÜäöüß]+") + let courseRegex = try! NSRegularExpression(pattern: "[T|G|W][A-Z]{2,3}[0-9]{2}B[1-9]") + let nameRange = NSRange(location: 0, length: name.utf16.count) + let courseRange = NSRange(location: 0, length: course.utf16.count) + + invalidInputName = nameRegex.firstMatch(in: name, options: [], range: nameRange) == nil + invalidInputCourse = courseRegex.firstMatch(in: course, options: [], range: courseRange) == nil + + return !invalidInputName && !invalidInputCourse + } + func saveToCoreData(){ + if (!self.checkInput()) { + print("Input invalid") + return + } + // Delete old user data let status = UtilityFunctions.deleteAllCoreDataEntitiesOfType(type: "User") print("Deleting old user data status: \(status)") @@ -59,6 +101,7 @@ extension FirstOpeningSettings{ user.setValue(course, forKey: "course") user.setValue(director, forKey: "director") + self.settings.isFirstOpening = !self.settings.isFirstOpening PersistenceController.shared.save() } } diff --git a/DHBW-Service/Views/Tabs/HomeView.swift b/DHBW-Service/Views/Tabs/HomeView.swift index b3b08a0..58c6a77 100644 --- a/DHBW-Service/Views/Tabs/HomeView.swift +++ b/DHBW-Service/Views/Tabs/HomeView.swift @@ -16,13 +16,6 @@ struct HomeView: View { var body: some View { VStack { - Button(action: { - self.settings.isFirstOpening = !self.settings.isFirstOpening - }){ - Text("First opening toggle") - } - Text("Test") - HStack { Text("name".localized(tableName: "General", plural: false) + ": ") Text(self.name)