changeset 26:f8f54f72e843

Version sent to test
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Thu, 14 Jan 2021 11:52:36 +0000
parents 7ca00d9f3aa9
children 3dd331a54bc7
files FavCompany+CoreDataProperties.swift LazyBear.xcodeproj/project.pbxproj LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate lazybear/Functions/Price.swift lazybear/LazyBear.xcdatamodeld/LazyBear.xcdatamodel/contents lazybear/Main.swift lazybear/SampleConfig.swift lazybear/Stock.swift lazybear/Supply/FavCompanyRow.swift lazybear/Supply/WhatsNew.swift lazybear/User.swift
diffstat 11 files changed, 133 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/FavCompany+CoreDataProperties.swift	Wed Jan 13 17:13:42 2021 +0000
+++ b/FavCompany+CoreDataProperties.swift	Thu Jan 14 11:52:36 2021 +0000
@@ -16,7 +16,7 @@
         return NSFetchRequest<FavCompany>(entityName: "FavCompany")
     }
 
-    @NSManaged public var cik: Int16
+    @NSManaged public var cik: Int32
     @NSManaged public var symbol: String
     @NSManaged public var name: String
 
--- a/LazyBear.xcodeproj/project.pbxproj	Wed Jan 13 17:13:42 2021 +0000
+++ b/LazyBear.xcodeproj/project.pbxproj	Thu Jan 14 11:52:36 2021 +0000
@@ -14,6 +14,7 @@
 		954D996D25A2461B001F7F60 /* SwiftUICharts in Frameworks */ = {isa = PBXBuildFile; productRef = 954D996C25A2461B001F7F60 /* SwiftUICharts */; };
 		954D997125A253A9001F7F60 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954D997025A253A9001F7F60 /* Config.swift */; };
 		954D998325A27571001F7F60 /* Price.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954D998225A27571001F7F60 /* Price.swift */; };
+		9552A61F25B06580001CD0C8 /* SampleConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9552A61E25B0657F001CD0C8 /* SampleConfig.swift */; };
 		955AD1F425AE2BDC00965D42 /* TestFavourites.swift in Sources */ = {isa = PBXBuildFile; fileRef = 955AD1F325AE2BDC00965D42 /* TestFavourites.swift */; };
 		95612C472598D17F00F7698F /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95612C462598D17F00F7698F /* User.swift */; };
 		95612C4A2598D1F800F7698F /* About.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95612C492598D1F800F7698F /* About.swift */; };
@@ -51,6 +52,7 @@
 		954D992425A2123B001F7F60 /* PriceModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PriceModel.swift; path = lazybear/Models/PriceModel.swift; sourceTree = SOURCE_ROOT; };
 		954D997025A253A9001F7F60 /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Config.swift; path = lazybear/Config.swift; sourceTree = SOURCE_ROOT; };
 		954D998225A27571001F7F60 /* Price.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Price.swift; path = lazybear/Functions/Price.swift; sourceTree = SOURCE_ROOT; };
+		9552A61E25B0657F001CD0C8 /* SampleConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SampleConfig.swift; path = lazybear/SampleConfig.swift; sourceTree = SOURCE_ROOT; };
 		955AD1F325AE2BDC00965D42 /* TestFavourites.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestFavourites.swift; path = lazybear/Tests/TestFavourites.swift; sourceTree = SOURCE_ROOT; };
 		95612C462598D17F00F7698F /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = User.swift; path = lazybear/User.swift; sourceTree = SOURCE_ROOT; };
 		95612C492598D1F800F7698F /* About.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = About.swift; path = lazybear/About.swift; sourceTree = SOURCE_ROOT; };
@@ -185,6 +187,7 @@
 				95002578256D1564008FFD28 /* Configuration.storekit */,
 				95F7CAF425ADC7B7009E0E7C /* LazyBear.xcdatamodeld */,
 				954D997025A253A9001F7F60 /* Config.swift */,
+				9552A61E25B0657F001CD0C8 /* SampleConfig.swift */,
 				95B04EB225212369000AD27F /* LazyBearApp.swift */,
 				95B04EB425212369000AD27F /* ContentView.swift */,
 				95D1BF4B25ADD08500E5D063 /* Main.swift */,
@@ -312,6 +315,7 @@
 				954D997125A253A9001F7F60 /* Config.swift in Sources */,
 				95A1ECAF25A36127001D4A21 /* Transaction.swift in Sources */,
 				9521A8BD259B93200000D417 /* Company.swift in Sources */,
+				9552A61F25B06580001CD0C8 /* SampleConfig.swift in Sources */,
 				954D992525A2123B001F7F60 /* PriceModel.swift in Sources */,
 				95F7CAF625ADC7B7009E0E7C /* LazyBear.xcdatamodeld in Sources */,
 				95DF519D259DE118003790B2 /* TipJar.swift in Sources */,
@@ -460,7 +464,7 @@
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SUPPORTS_MACCATALYST = NO;
 				SWIFT_VERSION = 5.0;
-				TARGETED_DEVICE_FAMILY = "1,2";
+				TARGETED_DEVICE_FAMILY = 1;
 			};
 			name = Debug;
 		};
@@ -487,7 +491,7 @@
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SUPPORTS_MACCATALYST = NO;
 				SWIFT_VERSION = 5.0;
-				TARGETED_DEVICE_FAMILY = "1,2";
+				TARGETED_DEVICE_FAMILY = 1;
 			};
 			name = Release;
 		};
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/lazybear/Functions/Price.swift	Wed Jan 13 17:13:42 2021 +0000
+++ b/lazybear/Functions/Price.swift	Thu Jan 14 11:52:36 2021 +0000
@@ -13,7 +13,7 @@
     @Published var showingAlert = false
     
     func request(symbol: String) {
-        guard let url = URL(string: priceUrl(symbol: symbol, sandbox: true)) else {  // Change sandbox when production
+        guard let url = URL(string: priceUrl(symbol: symbol, sandbox: false)) else {  // Change sandbox when production
             print("Invalid URL")
             return
         }
--- a/lazybear/LazyBear.xcdatamodeld/LazyBear.xcdatamodel/contents	Wed Jan 13 17:13:42 2021 +0000
+++ b/lazybear/LazyBear.xcdatamodeld/LazyBear.xcdatamodel/contents	Thu Jan 14 11:52:36 2021 +0000
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="17709" systemVersion="20C69" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
     <entity name="FavCompany" representedClassName="FavCompany" syncable="YES">
-        <attribute name="cik" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
+        <attribute name="cik" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
         <attribute name="name" optional="YES" attributeType="String"/>
         <attribute name="symbol" optional="YES" attributeType="String"/>
     </entity>
--- a/lazybear/Main.swift	Wed Jan 13 17:13:42 2021 +0000
+++ b/lazybear/Main.swift	Thu Jan 14 11:52:36 2021 +0000
@@ -12,6 +12,7 @@
     @State var showingSettings = false
     @State var showingUser = false
     @State public var showingSearch: Bool = false  // Search Bar
+    @Environment(\.managedObjectContext) private var viewContext
     
     var body: some View {
         VStack {
@@ -33,10 +34,9 @@
                             .imageIconModifier()
                     }.sheet(isPresented: $showingUser) {
                         User()
+                            .environment(\.managedObjectContext, self.viewContext)
                     }
                 }
-                .transition(.move(edge: .top))
-                .animation(.default)
                 .padding()
             }
             
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lazybear/SampleConfig.swift	Thu Jan 14 11:52:36 2021 +0000
@@ -0,0 +1,31 @@
+//
+//  SampleConfig.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 14/1/21.
+//
+
+/*
+import SwiftUI
+
+func samplePriceUrl(symbol: String, sandbox: Bool) -> String {
+    var token = ""
+    var url = ""
+    if sandbox {
+        token = "SANDBOX TOKEN"
+        url = "SANDBOX URL"
+    }
+    else {
+        token = "TOKEN"
+        url = "URL"
+    }
+    
+    return url
+}
+
+func sampleTransactionUrl(cik: String, date: String) -> String {
+    let url = "URL"
+    
+    return url
+}
+*/
--- a/lazybear/Stock.swift	Wed Jan 13 17:13:42 2021 +0000
+++ b/lazybear/Stock.swift	Thu Jan 14 11:52:36 2021 +0000
@@ -44,18 +44,17 @@
                 }
                 
                 // Stock Price
-                let width = geo.size.height*0.6
+                let width = geo.size.width*0.9
                 let prices = price.result.map { $0.close }  // Get an array of a variable in the struct
-                LineChartView(data: prices, title: "Stock price", legend: "Last 20 days",  form: CGSize(width: width, height: width/1.8), rateValue: nil)
-                    .padding()
-                
-                Spacer()
-            
-                // Volume
-                let volume = price.result.map { $0.volume }
-                BarChartView(data: ChartData(points: volume), title: "Volume", form: CGSize(width: width, height: width/1.6))
+                ScrollView {
+                    LineChartView(data: prices, title: "Stock price", legend: "Last 20 days",  form: CGSize(width: width, height: width/2), rateValue: nil)  // It has a minimum height
                         .padding()
                     
+                    // Volume
+                    let volume = price.result.map { $0.volume }
+                    BarChartView(data: ChartData(points: volume), title: "Volume", form: CGSize(width: width, height: width/1.5))
+                            .padding()
+                    }
                 }
             }
         }
--- a/lazybear/Supply/FavCompanyRow.swift	Wed Jan 13 17:13:42 2021 +0000
+++ b/lazybear/Supply/FavCompanyRow.swift	Thu Jan 14 11:52:36 2021 +0000
@@ -17,13 +17,13 @@
         let names = favCompanies.map { $0.name }
         HStack {
             if names.contains(company.name) {
-                Button(action: { deleteFavourite(symbol: company.symbol, name: company.name) }) {
+                Button(action: { deleteFavourite(symbol: company.symbol) }) {
                     Image(systemName: "minus.circle.fill")
                         .iconModifier()
                 }
             }
             else {
-                Button(action: { addFavourite(symbol: company.symbol, name: company.name) }) {
+                Button(action: { addFavourite(cik: company.cik, symbol: company.symbol, name: company.name) }) {
                     Image(systemName: "plus.circle.fill")
                         .iconModifier()
                 }
@@ -32,8 +32,9 @@
         }
     }
     
-    func addFavourite(symbol: String, name: String) {
+    func addFavourite(cik: Int, symbol: String, name: String) {
         let favCompany = FavCompany(context: viewContext)
+        favCompany.cik = Int32(cik)
         favCompany.symbol = symbol
         favCompany.name = name
         do {
@@ -44,8 +45,17 @@
         }
     }
     
-    func deleteFavourite(symbol: String, name: String) {
-        
+    func deleteFavourite(symbol: String) {
+        let symbols = favCompanies.map { $0.symbol }  // Get array of symbols
+        let index = symbols.firstIndex(of: symbol)  // Find index of the symbol to delete
+        viewContext.delete(favCompanies[index!])  // Delete it
+        // Save the deletion
+        do {
+            try viewContext.save()
+            print("Company deleted")
+        } catch {
+            print(error.localizedDescription)
+        }
     }
 }
 extension Image {
--- a/lazybear/Supply/WhatsNew.swift	Wed Jan 13 17:13:42 2021 +0000
+++ b/lazybear/Supply/WhatsNew.swift	Thu Jan 14 11:52:36 2021 +0000
@@ -13,35 +13,62 @@
         GeometryReader { geo in
             ScrollView {
                 VStack(alignment: .leading, spacing: 20) {
-                    let intro = "This new version comes with lots of changes and many cool stuff. I've been working hard to improve the backend efficiency, deploy a new API and other boring stuff that you probably are not interested in. So let's talk about the cool stuff."
-                    Text(intro)
-                        
-                    let title1 = "New design"
-                    let text1 = "As you can see, there is a completely new design, more clean, colourful, and simple. Now you can check the date for the company you want in three clicks. Less is more."
-                    Text(title1 + " 😎")
-                        .title()
-                        
-                    Text(text1)
+                    Group {
+                        let intro = "This new version comes with lots of changes and many cool stuff. I've been working hard to improve the backend efficiency, deploy a new API and other boring stuff that you probably are not interested in. So let's talk about the cool stuff."
+                        Text(intro)
+                    }
                     
-                    let title2 = "Charts! A bunch!"
-                    let text2 = "Look how cool they are"
-                    Text(title2)
-                        .title()
+                    Group {
+                        let title1 = "New design"
+                        let text1 = "As you can see, there is a completely new design, more clean, colourful, and simple. Less is more."
+                        Text(title1 + " 😎")
+                            .title()
+                            
+                        Text(text1)
+                    }
                     
-                    Text(text2 + " 😁")
-                    HStack {
-                        Spacer()
-                        let width = geo.size.height*0.4
-                        LineChartView(data: [8,23,54,32,12,37,7,23,43], title: "Some cool title", form: CGSize(width: width, height: width/2), rateValue: 14)
-                        Spacer()
+                    Group {
+                        let title2 = "Charts! A bunch!"
+                        let text2 = "Look how cool they are"
+                        Text(title2)
+                            .title()
+                        
+                        Text(text2 + " 😁")
                     }
                     
-                    let title3 = "Stock prices"
-                    let text3 = "Finally I found a not-so-expensive method to show stock prices. In this version you can see the latest stock price from the previous day, but I promise you in future versions I am going to add real-time stock prices."
-                    Text(title3)
-                        .title()
+                    Group {
+                        HStack {
+                            Spacer()
+                            let width = geo.size.height*0.4
+                            LineChartView(data: [8,23,54,32,12,37,7,23,43], title: "Some cool title", form: CGSize(width: width, height: width/2), rateValue: 14)
+                            Spacer()
+                        }
+                    }
                     
-                    Text(text3)
+                    Group {
+                        let title3 = "Stock prices"
+                        let text3 = "Finally I found a not-so-expensive method to show stock prices. In this version you can see the latest stock price from the previous day, but I promise you in future versions I am going to add real-time stock prices."
+                        Text(title3)
+                            .title()
+                        
+                        Text(text3)
+                    }
+                    
+                    Group {
+                        let title4 = "Watchlist 👀"
+                        let text4 = "Now, you can save your favourite companies to have a quick access whenever you want."
+                        Text(title4)
+                            .title()
+                        
+                        Text(text4)
+                        
+                        Text("Favourites")
+                            .font(.headline)
+                        
+                        ExampleFavourite(companyName: "Apple Inc")
+                        ExampleFavourite(companyName: "Netflix")
+                        ExampleFavourite(companyName: "Goldman Sachs")
+                    }
                 }
                 .padding()
             }
@@ -56,6 +83,17 @@
     }
 }
 
+struct ExampleFavourite: View {
+    @State var companyName: String
+    var body: some View {
+        HStack {
+            Image(systemName: "star.fill")
+                .renderingMode(.original)
+            Text(companyName)
+        }
+    }
+}
+
 struct WhatsNew_Previews: PreviewProvider {
     static var previews: some View {
         WhatsNew()
--- a/lazybear/User.swift	Wed Jan 13 17:13:42 2021 +0000
+++ b/lazybear/User.swift	Thu Jan 14 11:52:36 2021 +0000
@@ -25,8 +25,11 @@
                     List {
                         ForEach(favCompanies) { favCompany in
                             HStack {
-                                Text(favCompany.name.capitalized)
-
+                                NavigationLink(destination: Company(cik: Int(favCompany.cik), symbol: favCompany.symbol, name: favCompany.name)
+                                                .navigationBarTitle(favCompany.name.capitalized)
+                                ) {
+                                    Text(favCompany.name.capitalized)
+                                }
                             }.padding()
                         }
                         // Delete from persistent storage
@@ -65,6 +68,7 @@
                     Image(systemName: "multiply")
                         .resizable()
                         .frame(width: 25, height: 25)
+                    
                 }
             )
         }