changeset 341:4e6c47a81b80

Testing UserProfile
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sun, 04 Apr 2021 13:20:14 +0200
parents d17dd5c28211
children a6c49f1409f3
files LazyBear.xcodeproj/project.pbxproj LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate LazyBear/ContentView.swift LazyBear/Global Models/UserSettings+CoreDataClass.swift LazyBear/Global Models/UserSettings+CoreDataProperties.swift LazyBear/LazyBear.entitlements LazyBear/LazyBear.xcdatamodeld/LazyBear.xcdatamodel/contents LazyBear/Persistence.swift LazyBear/Views/Home/HomeView.swift LazyBear/Views/Profile/Helpers/EditProfile.swift LazyBear/Views/Profile/Helpers/ImagePicker.swift LazyBear/Views/Profile/Helpers/UserProfile.swift LazyBear/Views/Profile/ProfileView.swift LazyBear/Views/Search/SearchView.swift
diffstat 14 files changed, 195 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/LazyBear.xcodeproj/project.pbxproj	Sat Apr 03 17:46:05 2021 +0200
+++ b/LazyBear.xcodeproj/project.pbxproj	Sun Apr 04 13:20:14 2021 +0200
@@ -8,8 +8,6 @@
 
 /* Begin PBXBuildFile section */
 		950C36E3260FB6180081CF53 /* HapticsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950C36E2260FB6180081CF53 /* HapticsManager.swift */; };
-		950C36E8260FBB550081CF53 /* UserSettings+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950C36E6260FBB550081CF53 /* UserSettings+CoreDataClass.swift */; };
-		950C36E9260FBB550081CF53 /* UserSettings+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950C36E7260FBB550081CF53 /* UserSettings+CoreDataProperties.swift */; };
 		950D0E192618AA4900D17AD7 /* CompanyList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950D0E182618AA4900D17AD7 /* CompanyList.swift */; };
 		950D0E222618AD4A00D17AD7 /* SearchModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950D0E212618AD4A00D17AD7 /* SearchModel.swift */; };
 		950D0E252618ADD000D17AD7 /* SearchData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950D0E242618ADD000D17AD7 /* SearchData.swift */; };
@@ -50,14 +48,16 @@
 		95E745DA2614624500744A1E /* HomeDataPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E745D92614624500744A1E /* HomeDataPreview.swift */; };
 		95ECCA5D2612169200A67EFA /* LineShape.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95ECCA5C2612169200A67EFA /* LineShape.swift */; };
 		95ECCA60261216D500A67EFA /* LineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95ECCA5F261216D500A67EFA /* LineView.swift */; };
+		95FBE0DC2619CA7200440386 /* ProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95FBE0DB2619CA7200440386 /* ProfileView.swift */; };
+		95FBE0E32619CBE500440386 /* UserProfile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95FBE0E22619CBE500440386 /* UserProfile.swift */; };
+		95FBE0E72619CC8700440386 /* ImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95FBE0E62619CC8700440386 /* ImagePicker.swift */; };
+		95FBE0EB2619D31100440386 /* EditProfile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95FBE0EA2619D31100440386 /* EditProfile.swift */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
 		950BA46B25E944F500D065EF /* Production.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Production.xcconfig; sourceTree = "<group>"; };
 		950BA46C25E944FC00D065EF /* Sandbox.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Sandbox.xcconfig; sourceTree = "<group>"; };
 		950C36E2260FB6180081CF53 /* HapticsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HapticsManager.swift; sourceTree = "<group>"; };
-		950C36E6260FBB550081CF53 /* UserSettings+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserSettings+CoreDataClass.swift"; sourceTree = "<group>"; };
-		950C36E7260FBB550081CF53 /* UserSettings+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserSettings+CoreDataProperties.swift"; sourceTree = "<group>"; };
 		950D0E182618AA4900D17AD7 /* CompanyList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanyList.swift; sourceTree = "<group>"; };
 		950D0E212618AD4A00D17AD7 /* SearchModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchModel.swift; sourceTree = "<group>"; };
 		950D0E242618ADD000D17AD7 /* SearchData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchData.swift; sourceTree = "<group>"; };
@@ -100,6 +100,10 @@
 		95E745D92614624500744A1E /* HomeDataPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeDataPreview.swift; sourceTree = "<group>"; };
 		95ECCA5C2612169200A67EFA /* LineShape.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineShape.swift; sourceTree = "<group>"; };
 		95ECCA5F261216D500A67EFA /* LineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineView.swift; sourceTree = "<group>"; };
+		95FBE0DB2619CA7200440386 /* ProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = "<group>"; };
+		95FBE0E22619CBE500440386 /* UserProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserProfile.swift; sourceTree = "<group>"; };
+		95FBE0E62619CC8700440386 /* ImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePicker.swift; sourceTree = "<group>"; };
+		95FBE0EA2619D31100440386 /* EditProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditProfile.swift; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -169,8 +173,6 @@
 		954D7E9D260BBA5200A13C50 /* Global Models */ = {
 			isa = PBXGroup;
 			children = (
-				950C36E6260FBB550081CF53 /* UserSettings+CoreDataClass.swift */,
-				950C36E7260FBB550081CF53 /* UserSettings+CoreDataProperties.swift */,
 				954D7EA5260BBA6600A13C50 /* WatchlistCompany+CoreDataClass.swift */,
 				954D7EA6260BBA6600A13C50 /* WatchlistCompany+CoreDataProperties.swift */,
 			);
@@ -299,6 +301,7 @@
 				951490572610BD3000BDEEB5 /* Welcome */,
 				954D7EAA260BBB0E00A13C50 /* Home */,
 				95A7C06126163943003E2EC1 /* Search */,
+				95FBE0DA2619CA6000440386 /* Profile */,
 				95893DD22613CAB5003698C5 /* Global Helpers */,
 			);
 			path = Views;
@@ -320,6 +323,25 @@
 			path = Networking;
 			sourceTree = "<group>";
 		};
+		95FBE0DA2619CA6000440386 /* Profile */ = {
+			isa = PBXGroup;
+			children = (
+				95FBE0DB2619CA7200440386 /* ProfileView.swift */,
+				95FBE0E12619CBD600440386 /* Helpers */,
+			);
+			path = Profile;
+			sourceTree = "<group>";
+		};
+		95FBE0E12619CBD600440386 /* Helpers */ = {
+			isa = PBXGroup;
+			children = (
+				95FBE0E22619CBE500440386 /* UserProfile.swift */,
+				95FBE0EA2619D31100440386 /* EditProfile.swift */,
+				95FBE0E62619CC8700440386 /* ImagePicker.swift */,
+			);
+			path = Helpers;
+			sourceTree = "<group>";
+		};
 /* End PBXGroup section */
 
 /* Begin PBXNativeTarget section */
@@ -396,22 +418,24 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				95FBE0E72619CC8700440386 /* ImagePicker.swift in Sources */,
 				950C36E3260FB6180081CF53 /* HapticsManager.swift in Sources */,
+				95FBE0DC2619CA7200440386 /* ProfileView.swift in Sources */,
+				95FBE0EB2619D31100440386 /* EditProfile.swift in Sources */,
 				95A5186A26185AAB0002D27C /* GenericRequest.swift in Sources */,
 				95E745DA2614624500744A1E /* HomeDataPreview.swift in Sources */,
 				95A5187726186C830002D27C /* IntradayPricesModel.swift in Sources */,
 				95A5188626186F590002D27C /* PriceView.swift in Sources */,
 				9550444926111FC9000E0BCB /* TopStockRow.swift in Sources */,
 				9523ED542615CB7F006D3D6F /* HomeData.swift in Sources */,
+				95FBE0E32619CBE500440386 /* UserProfile.swift in Sources */,
 				9550444326111E7A000E0BCB /* SectorRow.swift in Sources */,
 				950D0E302618B34600D17AD7 /* BlurBackground.swift in Sources */,
 				95ECCA60261216D500A67EFA /* LineView.swift in Sources */,
 				9550443A26111B2B000E0BCB /* HomeView.swift in Sources */,
-				950C36E8260FBB550081CF53 /* UserSettings+CoreDataClass.swift in Sources */,
 				95A5187426186C680002D27C /* SectorPerformanceModel.swift in Sources */,
 				95672B9825DDA54700DCBE4A /* Persistence.swift in Sources */,
 				95A7C0742616409D003E2EC1 /* ParseJSON.swift in Sources */,
-				950C36E9260FBB550081CF53 /* UserSettings+CoreDataProperties.swift in Sources */,
 				954D7EA8260BBA6600A13C50 /* WatchlistCompany+CoreDataProperties.swift in Sources */,
 				951566E72613A2B6007C0F36 /* TradingDates.swift in Sources */,
 				95893DCE2613C46B003698C5 /* CompanyQuoteModel.swift in Sources */,
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/LazyBear/ContentView.swift	Sat Apr 03 17:46:05 2021 +0200
+++ b/LazyBear/ContentView.swift	Sun Apr 04 13:20:14 2021 +0200
@@ -24,14 +24,14 @@
                         Image(systemName: "magnifyingglass")
                         Text("Search")
                     }
-                Text("The Last Tab")
+                ProfileView()
                     .tabItem {
-                        Image(systemName: "3.square.fill")
-                        Text("Third")
+                        Image(systemName: "person")
+                        Text("Profile")
                     }
                 Text("The Last Tab")
                     .tabItem {
-                        Image(systemName: "3.square.fill")
+                        Image(systemName: "4.square.fill")
                         Text("Forth")
                     }
             }
--- a/LazyBear/Global Models/UserSettings+CoreDataClass.swift	Sat Apr 03 17:46:05 2021 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-//
-//  UserSettings+CoreDataClass.swift
-//  LazyBear
-//
-//  Created by Dennis Concepción Martín on 27/3/21.
-//
-//
-
-import Foundation
-import CoreData
-
-@objc(UserSettings)
-public class UserSettings: NSManagedObject {
-
-}
--- a/LazyBear/Global Models/UserSettings+CoreDataProperties.swift	Sat Apr 03 17:46:05 2021 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-//
-//  UserSettings+CoreDataProperties.swift
-//  LazyBear
-//
-//  Created by Dennis Concepción Martín on 27/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 body: String
-    @NSManaged public var bodyColor: String
-    @NSManaged public var eyes: String
-    @NSManaged public var facialHair: String
-    @NSManaged public var hair: String
-    @NSManaged public var hairColor: String
-    @NSManaged public var mouth: String
-    @NSManaged public var nose: String
-    @NSManaged public var skinTone: String
-    @NSManaged public var background: String
-
-}
-
-extension UserSettings : Identifiable {
-
-}
--- a/LazyBear/LazyBear.entitlements	Sat Apr 03 17:46:05 2021 +0200
+++ b/LazyBear/LazyBear.entitlements	Sun Apr 04 13:20:14 2021 +0200
@@ -6,7 +6,7 @@
 	<string>development</string>
 	<key>com.apple.developer.icloud-container-identifiers</key>
 	<array>
-		<string>iCloud.v4.Lazybear</string>
+		<string>iCloud.app.lazybear</string>
 	</array>
 	<key>com.apple.developer.icloud-services</key>
 	<array>
--- a/LazyBear/LazyBear.xcdatamodeld/LazyBear.xcdatamodel/contents	Sat Apr 03 17:46:05 2021 +0200
+++ b/LazyBear/LazyBear.xcdatamodeld/LazyBear.xcdatamodel/contents	Sun Apr 04 13:20:14 2021 +0200
@@ -3,19 +3,6 @@
     <entity name="Entity" representedClassName="Entity" syncable="YES" codeGenerationType="class">
         <attribute name="attribute" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
     </entity>
-    <entity name="UserSettings" representedClassName="UserSettings" syncable="YES">
-        <attribute name="background" optional="YES" attributeType="String"/>
-        <attribute name="body" optional="YES" attributeType="String"/>
-        <attribute name="bodyColor" optional="YES" attributeType="String"/>
-        <attribute name="eyes" optional="YES" attributeType="String"/>
-        <attribute name="facialHair" optional="YES" attributeType="String"/>
-        <attribute name="hair" optional="YES" attributeType="String"/>
-        <attribute name="hairColor" optional="YES" attributeType="String"/>
-        <attribute name="mouth" optional="YES" attributeType="String"/>
-        <attribute name="nose" optional="YES" attributeType="String"/>
-        <attribute name="skinTone" optional="YES" attributeType="String"/>
-        <attribute name="username" optional="YES" attributeType="String"/>
-    </entity>
     <entity name="WatchlistCompany" representedClassName="WatchlistCompany" syncable="YES">
         <attribute name="name" optional="YES" attributeType="String"/>
         <attribute name="symbol" optional="YES" attributeType="String"/>
@@ -23,7 +10,6 @@
     </entity>
     <elements>
         <element name="Entity" positionX="-63" positionY="-18" width="128" height="44"/>
-        <element name="UserSettings" positionX="-63" positionY="9" width="128" height="14"/>
         <element name="WatchlistCompany" positionX="-63" positionY="-9" width="128" height="74"/>
     </elements>
 </model>
\ No newline at end of file
--- a/LazyBear/Persistence.swift	Sat Apr 03 17:46:05 2021 +0200
+++ b/LazyBear/Persistence.swift	Sun Apr 04 13:20:14 2021 +0200
@@ -16,9 +16,6 @@
         for _ in 0..<10 {
             let entity = Entity(context: viewContext)
             entity.attribute = 1
-            
-            let userSettings = UserSettings(context: viewContext)
-            userSettings.username = "Dennis"
     
         }
         do {
--- a/LazyBear/Views/Home/HomeView.swift	Sat Apr 03 17:46:05 2021 +0200
+++ b/LazyBear/Views/Home/HomeView.swift	Sun Apr 04 13:20:14 2021 +0200
@@ -10,7 +10,8 @@
 struct HomeView: View {
     @ObservedObject var homeData = HomeData()
     @State private var showTradingDates = false
-    @State private var timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()  // Set recurrent price request
+    // Set recurrent price request
+    @State private var timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()
     
     static let taskDateFormat: DateFormatter = {
         let formatter = DateFormatter()
@@ -55,7 +56,8 @@
             ProgressView()
                 .onAppear {
                     homeData.request()
-                    self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()  // Restart timer
+                    // Restart timer
+                    self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()
                 }
             
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Profile/Helpers/EditProfile.swift	Sun Apr 04 13:20:14 2021 +0200
@@ -0,0 +1,33 @@
+//
+//  EditProfile.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 4/4/21.
+//
+
+import SwiftUI
+
+struct EditProfile: View {
+    var body: some View {
+        NavigationView {
+            Form {
+                let footer = "This could be your first name or nickname. Let you creativity flow."
+                Section(header: Text("Name"), footer: Text(footer)) {
+                    Text("Hello")
+                }
+                
+                Section(header: Text("Country")) {
+                    Text("Country")
+                }
+            }
+            .navigationTitle("Edit your profile")
+            .navigationBarTitleDisplayMode(.inline)
+        }
+    }
+}
+
+struct EditProfile_Previews: PreviewProvider {
+    static var previews: some View {
+        EditProfile()
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Profile/Helpers/ImagePicker.swift	Sun Apr 04 13:20:14 2021 +0200
@@ -0,0 +1,45 @@
+//
+//  ImagePicker.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 4/4/21.
+//
+
+import SwiftUI
+
+struct ImagePicker: UIViewControllerRepresentable {
+    @Environment(\.presentationMode) var presentationMode
+    @Binding var image: UIImage?
+
+    func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePicker>) -> UIImagePickerController {
+        let picker = UIImagePickerController()
+        picker.delegate = context.coordinator
+        return picker
+    }
+
+    func updateUIViewController(_ uiViewController: UIImagePickerController, context: UIViewControllerRepresentableContext<ImagePicker>) {
+
+    }
+    
+    class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
+        let parent: ImagePicker
+
+        init(_ parent: ImagePicker) {
+            self.parent = parent
+        }
+        
+        func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
+            if let uiImage = info[.originalImage] as? UIImage {
+                parent.image = uiImage
+            }
+
+            parent.presentationMode.wrappedValue.dismiss()
+        }
+    }
+    
+    func makeCoordinator() -> Coordinator {
+        Coordinator(self)
+        
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Profile/Helpers/UserProfile.swift	Sun Apr 04 13:20:14 2021 +0200
@@ -0,0 +1,44 @@
+//
+//  UserProfile.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 4/4/21.
+//
+
+import SwiftUI
+
+struct UserProfile: View {
+    @State private var showingImagePicker = false
+    @State private var inputImage: UIImage?
+    @State private var userImage = Image("")
+    
+    var body: some View {
+        VStack {
+            Circle()
+                .frame(width: 200, height: 200)
+                .overlay(
+                    userImage
+                        .resizable()
+                        .clipShape(Circle())
+
+                )
+                .onTapGesture { self.showingImagePicker = true }
+
+        }
+        .sheet(isPresented: $showingImagePicker, onDismiss: loadImage) {
+            ImagePicker(image: self.$inputImage)
+        }
+    }
+    
+    private func loadImage() {
+        guard let inputImage = inputImage else { return }
+        userImage = Image(uiImage: inputImage)
+
+    }
+}
+
+struct UserProfile_Previews: PreviewProvider {
+    static var previews: some View {
+        UserProfile()
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Profile/ProfileView.swift	Sun Apr 04 13:20:14 2021 +0200
@@ -0,0 +1,22 @@
+//
+//  ProfileView.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 4/4/21.
+//
+
+import SwiftUI
+
+struct ProfileView: View {
+    var body: some View {
+        NavigationView {
+            UserProfile()
+        }
+    }
+}
+
+struct ProfileView_Previews: PreviewProvider {
+    static var previews: some View {
+        ProfileView()
+    }
+}
--- a/LazyBear/Views/Search/SearchView.swift	Sat Apr 03 17:46:05 2021 +0200
+++ b/LazyBear/Views/Search/SearchView.swift	Sun Apr 04 13:20:14 2021 +0200
@@ -32,10 +32,7 @@
             .navigationBarTitleDisplayMode(.inline)
             .navigationBarSearch($searchedText)
             .onChange(of: searchedText, perform: { searchedText in
-                if !searchedText.isEmpty {
-                    searchData.request(searchedText)
-                    self.showingSearchList = true
-                }
+                showSearchList(searchedText)
             })
             .toolbar {
                 ToolbarItem(placement: .navigationBarTrailing) {
@@ -46,6 +43,15 @@
             }
         }
     }
+    
+    private func showSearchList(_ searchedText: String) {
+        if !searchedText.isEmpty {
+            // Encode string with spaces
+            let encodedSearchedText = searchedText.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
+            searchData.request(encodedSearchedText!)
+            self.showingSearchList = true
+        }
+    }
 }
 
 struct SearchView_Previews: PreviewProvider {