From 2ea4182e6329b641b6d785c33f78ea822be31b45 Mon Sep 17 00:00:00 2001 From: David Huh <38101884+qt1337@users.noreply.github.com> Date: Mon, 21 Dec 2020 21:48:26 +0100 Subject: [PATCH] Added TextFields to FirstTimeOpening --- DHBW-Service.xcodeproj/project.pbxproj | 4 +- .../DHBW_Service.xcdatamodel/contents | 8 +++- DHBW-Service/Views/ContentView.swift | 1 + .../Views/Other/FirstOpeningSettings.swift | 48 +++++++++++++++++-- DHBW-Service/Views/Tabs/HomeView.swift | 1 + 5 files changed, 55 insertions(+), 7 deletions(-) diff --git a/DHBW-Service.xcodeproj/project.pbxproj b/DHBW-Service.xcodeproj/project.pbxproj index 8bd7118..f239b18 100644 --- a/DHBW-Service.xcodeproj/project.pbxproj +++ b/DHBW-Service.xcodeproj/project.pbxproj @@ -495,7 +495,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; @@ -517,7 +517,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/CoreData/DHBW_Service.xcdatamodeld/DHBW_Service.xcdatamodel/contents b/DHBW-Service/CoreData/DHBW_Service.xcdatamodeld/DHBW_Service.xcdatamodel/contents index e8d6ec8..43cf81e 100644 --- a/DHBW-Service/CoreData/DHBW_Service.xcdatamodeld/DHBW_Service.xcdatamodel/contents +++ b/DHBW-Service/CoreData/DHBW_Service.xcdatamodeld/DHBW_Service.xcdatamodel/contents @@ -1,9 +1,15 @@ - + + + + + + + \ No newline at end of file diff --git a/DHBW-Service/Views/ContentView.swift b/DHBW-Service/Views/ContentView.swift index cff9d32..14c2b8f 100644 --- a/DHBW-Service/Views/ContentView.swift +++ b/DHBW-Service/Views/ContentView.swift @@ -39,5 +39,6 @@ struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() .preferredColorScheme(.dark) + .environmentObject(LocalSettings()) } } diff --git a/DHBW-Service/Views/Other/FirstOpeningSettings.swift b/DHBW-Service/Views/Other/FirstOpeningSettings.swift index 7fa5e67..7869feb 100644 --- a/DHBW-Service/Views/Other/FirstOpeningSettings.swift +++ b/DHBW-Service/Views/Other/FirstOpeningSettings.swift @@ -6,21 +6,61 @@ // import SwiftUI +import CoreData struct FirstOpeningSettings: View { @EnvironmentObject var settings: LocalSettings + @State private var name = "" + @State private var course = "" + @State private var director = "" var body: some View { - Button(action: { - self.settings.isFirstOpening = !self.settings.isFirstOpening - }){ - Text("First opening toggle") + + VStack { + TextField("Name", text: self.$name) + .textContentType(.name) + .textFieldStyle(RoundedBorderTextFieldStyle()) + .frame(minWidth: 200, idealWidth: nil, maxWidth: 500, minHeight: nil, idealHeight: nil, maxHeight: nil, alignment: .center) + .padding(.horizontal) + TextField("Course", 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", text: self.$director) + .textContentType(.name) + .textFieldStyle(RoundedBorderTextFieldStyle()) + .frame(minWidth: 200, idealWidth: nil, maxWidth: 500, minHeight: nil, idealHeight: nil, maxHeight: nil, alignment: .center) + .padding(.horizontal) + Button(action: { + self.settings.isFirstOpening = !self.settings.isFirstOpening + }){ + Text("Confirm") + .padding() + .foregroundColor(.white) + .background(Color.blue) + .cornerRadius(15) + } } } } +extension FirstOpeningSettings{ + func saveToCoreData(){ + let entity = NSEntityDescription.entity(forEntityName: "User", in: PersistenceController.shared.context)! + let user = NSManagedObject(entity: entity, insertInto: PersistenceController.shared.context) + user.setValue(name, forKey: "name") + user.setValue(course, forKey: "course") + user.setValue(director, forKey: "director") + + PersistenceController.shared.save() + } +} + struct FirstOpeningSettings_Previews: PreviewProvider { static var previews: some View { FirstOpeningSettings() + .preferredColorScheme(.dark) + .environmentObject(LocalSettings()) } } diff --git a/DHBW-Service/Views/Tabs/HomeView.swift b/DHBW-Service/Views/Tabs/HomeView.swift index 482691f..10b984a 100644 --- a/DHBW-Service/Views/Tabs/HomeView.swift +++ b/DHBW-Service/Views/Tabs/HomeView.swift @@ -26,5 +26,6 @@ struct HomeView_Previews: PreviewProvider { static var previews: some View { HomeView() .preferredColorScheme(.dark) + .environmentObject(LocalSettings()) } }