changeset 241:93c8b0c12a4b

Implement view selector
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Fri, 05 Mar 2021 15:52:35 +0000
parents c6df1145a833
children bbb2a47fac02
files LazyBear.xcodeproj/project.pbxproj LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate LazyBear/UI/CompanyView.swift LazyBear/UI/InsidersView.swift LazyBear/UI/Search.swift LazyBear/UI/Watchlist.swift
diffstat 6 files changed, 61 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/LazyBear.xcodeproj/project.pbxproj	Thu Mar 04 07:54:33 2021 +0000
+++ b/LazyBear.xcodeproj/project.pbxproj	Fri Mar 05 15:52:35 2021 +0000
@@ -60,6 +60,7 @@
 		95F0460B25E970DB006A5A17 /* LanguagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F0460A25E970DB006A5A17 /* LanguagePicker.swift */; };
 		95F0461025E976B5006A5A17 /* SettingRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F0460F25E976B5006A5A17 /* SettingRow.swift */; };
 		95F0462825E98376006A5A17 /* default.png in Resources */ = {isa = PBXBuildFile; fileRef = 95F0462625E98376006A5A17 /* default.png */; };
+		95F90AB825F280190023A4B0 /* InsidersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F90AB725F280190023A4B0 /* InsidersView.swift */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
@@ -118,6 +119,7 @@
 		95F0460A25E970DB006A5A17 /* LanguagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguagePicker.swift; sourceTree = "<group>"; };
 		95F0460F25E976B5006A5A17 /* SettingRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingRow.swift; sourceTree = "<group>"; };
 		95F0462625E98376006A5A17 /* default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = default.png; sourceTree = "<group>"; };
+		95F90AB725F280190023A4B0 /* InsidersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsidersView.swift; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -246,6 +248,7 @@
 				95F0460F25E976B5006A5A17 /* SettingRow.swift */,
 				9517626225EEBD3800733235 /* IexAttribution.swift */,
 				95BFAE4A25E2AEA000A70EC3 /* HUD.swift */,
+				95F90AB725F280190023A4B0 /* InsidersView.swift */,
 			);
 			path = UI;
 			sourceTree = "<group>";
@@ -378,6 +381,7 @@
 				950B674F25E9A0AE00BF8593 /* IconModel.swift in Sources */,
 				958A733B25E00C3100FD7ECA /* Company+CoreDataProperties.swift in Sources */,
 				9517626325EEBD3800733235 /* IexAttribution.swift in Sources */,
+				95F90AB825F280190023A4B0 /* InsidersView.swift in Sources */,
 				95ACB5AF25E03AA100A3CCC8 /* ThemeModel.swift in Sources */,
 				95672B8F25DDA54700DCBE4A /* LazyBearApp.swift in Sources */,
 				9517626025EEB37E00733235 /* PriceModel.swift in Sources */,
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/LazyBear/UI/CompanyView.swift	Thu Mar 04 07:54:33 2021 +0000
+++ b/LazyBear/UI/CompanyView.swift	Fri Mar 05 15:52:35 2021 +0000
@@ -7,25 +7,44 @@
 
 import SwiftUI
 
+enum ViewType {
+    case stock, insiders
+}
+
 struct CompanyView: View {
+    var name: String
+    var symbol: String
+    
     @ObservedObject var hudManager: HUDManager
     @FetchRequest(entity: Company.entity(), sortDescriptors: []) var companies: FetchedResults<Company>
     @Environment(\.managedObjectContext) private var moc
     
-    var name: String
-    var symbol: String
+    @State private var showingAction = false
+    @State var viewState = ViewType.stock
     
     var body: some View {
         GeometryReader { geo in
             ScrollView {
-                PriceView(symbol: symbol)
-                ChartView(symbol: symbol, chartHeight: geo.size.width / 2)
-                NewsView(symbol: symbol)
+                if viewState == .stock {
+                        PriceView(symbol: symbol)
+                        ChartView(symbol: symbol, chartHeight: geo.size.width / 2)
+                        NewsView(symbol: symbol)
+                        
+                } else if viewState == .insiders {
+                    InsidersView()
+                }
             }
         }
         .toolbar {
             ToolbarItem(placement: .principal) {
-                // Here I will add the view selector (Stock news, insiders, etc)
+                Button(action: { self.showingAction = true }) {
+                    if viewState == .stock {
+                        Text("Stock")
+                    } else if viewState == .insiders {
+                        Text("Insiders")
+                    }
+                    Image(systemName: "chevron.down")
+                }
             }
             
             ToolbarItem(placement: .navigationBarTrailing) {
@@ -38,6 +57,13 @@
                 }
             }
         }
+        .actionSheet(isPresented: $showingAction) {
+            ActionSheet(title: Text("Select an option"), buttons: [
+                .default(Text("Stock & news")) { self.viewState = ViewType.stock },
+                .default(Text("Insiders")) { self.viewState = ViewType.insiders },
+                .cancel()
+                ])
+        }
     }
     
     // Add to watchlist
@@ -60,7 +86,7 @@
 struct CompanyView_Previews: PreviewProvider {
     static var previews: some View {
         NavigationView {
-            CompanyView(hudManager: HUDManager(), name: "apple inc", symbol: "aapl")
+            CompanyView(name: "apple inc", symbol: "aapl", hudManager: HUDManager())
         }
         .navigationViewStyle(StackNavigationViewStyle())
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/UI/InsidersView.swift	Fri Mar 05 15:52:35 2021 +0000
@@ -0,0 +1,22 @@
+//
+//  InsidersView.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 5/3/21.
+//
+
+import SwiftUI
+
+struct InsidersView: View {
+    var body: some View {
+        ForEach((1...50), id: \.self) { item in
+               Text("Insider view")
+       }
+    }
+}
+
+struct InsidersView_Previews: PreviewProvider {
+    static var previews: some View {
+        InsidersView()
+    }
+}
--- a/LazyBear/UI/Search.swift	Thu Mar 04 07:54:33 2021 +0000
+++ b/LazyBear/UI/Search.swift	Fri Mar 05 15:52:35 2021 +0000
@@ -19,7 +19,7 @@
             List(list.indices, id: \.self) { i in
                 let name = list[i].securityName ?? "-"
                 let symbol = list[i].symbol
-                NavigationLink(destination: CompanyView(hudManager: hudManager, name: name, symbol: symbol)
+                NavigationLink(destination: CompanyView(name: name, symbol: symbol, hudManager: hudManager)
                                 .navigationTitle(symbol)
                 ) {
                     CompanyRow(symbol: symbol, name: name, rowNumber: i % 5)
--- a/LazyBear/UI/Watchlist.swift	Thu Mar 04 07:54:33 2021 +0000
+++ b/LazyBear/UI/Watchlist.swift	Fri Mar 05 15:52:35 2021 +0000
@@ -19,7 +19,7 @@
                 ForEach(companies.indices, id: \.self) { i in
                     let name = companies[i].name
                     let symbol = companies[i].symbol
-                    NavigationLink(destination: CompanyView(hudManager: hudManager, name: name, symbol: symbol)
+                    NavigationLink(destination: CompanyView(name: name, symbol: symbol, hudManager: hudManager)
                                     .navigationTitle(symbol)
                     ) {
                         CompanyRow(symbol: symbol, name: name, rowNumber: i % 5)