changeset 398:933546fa5651

Implementing CompanyView
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sun, 09 May 2021 00:07:44 +0200
parents 6f04495c462d
children 5c99883c7964
files LazyBear.xcodeproj/project.pbxproj LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate LazyBear/Styles/PriceViewStyle.swift LazyBear/Views/Company/CompanyView.swift LazyBear/Views/Company/Helpers/Chart.swift LazyBear/Views/Company/Helpers/CompanyHeader.swift LazyBear/Views/Company/Helpers/DatePicker.swift LazyBear/Views/Company/Helpers/ViewType.swift LazyBear/Views/Global Helpers/PriceView.swift LazyBear/Views/Global Helpers/StockItem.swift
diffstat 10 files changed, 308 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/LazyBear.xcodeproj/project.pbxproj	Sat May 08 19:23:06 2021 +0200
+++ b/LazyBear.xcodeproj/project.pbxproj	Sun May 09 00:07:44 2021 +0200
@@ -61,6 +61,12 @@
 		95BD2FB326341D36008B6752 /* BlurBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BD2FB226341D36008B6752 /* BlurBackground.swift */; };
 		95C8C0E0262A369F0082D1D9 /* ProfileResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C8C0DF262A369F0082D1D9 /* ProfileResponse.swift */; };
 		95D308F82624B3A400A39F77 /* CurrencyItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95D308F72624B3A400A39F77 /* CurrencyItem.swift */; };
+		95E31C0D26472CA000106B98 /* CompanyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E31C0C26472CA000106B98 /* CompanyView.swift */; };
+		95E31C122647304100106B98 /* PriceViewStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E31C112647304100106B98 /* PriceViewStyle.swift */; };
+		95E31C142647363800106B98 /* Chart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E31C132647363800106B98 /* Chart.swift */; };
+		95E31C16264736BE00106B98 /* DatePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E31C15264736BE00106B98 /* DatePicker.swift */; };
+		95E31C1826473A4D00106B98 /* CompanyHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E31C1726473A4D00106B98 /* CompanyHeader.swift */; };
+		95E31C1C26473B5100106B98 /* ViewType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E31C1B26473B5100106B98 /* ViewType.swift */; };
 		95FBE0DC2619CA7200440386 /* ProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95FBE0DB2619CA7200440386 /* ProfileView.swift */; };
 /* End PBXBuildFile section */
 
@@ -142,6 +148,12 @@
 		95BD2FB226341D36008B6752 /* BlurBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurBackground.swift; sourceTree = "<group>"; };
 		95C8C0DF262A369F0082D1D9 /* ProfileResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileResponse.swift; sourceTree = "<group>"; };
 		95D308F72624B3A400A39F77 /* CurrencyItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyItem.swift; sourceTree = "<group>"; };
+		95E31C0C26472CA000106B98 /* CompanyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanyView.swift; sourceTree = "<group>"; };
+		95E31C112647304100106B98 /* PriceViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PriceViewStyle.swift; sourceTree = "<group>"; };
+		95E31C132647363800106B98 /* Chart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Chart.swift; sourceTree = "<group>"; };
+		95E31C15264736BE00106B98 /* DatePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePicker.swift; sourceTree = "<group>"; };
+		95E31C1726473A4D00106B98 /* CompanyHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanyHeader.swift; sourceTree = "<group>"; };
+		95E31C1B26473B5100106B98 /* ViewType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewType.swift; sourceTree = "<group>"; };
 		95FBE0DB2619CA7200440386 /* ProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
@@ -327,6 +339,7 @@
 				95B1874925DDAC4D0068A364 /* Views */,
 				952045132610C7A200A76362 /* Global functions */,
 				954D7E9D260BBA5200A13C50 /* Global Models */,
+				95E31C102647302F00106B98 /* Styles */,
 				9523ED402615BD93006D3D6F /* Resources */,
 				95672B9425DDA54700DCBE4A /* Preview Content */,
 			);
@@ -388,6 +401,7 @@
 				954D7EAA260BBB0E00A13C50 /* Home */,
 				95A7C06126163943003E2EC1 /* Search */,
 				95FBE0DA2619CA6000440386 /* Profile */,
+				95E31C0B26472C8500106B98 /* Company */,
 				95893DD22613CAB5003698C5 /* Global Helpers */,
 			);
 			path = Views;
@@ -415,6 +429,42 @@
 			path = Networking;
 			sourceTree = "<group>";
 		};
+		95E31C0B26472C8500106B98 /* Company */ = {
+			isa = PBXGroup;
+			children = (
+				95E31C0C26472CA000106B98 /* CompanyView.swift */,
+				95E31C0E26472CB600106B98 /* Helpers */,
+				95E31C0F26472CC000106B98 /* Networking */,
+			);
+			path = Company;
+			sourceTree = "<group>";
+		};
+		95E31C0E26472CB600106B98 /* Helpers */ = {
+			isa = PBXGroup;
+			children = (
+				95E31C1B26473B5100106B98 /* ViewType.swift */,
+				95E31C1726473A4D00106B98 /* CompanyHeader.swift */,
+				95E31C132647363800106B98 /* Chart.swift */,
+				95E31C15264736BE00106B98 /* DatePicker.swift */,
+			);
+			path = Helpers;
+			sourceTree = "<group>";
+		};
+		95E31C0F26472CC000106B98 /* Networking */ = {
+			isa = PBXGroup;
+			children = (
+			);
+			path = Networking;
+			sourceTree = "<group>";
+		};
+		95E31C102647302F00106B98 /* Styles */ = {
+			isa = PBXGroup;
+			children = (
+				95E31C112647304100106B98 /* PriceViewStyle.swift */,
+			);
+			path = Styles;
+			sourceTree = "<group>";
+		};
 		95FBE0DA2619CA6000440386 /* Profile */ = {
 			isa = PBXGroup;
 			children = (
@@ -583,6 +633,7 @@
 			files = (
 				950C36E3260FB6180081CF53 /* HapticsManager.swift in Sources */,
 				95FBE0DC2619CA7200440386 /* ProfileView.swift in Sources */,
+				95E31C1C26473B5100106B98 /* ViewType.swift in Sources */,
 				95A5186A26185AAB0002D27C /* GenericRequest.swift in Sources */,
 				95A5188626186F590002D27C /* PriceView.swift in Sources */,
 				9550444926111FC9000E0BCB /* StockRow.swift in Sources */,
@@ -595,6 +646,7 @@
 				954D7EA8260BBA6600A13C50 /* WatchlistCompany+CoreDataProperties.swift in Sources */,
 				951566E72613A2B6007C0F36 /* TradingDates.swift in Sources */,
 				955E73392623568F005652FF /* Home.swift in Sources */,
+				95E31C122647304100106B98 /* PriceViewStyle.swift in Sources */,
 				95721DA6262761E700EC527B /* CurrencyRow.swift in Sources */,
 				9562404C263C766D00C6C511 /* WatchlistCreator.swift in Sources */,
 				95672B8F25DDA54700DCBE4A /* LazyBearApp.swift in Sources */,
@@ -604,14 +656,18 @@
 				950D0E192618AA4900D17AD7 /* CompanyList.swift in Sources */,
 				952994822629CA46005F0AB0 /* SearchResponse.swift in Sources */,
 				95A07F6C26305AC6009865AA /* QuoteModel.swift in Sources */,
+				95E31C1826473A4D00106B98 /* CompanyHeader.swift in Sources */,
 				95A07F6226305A9B009865AA /* CurrencyModel.swift in Sources */,
 				9529947E2629CA3E005F0AB0 /* Search.swift in Sources */,
 				950D0E292618AEC800D17AD7 /* SearchedCompanyItem.swift in Sources */,
 				955E733C262356F3005652FF /* HomeResponse.swift in Sources */,
 				95BD2FB326341D36008B6752 /* BlurBackground.swift in Sources */,
+				95E31C16264736BE00106B98 /* DatePicker.swift in Sources */,
+				95E31C142647363800106B98 /* Chart.swift in Sources */,
 				951566EA2613A37C007C0F36 /* TradingDatesItem.swift in Sources */,
 				951490552610BD2B00BDEEB5 /* WelcomeView.swift in Sources */,
 				95D308F82624B3A400A39F77 /* CurrencyItem.swift in Sources */,
+				95E31C0D26472CA000106B98 /* CompanyView.swift in Sources */,
 				95A07F7126305AD5009865AA /* SectorPerformanceModel.swift in Sources */,
 				9550444626111EE5000E0BCB /* SectorItem.swift in Sources */,
 				954D7EA7260BBA6600A13C50 /* WatchlistCompany+CoreDataClass.swift in Sources */,
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Styles/PriceViewStyle.swift	Sun May 09 00:07:44 2021 +0200
@@ -0,0 +1,24 @@
+//
+//  PriceViewStyle.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 8/5/21.
+//
+
+import SwiftUI
+
+class PriceViewStyle {
+    var alignment: HorizontalAlignment
+    var priceFont: Font
+    var priceFontWeight: Font.Weight
+    var percentFont: Font
+    var percentFontWeight: Font.Weight
+    
+    init(alignment: HorizontalAlignment, priceFont: Font, priceFontWeight: Font.Weight, percentFont: Font, percentFontWeight: Font.Weight) {
+        self.alignment = alignment
+        self.priceFont = priceFont
+        self.priceFontWeight = priceFontWeight
+        self.percentFont = percentFont
+        self.percentFontWeight = percentFontWeight
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Company/CompanyView.swift	Sun May 09 00:07:44 2021 +0200
@@ -0,0 +1,47 @@
+//
+//  CompanyView.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 8/5/21.
+//
+
+import SwiftUI
+import StockCharts
+
+struct CompanyView: View {
+    var symbol: String
+    
+    // Date picker
+    var ranges = ["1D", "5D", "1M", "3M", "6M", "1Y", "5Y"]
+    @State private var selectedRange = "Red"
+    
+    @ObservedObject var viewSelector = ViewSelector()
+    @State private var showViewSelector = false
+    
+    var body: some View {
+        NavigationView {
+            ScrollView {
+                VStack {
+                    CompanyHeader(symbol: symbol, showViewSelector: $showViewSelector)
+                    DatePicker(ranges: ranges, selectedRange: $selectedRange)
+                    Chart()
+                }
+                .padding()
+            }
+            .navigationTitle("Apple inc")
+            .navigationBarTitleDisplayMode(.inline)
+        }
+        .actionSheet(isPresented: $showViewSelector) {
+            ActionSheet(title: Text("Change background"), message: Text("Select a new color"), buttons: [
+                .default(Text("Chart")) { viewSelector.showView(.chart) }, 
+                .cancel()
+            ])
+        }
+    }
+}
+
+struct CompanyView_Previews: PreviewProvider {
+    static var previews: some View {
+        CompanyView(symbol: "AAPL")
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Company/Helpers/Chart.swift	Sun May 09 00:07:44 2021 +0200
@@ -0,0 +1,46 @@
+//
+//  Chart.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 8/5/21.
+//
+
+import SwiftUI
+import StockCharts
+
+struct Chart: View {
+    var body: some View {
+        let priceViewStyle = PriceViewStyle(
+            alignment: .leading,
+            priceFont: .title2,
+            priceFontWeight: .semibold,
+            percentFont: .title3,
+            percentFontWeight: .semibold
+        )
+        
+        RoundedRectangle(cornerRadius: 15)
+            .foregroundColor(Color(.secondarySystemBackground))
+            .frame(height: 300)
+            .overlay(
+                VStack {
+                    HStack {
+                        PriceView(latestPrice: 120.30, changePercent: 0.03, style: priceViewStyle)
+                        Spacer()
+                    }
+                    .padding([.top, .leading, .trailing])
+                    
+                    LineChartView(data: [120.3, 120.4, 121.0, 122.0],
+                                  dates: nil,
+                                  hours: nil,
+                                  dragGesture: true)
+                        .padding(.bottom)
+                }
+            )
+    }
+}
+
+struct Chart_Previews: PreviewProvider {
+    static var previews: some View {
+        Chart()
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Company/Helpers/CompanyHeader.swift	Sun May 09 00:07:44 2021 +0200
@@ -0,0 +1,31 @@
+//
+//  CompanyHeader.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 8/5/21.
+//
+
+import SwiftUI
+
+struct CompanyHeader: View {
+    var symbol: String
+    @Binding var showViewSelector: Bool
+    
+    var body: some View {
+        HStack {
+            Text(symbol.uppercased())
+                .font(.title)
+                .fontWeight(.semibold)
+            
+            Spacer()
+            
+            Button("Views", action: { showViewSelector = true })
+        }
+    }
+}
+
+struct CompanyHeader_Previews: PreviewProvider {
+    static var previews: some View {
+        CompanyHeader(symbol: "AAPL", showViewSelector: .constant(false))
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Company/Helpers/DatePicker.swift	Sun May 09 00:07:44 2021 +0200
@@ -0,0 +1,30 @@
+//
+//  DatePicker.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 8/5/21.
+//
+
+import SwiftUI
+
+struct DatePicker: View {
+    var ranges: [String]
+    @Binding var selectedRange: String
+    
+    var body: some View {
+        VStack {
+            Picker("Please choose a range", selection: $selectedRange) {
+                ForEach(ranges, id: \.self) {
+                    Text($0)
+                }
+            }
+            .pickerStyle(SegmentedPickerStyle())
+        }
+    }
+}
+
+struct DatePicker_Previews: PreviewProvider {
+    static var previews: some View {
+        DatePicker(ranges: ["1D", "5D", "1M", "3M", "6M", "1Y", "5Y"], selectedRange: .constant("3M"))
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Company/Helpers/ViewType.swift	Sun May 09 00:07:44 2021 +0200
@@ -0,0 +1,35 @@
+//
+//  ViewType.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 8/5/21.
+//
+
+import SwiftUI
+
+
+class ViewSelector: ObservableObject {
+    @Published var showChartView = false
+    
+    enum ViewType {
+        case chart
+    }
+    
+    func showView(_ viewType: ViewType) {
+        switch viewType {
+        case .chart:
+            toogleVariables()
+        }
+    }
+    
+    private func toogleVariables() {
+        // Testing this ////
+        let mirror = Mirror(reflecting: self)
+        
+        for child in mirror.children {
+//            let value = child.value
+//            child.label = value
+        }
+        ////
+    }
+}
--- a/LazyBear/Views/Global Helpers/PriceView.swift	Sat May 08 19:23:06 2021 +0200
+++ b/LazyBear/Views/Global Helpers/PriceView.swift	Sun May 09 00:07:44 2021 +0200
@@ -10,18 +10,19 @@
 struct PriceView: View {
     var latestPrice: Double
     var changePercent: Double
-    var align: HorizontalAlignment
+    var style: PriceViewStyle
     
     var body: some View {
-        VStack(alignment: align) {
+        VStack(alignment: style.alignment) {
             Text("$\(latestPrice, specifier: "%.2f")")
                 .foregroundColor(changePercent < 0 ? .red: .green)
-                .fontWeight(.semibold)
+                .font(style.priceFont)
+                .fontWeight(style.priceFontWeight)
             
             Text("\(changePercent*100, specifier: "%.2f")%")
                 .foregroundColor(changePercent < 0 ? .red: .green)
-                .font(.callout)
-                .fontWeight(.semibold)
+                .font(style.percentFont)
+                .fontWeight(style.percentFontWeight)
         }
     }
 }
@@ -29,6 +30,16 @@
 
 struct PriceView_Previews: PreviewProvider {
     static var previews: some View {
-        PriceView(latestPrice: 120.30, changePercent: 0.03, align: .leading)
+        PriceView(
+            latestPrice: 120.30,
+            changePercent: 0.03,
+            style: PriceViewStyle(
+                alignment: .leading,
+                priceFont: .body,
+                priceFontWeight: .semibold,
+                percentFont: .callout,
+                percentFontWeight: .semibold
+            )
+        )
     }
 }
--- a/LazyBear/Views/Global Helpers/StockItem.swift	Sat May 08 19:23:06 2021 +0200
+++ b/LazyBear/Views/Global Helpers/StockItem.swift	Sun May 09 00:07:44 2021 +0200
@@ -61,7 +61,17 @@
                             .opacity(0.6)
                             .lineLimit(1)
                         
-                        PriceView(latestPrice: company.latestPrice ?? 0, changePercent: company.changePercent ?? 0, align: .leading)
+                        let priceViewStyle = PriceViewStyle(
+                            alignment: .leading,
+                            priceFont: .body,
+                            priceFontWeight: .semibold,
+                            percentFont: .callout,
+                            percentFontWeight: .semibold
+                        )
+                        
+                        PriceView(latestPrice: company.latestPrice ?? 0,
+                                  changePercent: company.changePercent ?? 0,
+                                  style: priceViewStyle)
                             .padding(.top)
                             
                     }
@@ -110,7 +120,17 @@
                         .padding(.leading)
                 }
                 
-                PriceView(latestPrice: company.latestPrice ?? 0, changePercent: company.changePercent ?? 0, align: .trailing)
+                let priceViewStyle = PriceViewStyle(
+                    alignment: .leading,
+                    priceFont: .body,
+                    priceFontWeight: .semibold,
+                    percentFont: .callout,
+                    percentFontWeight: .semibold
+                )
+                
+                PriceView(latestPrice: company.latestPrice ?? 0,
+                          changePercent: company.changePercent ?? 0,
+                          style: priceViewStyle)
                     // Center PriceView with the other rows
                     .frame(minWidth: 80, alignment: .trailing)
             }