changeset 312:d0f7e9231178

Implementing CloudKit
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Thu, 25 Mar 2021 17:07:59 +0100
parents cabb85aa0f18
children c6d1940aa68e
files LazyBear/Assets.xcassets/Avatars/Contents.json LazyBear/Assets.xcassets/Avatars/Random selection/Contents.json LazyBear/Assets.xcassets/Avatars/Random selection/random1.imageset/Contents.json LazyBear/Assets.xcassets/Memojis/Contents.json LazyBear/Assets.xcassets/Memojis/testMemoji.imageset/Contents.json LazyBear/Assets.xcassets/Themes/default.colorset/Contents.json LazyBear/LazyBear.entitlements LazyBear/LazyBearApp.swift LazyBear/Models/UserSettings+CoreDataClass.swift LazyBear/Models/UserSettings+CoreDataProperties.swift LazyBear/Views/Home/Helpers/UserHelper.swift LazyBear/Views/Onboarding/Helpers/EnvironmentSignUp.swift LazyBear/Views/Onboarding/Helpers/ListAvatarHelper.swift LazyBear/Views/Onboarding/SignUpView.swift LazyBear/Views/Onboarding/WelcomeView.swift UserSettings+CoreDataClass.swift UserSettings+CoreDataProperties.swift
diffstat 17 files changed, 307 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Avatars/Contents.json	Thu Mar 25 17:07:59 2021 +0100
@@ -0,0 +1,6 @@
+{
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Avatars/Random selection/Contents.json	Thu Mar 25 17:07:59 2021 +0100
@@ -0,0 +1,6 @@
+{
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Avatars/Random selection/random1.imageset/Contents.json	Thu Mar 25 17:07:59 2021 +0100
@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "filename" : "randomBoy1.png",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
--- a/LazyBear/Assets.xcassets/Memojis/Contents.json	Wed Mar 24 23:10:44 2021 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-{
-  "info" : {
-    "author" : "xcode",
-    "version" : 1
-  }
-}
--- a/LazyBear/Assets.xcassets/Memojis/testMemoji.imageset/Contents.json	Wed Mar 24 23:10:44 2021 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-{
-  "images" : [
-    {
-      "filename" : "testMemoji.png",
-      "idiom" : "universal",
-      "scale" : "1x"
-    },
-    {
-      "idiom" : "universal",
-      "scale" : "2x"
-    },
-    {
-      "idiom" : "universal",
-      "scale" : "3x"
-    }
-  ],
-  "info" : {
-    "author" : "xcode",
-    "version" : 1
-  }
-}
--- a/LazyBear/Assets.xcassets/Themes/default.colorset/Contents.json	Wed Mar 24 23:10:44 2021 +0100
+++ b/LazyBear/Assets.xcassets/Themes/default.colorset/Contents.json	Thu Mar 25 17:07:59 2021 +0100
@@ -5,9 +5,9 @@
         "color-space" : "srgb",
         "components" : {
           "alpha" : "1.000",
-          "blue" : "0.620",
-          "green" : "0.267",
-          "red" : "0.098"
+          "blue" : "0.996",
+          "green" : "0.729",
+          "red" : "0.290"
         }
       },
       "idiom" : "universal"
@@ -23,9 +23,9 @@
         "color-space" : "srgb",
         "components" : {
           "alpha" : "1.000",
-          "blue" : "0.996",
-          "green" : "0.729",
-          "red" : "0.290"
+          "blue" : "0.620",
+          "green" : "0.267",
+          "red" : "0.098"
         }
       },
       "idiom" : "universal"
--- a/LazyBear/LazyBear.entitlements	Wed Mar 24 23:10:44 2021 +0100
+++ b/LazyBear/LazyBear.entitlements	Thu Mar 25 17:07:59 2021 +0100
@@ -6,7 +6,7 @@
 	<string>development</string>
 	<key>com.apple.developer.icloud-container-identifiers</key>
 	<array>
-		<string>iCloud.dennis.LazyBear</string>
+		<string>iCloud.v4.Lazybear</string>
 	</array>
 	<key>com.apple.developer.icloud-services</key>
 	<array>
--- a/LazyBear/LazyBearApp.swift	Wed Mar 24 23:10:44 2021 +0100
+++ b/LazyBear/LazyBearApp.swift	Thu Mar 25 17:07:59 2021 +0100
@@ -18,6 +18,7 @@
                 .environment(\.managedObjectContext, persistenceController.container.viewContext)
             } else {
                 WelcomeView()
+                    .environment(\.managedObjectContext, persistenceController.container.viewContext)
             }
         }
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Models/UserSettings+CoreDataClass.swift	Thu Mar 25 17:07:59 2021 +0100
@@ -0,0 +1,15 @@
+//
+//  UserSettings+CoreDataClass.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 25/3/21.
+//
+//
+
+import Foundation
+import CoreData
+
+@objc(UserSettings)
+public class UserSettings: NSManagedObject {
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Models/UserSettings+CoreDataProperties.swift	Thu Mar 25 17:07:59 2021 +0100
@@ -0,0 +1,26 @@
+//
+//  UserSettings+CoreDataProperties.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 25/3/21.
+//
+//
+
+import Foundation
+import CoreData
+
+
+extension UserSettings {
+
+    @nonobjc public class func fetchRequest() -> NSFetchRequest<UserSettings> {
+        return NSFetchRequest<UserSettings>(entityName: "UserSettings")
+    }
+
+    @NSManaged public var username: String
+    @NSManaged public var avatar: String
+
+}
+
+extension UserSettings : Identifiable {
+
+}
--- a/LazyBear/Views/Home/Helpers/UserHelper.swift	Wed Mar 24 23:10:44 2021 +0100
+++ b/LazyBear/Views/Home/Helpers/UserHelper.swift	Thu Mar 25 17:07:59 2021 +0100
@@ -8,6 +8,8 @@
 import SwiftUI
 
 struct UserHelper: View {
+    @FetchRequest(entity: UserSettings.entity(), sortDescriptors: []) var userSettings: FetchedResults<UserSettings>
+    
     var body: some View {
         GeometryReader { geo in
             HStack {
@@ -16,7 +18,8 @@
                     .padding(.horizontal)
                 
                 VStack(alignment: .leading) {
-                    Text("Hello, Dennis!")
+                    let name = userSettings.first!.username
+                    Text("Hello, \(name)")
                         .font(.title)
                         .fontWeight(.semibold)
                     
@@ -29,13 +32,16 @@
 }
 
 struct UserImage: View {
+    @FetchRequest(entity: UserSettings.entity(), sortDescriptors: []) var userSettings: FetchedResults<UserSettings>
+    
     var body: some View {
+        let avatar = userSettings.first!.avatar
         RoundedRectangle(cornerRadius: 20)
             .aspectRatio(1.0, contentMode: .fit)
             .foregroundColor(Color("default"))
             .opacity(0.3)
             .overlay(
-                Image("testMemoji")
+                Image(avatar)
                     .resizable()
                     .aspectRatio(1.0, contentMode: .fit)
                     .cornerRadius(20)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Onboarding/Helpers/EnvironmentSignUp.swift	Thu Mar 25 17:07:59 2021 +0100
@@ -0,0 +1,20 @@
+//
+//  EnvironmentSignUp.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 25/3/21.
+//
+
+import SwiftUI
+
+struct EnvironmentSignUp: View {
+    var body: some View {
+        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
+    }
+}
+
+struct EnvironmentSignUp_Previews: PreviewProvider {
+    static var previews: some View {
+        EnvironmentSignUp()
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Onboarding/Helpers/ListAvatarHelper.swift	Thu Mar 25 17:07:59 2021 +0100
@@ -0,0 +1,31 @@
+//
+//  ListAvatarHelper.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 25/3/21.
+//
+
+import SwiftUI
+
+struct ListAvatarHelper: View {
+    let columns = [
+            GridItem(.flexible()),
+            GridItem(.flexible())
+        ]
+    
+    var body: some View {
+        ScrollView {
+            LazyVGrid(columns: columns, spacing: 20) {
+                ForEach((1..<8), id: \.self) { index in
+                    Image("randomGirl\(index)")
+                }
+            }
+        }
+    }
+}
+
+struct ListAvatarHelper_Previews: PreviewProvider {
+    static var previews: some View {
+        ListAvatarHelper()
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Onboarding/SignUpView.swift	Thu Mar 25 17:07:59 2021 +0100
@@ -0,0 +1,112 @@
+//
+//  SignUp.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 25/3/21.
+//
+
+import SwiftUI
+
+struct SignUp: View {
+    @State var username: String = ""
+    @State var textFieldIsEditing = false
+    
+    var body: some View {
+        GeometryReader { geo in
+            VStack(alignment: .leading) {
+                Text("Sign Up")
+                    .font((.system(size: 50, weight: .black)))
+                    .padding(.vertical)
+                
+                Text("Let us customise your experience")
+                    .opacity(0.5)
+                    .padding(.bottom)
+            
+                ProfileAvatar(size: geo.size.height * 0.3, textFieldIsEditing: $textFieldIsEditing)
+                    .padding(.bottom)
+                    
+                UserNameTextfield(username: $username, isEditing: $textFieldIsEditing)
+                Spacer()
+                NextButton(text: "Continue")
+                    .padding(.bottom, 50)
+                
+                
+            }
+            .padding(.horizontal)
+        }
+    }
+}
+
+struct SignUp_Previews: PreviewProvider {
+    static var previews: some View {
+        SignUp()
+    }
+}
+
+struct ProfileAvatar: View {
+    @State var size: CGFloat
+    @Binding var textFieldIsEditing: Bool
+    
+    var body: some View {
+        HStack {
+            Spacer()
+            ZStack(alignment: .topTrailing) {
+                Image("boyAvatar")
+                    .resizable()
+                    .frame(maxWidth: size, maxHeight: size)
+                    .scaledToFit()
+                    .clipShape(Circle())
+                
+                if !textFieldIsEditing {
+                    Image(systemName: "photo")
+                        .foregroundColor(.white)
+                        .padding()
+                        .background(
+                            Circle()
+                                .foregroundColor(Color("default"))
+                        )
+                        .padding()
+                }
+            }
+            
+            Spacer()
+        }
+    }
+}
+
+struct UserNameTextfield: View {
+    @Binding var username: String
+    @Binding var isEditing: Bool
+    
+    var body: some View {
+        VStack {
+        Text("Your username")
+            .font(.headline)
+        
+            TextField("Username", text: $username) { isEditing in
+                self.isEditing = isEditing
+            } onCommit: {
+                print(username)
+            }
+            .padding(8)
+            .background(
+                RoundedRectangle(cornerRadius: 10)
+                    .foregroundColor(Color(.systemGray6))
+            )
+        }
+    }
+}
+
+struct NextButton: View {
+    var text: String
+    
+    var body: some View {
+        RoundedRectangle(cornerRadius: 10)
+            .foregroundColor(Color("default"))
+            .frame(height: 50)
+            .overlay(
+            Text(text)
+                .foregroundColor(.white)
+            )
+    }
+}
--- a/LazyBear/Views/Onboarding/WelcomeView.swift	Wed Mar 24 23:10:44 2021 +0100
+++ b/LazyBear/Views/Onboarding/WelcomeView.swift	Thu Mar 25 17:07:59 2021 +0100
@@ -8,12 +8,20 @@
 import SwiftUI
 
 struct WelcomeView: View {
+    @FetchRequest(entity: UserSettings.entity(), sortDescriptors: []) var userSettings: FetchedResults<UserSettings>
+    @ObservedObject var environmentSignUp = EnvironmentSignUp()
     @State private var showingNextView = false
     @State private var showingProgressView = false
     
     var body: some View {
         if showingNextView {
-            WhatsNewView()
+            if userSettings.isEmpty {
+                SignUpView()
+                    .environmentObject(environmentSignUp)
+            } else {
+                ContentView()
+            }
+            
         } else {
             GeometryReader { geo in
                 VStack(alignment: .leading) {
@@ -26,12 +34,13 @@
                     
                     Group {
                         Text("Welcome to")
+                            .fontWeight(.black)
                         Text("Lazybear")
+                            .fontWeight(.black)
                             .foregroundColor(Color("default"))
-                            .offset(y: -15)
-                            .padding(.bottom, -15)
                     }
-                    .font((.system(size: 50, weight: .black)))
+                    .font(.largeTitle)
+                    
                             
                     Text("Easily follow your stocks and the markets in real-time.")
                     
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UserSettings+CoreDataClass.swift	Thu Mar 25 17:07:59 2021 +0100
@@ -0,0 +1,15 @@
+//
+//  UserSettings+CoreDataClass.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 25/3/21.
+//
+//
+
+import Foundation
+import CoreData
+
+@objc(UserSettings)
+public class UserSettings: NSManagedObject {
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UserSettings+CoreDataProperties.swift	Thu Mar 25 17:07:59 2021 +0100
@@ -0,0 +1,26 @@
+//
+//  UserSettings+CoreDataProperties.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 25/3/21.
+//
+//
+
+import Foundation
+import CoreData
+
+
+extension UserSettings {
+
+    @nonobjc public class func fetchRequest() -> NSFetchRequest<UserSettings> {
+        return NSFetchRequest<UserSettings>(entityName: "UserSettings")
+    }
+
+    @NSManaged public var username: String?
+    @NSManaged public var avatar: String?
+
+}
+
+extension UserSettings : Identifiable {
+
+}