# HG changeset patch # User Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> # Date 1623235757 -7200 # Node ID 34f9e408b861852d39bbaab85b97a16c9f5aeb26 # Parent b93172662988976369d0e323bfd698cb287a5c8d Minor UI Updates and tests diff -r b93172662988 -r 34f9e408b861 LazyBear.xcodeproj/project.pbxproj --- a/LazyBear.xcodeproj/project.pbxproj Wed Jun 09 10:57:25 2021 +0200 +++ b/LazyBear.xcodeproj/project.pbxproj Wed Jun 09 12:49:17 2021 +0200 @@ -72,6 +72,7 @@ 95BB05B22670B8C3005A2029 /* KeyStatsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BB05B12670B8C3005A2029 /* KeyStatsModel.swift */; }; 95BD2FAE26341BD1008B6752 /* TextfieldAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BD2FAD26341BD1008B6752 /* TextfieldAlert.swift */; }; 95BD2FB326341D36008B6752 /* BlurBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BD2FB226341D36008B6752 /* BlurBackground.swift */; }; + 95C6CCD92670C3BB00E60517 /* StatsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C6CCD82670C3BB00E60517 /* StatsView.swift */; }; 95C8C0E0262A369F0082D1D9 /* ProfileResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C8C0DF262A369F0082D1D9 /* ProfileResponse.swift */; }; 95CCFB56266E7A0F00C384A1 /* InsiderTransactionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95CCFB55266E7A0F00C384A1 /* InsiderTransactionModel.swift */; }; 95CCFB58266E7F4F00C384A1 /* InsiderList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95CCFB57266E7F4F00C384A1 /* InsiderList.swift */; }; @@ -176,6 +177,7 @@ 95BB05B12670B8C3005A2029 /* KeyStatsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyStatsModel.swift; sourceTree = ""; }; 95BD2FAD26341BD1008B6752 /* TextfieldAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextfieldAlert.swift; sourceTree = ""; }; 95BD2FB226341D36008B6752 /* BlurBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurBackground.swift; sourceTree = ""; }; + 95C6CCD82670C3BB00E60517 /* StatsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsView.swift; sourceTree = ""; }; 95C8C0DF262A369F0082D1D9 /* ProfileResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileResponse.swift; sourceTree = ""; }; 95CCFB55266E7A0F00C384A1 /* InsiderTransactionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsiderTransactionModel.swift; sourceTree = ""; }; 95CCFB57266E7F4F00C384A1 /* InsiderList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsiderList.swift; sourceTree = ""; }; @@ -498,6 +500,7 @@ 950857D0266BE54B005357BA /* InsiderRow.swift */, 95CCFB5B266E842000C384A1 /* TransactionList.swift */, 95CCFB59266E841B00C384A1 /* TransactionRow.swift */, + 95C6CCD82670C3BB00E60517 /* StatsView.swift */, ); path = Helpers; sourceTree = ""; @@ -716,6 +719,7 @@ 95CCFB58266E7F4F00C384A1 /* InsiderList.swift in Sources */, 9562404C263C766D00C6C511 /* WatchlistCreator.swift in Sources */, 95BB05B22670B8C3005A2029 /* KeyStatsModel.swift in Sources */, + 95C6CCD92670C3BB00E60517 /* StatsView.swift in Sources */, 95672B8F25DDA54700DCBE4A /* LazyBearApp.swift in Sources */, 95A7C066261639E0003E2EC1 /* SearchView.swift in Sources */, 9550444C26111FED000E0BCB /* StockItem.swift in Sources */, diff -r b93172662988 -r 34f9e408b861 LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed diff -r b93172662988 -r 34f9e408b861 LazyBear/Views/Company/Chart.swift --- a/LazyBear/Views/Company/Chart.swift Wed Jun 09 10:57:25 2021 +0200 +++ b/LazyBear/Views/Company/Chart.swift Wed Jun 09 12:49:17 2021 +0200 @@ -19,6 +19,8 @@ // Set recurrent price request @State private var timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() + @State private var showingStatistics = false + var body: some View { if company.showChartView { VStack { @@ -43,13 +45,17 @@ orientation: .HStack, priceFont: .title3, priceFontWeight: .semibold, - percentFont: .headline, - percentFontWeight: .medium, + percentFont: .body, + percentFontWeight: .semibold, showBackground: true ) PriceView(latestPrice: latestPrice, changePercent: changePercent, style: priceViewStyle) } Spacer() + + if let _ = company.chartData.keyStats { + Button("See stats", action: { showingStatistics = true }) + } } .padding([.top, .leading, .trailing]) @@ -73,6 +79,9 @@ .padding(.top) } } + .sheet(isPresented: $showingStatistics) { + StatsView(keyStats: company.chartData.keyStats!) + } .onAppear { self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } // Start timer .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer .onReceive(timer) { _ in diff -r b93172662988 -r 34f9e408b861 LazyBear/Views/Company/Helpers/StatsView.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Company/Helpers/StatsView.swift Wed Jun 09 12:49:17 2021 +0200 @@ -0,0 +1,91 @@ +// +// StatsView.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 9/6/21. +// + +import SwiftUI + +struct StatsView: View { + var keyStats: KeyStatsModel + @Environment(\.presentationMode) private var presentationStatsView + + var body: some View { + NavigationView { + Form { + let mirror = Mirror(reflecting: keyStats) + ForEach(Array(mirror.children), id: \.label) { child in + HStack { + let label = String(child.label!) + + Text("\(label)".capitalized) + .fontWeight(.semibold) + + // Unwrap optional value + if let doubleValue = child.value as? Double { + Text("\(doubleValue)") + } else if let intValue = child.value as? Int { + Text("\(intValue)") + } else if let stringValue = child.value as? String { + Text("\(stringValue)") + } else { + Text("NaN") + } + } + } + } + .navigationTitle("Key statistics") + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .navigationBarLeading) { + Button(action: { presentationStatsView.wrappedValue.dismiss() }) { + Image(systemName: "multiply") + .imageScale(.large) + } + } + } + } + } +} + + +struct StatsView_Previews: PreviewProvider { + static var previews: some View { + StatsView(keyStats: + KeyStatsModel(avg10Volume: 123, + avg30Volume: 123, + beta: 123.12, + companyName: "Apple inc", + day200MovingAvg: 123.4, + day30ChangePercent: 123.4, + day50MovingAvg: 123.4, + day5ChangePercent: 123.4, + dividendYield: 123.4, + employees: 123, + exDividendDate: "2020-01-01", + float: 123, + marketcap: 123, + maxChangePercent: 123.4, + month1ChangePercent: 123.4, + month3ChangePercent: 123.4, + month6ChangePercent: 123.4, + nextDividendDate: "2020-01-01", + nextEarningsDate: "2020-01-01", + peRatio: 123.4, + sharesOutstanding: 123, + ttmDividendRate: 123.4, + ttmEPS: 123.4, + week52Change: 123.4, + week52High: 123.4, + week52HighSplitAdjustOnly: 123.4, + week52Low: 123.4, + week52LowSplitAdjustOnly: 123.4, + year1ChangePercent: 123.4, + year2ChangePercent: 123.4, + year5ChangePercent: 123.4, + ytdChangePercent: 123.4 + ) + ) + } +} diff -r b93172662988 -r 34f9e408b861 LazyBear/Views/Company/Helpers/TransactionRow.swift --- a/LazyBear/Views/Company/Helpers/TransactionRow.swift Wed Jun 09 10:57:25 2021 +0200 +++ b/LazyBear/Views/Company/Helpers/TransactionRow.swift Wed Jun 09 12:49:17 2021 +0200 @@ -45,6 +45,7 @@ Text("\(transactionShares)") .foregroundColor(transactionShares < 0 ? Color(.systemRed): Color(.systemGreen)) } + .padding(.leading) } } .padding() diff -r b93172662988 -r 34f9e408b861 LazyBear/Views/Company/Networking/Company.swift --- a/LazyBear/Views/Company/Networking/Company.swift Wed Jun 09 10:57:25 2021 +0200 +++ b/LazyBear/Views/Company/Networking/Company.swift Wed Jun 09 12:49:17 2021 +0200 @@ -22,7 +22,6 @@ switch requestType { case .initial: self.chartData = response - print(response) case .refresh: self.chartData.historicalPrices = response.historicalPrices case .streaming: