Mercurial > public > lazybear
changeset 349:5ccceb527178
Implementing new internal API
line wrap: on
line diff
--- a/LazyBear.xcodeproj/project.pbxproj Sun Apr 11 19:56:04 2021 +0200 +++ b/LazyBear.xcodeproj/project.pbxproj Wed Apr 14 23:08:26 2021 +0200 @@ -14,6 +14,7 @@ 950D0E302618B34600D17AD7 /* BlurBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950D0E2F2618B34600D17AD7 /* BlurBackground.swift */; }; 950D0E332618B44800D17AD7 /* HudManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950D0E322618B44800D17AD7 /* HudManager.swift */; }; 950D0E362618B61000D17AD7 /* BackgroundShadow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950D0E352618B61000D17AD7 /* BackgroundShadow.swift */; }; + 95115E982625D15900BDC0F8 /* CurrencyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95115E972625D15900BDC0F8 /* CurrencyModel.swift */; }; 951490552610BD2B00BDEEB5 /* WelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 951490542610BD2B00BDEEB5 /* WelcomeView.swift */; }; 951566E72613A2B6007C0F36 /* TradingDates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 951566E62613A2B6007C0F36 /* TradingDates.swift */; }; 951566EA2613A37C007C0F36 /* TradingDatesItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 951566E92613A37C007C0F36 /* TradingDatesItem.swift */; }; @@ -38,12 +39,17 @@ 95672B9625DDA54700DCBE4A /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 95672B9525DDA54700DCBE4A /* Preview Assets.xcassets */; }; 95672B9825DDA54700DCBE4A /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95672B9725DDA54700DCBE4A /* Persistence.swift */; }; 95672B9B25DDA54800DCBE4A /* LazyBear.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 95672B9925DDA54800DCBE4A /* LazyBear.xcdatamodeld */; }; + 95721DA6262761E700EC527B /* CurrencyRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95721DA5262761E700EC527B /* CurrencyRow.swift */; }; + 95721DB4262787EF00EC527B /* ExtensiveList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95721DB3262787EF00EC527B /* ExtensiveList.swift */; }; + 95721DB826278EC100EC527B /* CurrencyListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95721DB726278EC100EC527B /* CurrencyListItem.swift */; }; + 95721DBB26278EDE00EC527B /* StockListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95721DBA26278EDE00EC527B /* StockListItem.swift */; }; 958A735225E0170900FD7ECA /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 958A735125E0170900FD7ECA /* CloudKit.framework */; }; 95A5186A26185AAB0002D27C /* GenericRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A5186926185AAB0002D27C /* GenericRequest.swift */; }; 95A5188626186F590002D27C /* PriceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A5188526186F590002D27C /* PriceView.swift */; }; 95A7C066261639E0003E2EC1 /* SearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A7C065261639DF003E2EC1 /* SearchView.swift */; }; 95A7C0742616409D003E2EC1 /* ParseJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A7C0732616409D003E2EC1 /* ParseJSON.swift */; }; 95AD4A2D26078C1400498079 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95AD4A2C26078C1400498079 /* ContentView.swift */; }; + 95D308F82624B3A400A39F77 /* CurrencyItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95D308F72624B3A400A39F77 /* CurrencyItem.swift */; }; 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 */; }; @@ -58,6 +64,7 @@ 950D0E2F2618B34600D17AD7 /* BlurBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurBackground.swift; sourceTree = "<group>"; }; 950D0E322618B44800D17AD7 /* HudManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HudManager.swift; sourceTree = "<group>"; }; 950D0E352618B61000D17AD7 /* BackgroundShadow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundShadow.swift; sourceTree = "<group>"; }; + 95115E972625D15900BDC0F8 /* CurrencyModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyModel.swift; sourceTree = "<group>"; }; 951490542610BD2B00BDEEB5 /* WelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeView.swift; sourceTree = "<group>"; }; 951566E62613A2B6007C0F36 /* TradingDates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TradingDates.swift; sourceTree = "<group>"; }; 951566E92613A37C007C0F36 /* TradingDatesItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TradingDatesItem.swift; sourceTree = "<group>"; }; @@ -83,6 +90,10 @@ 95672B9725DDA54700DCBE4A /* Persistence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Persistence.swift; sourceTree = "<group>"; }; 95672B9A25DDA54800DCBE4A /* LazyBear.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = LazyBear.xcdatamodel; sourceTree = "<group>"; }; 95672B9C25DDA54800DCBE4A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; + 95721DA5262761E700EC527B /* CurrencyRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyRow.swift; sourceTree = "<group>"; }; + 95721DB3262787EF00EC527B /* ExtensiveList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensiveList.swift; sourceTree = "<group>"; }; + 95721DB726278EC100EC527B /* CurrencyListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyListItem.swift; sourceTree = "<group>"; }; + 95721DBA26278EDE00EC527B /* StockListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StockListItem.swift; sourceTree = "<group>"; }; 958A734E25E016FD00FD7ECA /* LazyBear.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LazyBear.entitlements; sourceTree = "<group>"; }; 958A735125E0170900FD7ECA /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; }; 95A5186926185AAB0002D27C /* GenericRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericRequest.swift; sourceTree = "<group>"; }; @@ -90,6 +101,7 @@ 95A7C065261639DF003E2EC1 /* SearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchView.swift; sourceTree = "<group>"; }; 95A7C0732616409D003E2EC1 /* ParseJSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseJSON.swift; sourceTree = "<group>"; }; 95AD4A2C26078C1400498079 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; }; + 95D308F72624B3A400A39F77 /* CurrencyItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyItem.swift; sourceTree = "<group>"; }; 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>"; }; @@ -109,13 +121,6 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 950D0E202618AD3D00D17AD7 /* Networking */ = { - isa = PBXGroup; - children = ( - ); - path = Networking; - sourceTree = "<group>"; - }; 950D0E272618AEBB00D17AD7 /* Helpers */ = { isa = PBXGroup; children = ( @@ -167,6 +172,7 @@ 955E732F262355FD005652FF /* SectorPerformanceModel.swift */, 955E733226235633005652FF /* IntradayPricesModel.swift */, 955E73352623565F005652FF /* TradingDatesModel.swift */, + 95115E972625D15900BDC0F8 /* CurrencyModel.swift */, ); path = "Global Models"; sourceTree = "<group>"; @@ -176,6 +182,7 @@ children = ( 9550443926111B2B000E0BCB /* HomeView.swift */, 951566E62613A2B6007C0F36 /* TradingDates.swift */, + 95721DB3262787EF00EC527B /* ExtensiveList.swift */, 954D7EAF260BBBD500A13C50 /* Helpers */, 95893DC72613C410003698C5 /* Networking */, ); @@ -187,7 +194,10 @@ children = ( 9550444226111E7A000E0BCB /* SectorRow.swift */, 9550444526111EE5000E0BCB /* SectorItem.swift */, + 95721DA5262761E700EC527B /* CurrencyRow.swift */, + 95D308F72624B3A400A39F77 /* CurrencyItem.swift */, 951566E92613A37C007C0F36 /* TradingDatesItem.swift */, + 95721DB726278EC100EC527B /* CurrencyListItem.swift */, ); path = Helpers; sourceTree = "<group>"; @@ -259,6 +269,7 @@ 950D0E352618B61000D17AD7 /* BackgroundShadow.swift */, 9550444826111FC9000E0BCB /* StockRectangleRow.swift */, 9550444B26111FED000E0BCB /* StockItem.swift */, + 95721DBA26278EDE00EC527B /* StockListItem.swift */, ); path = "Global Helpers"; sourceTree = "<group>"; @@ -277,7 +288,6 @@ 95A7C065261639DF003E2EC1 /* SearchView.swift */, 950D0E182618AA4900D17AD7 /* CompanyList.swift */, 950D0E272618AEBB00D17AD7 /* Helpers */, - 950D0E202618AD3D00D17AD7 /* Networking */, ); path = Search; sourceTree = "<group>"; @@ -409,6 +419,7 @@ 95A5188626186F590002D27C /* PriceView.swift in Sources */, 9550444926111FC9000E0BCB /* StockRectangleRow.swift in Sources */, 9550444326111E7A000E0BCB /* SectorRow.swift in Sources */, + 95721DB826278EC100EC527B /* CurrencyListItem.swift in Sources */, 955E7330262355FD005652FF /* SectorPerformanceModel.swift in Sources */, 950D0E302618B34600D17AD7 /* BlurBackground.swift in Sources */, 95ECCA60261216D500A67EFA /* LineView.swift in Sources */, @@ -420,6 +431,7 @@ 950D0E332618B44800D17AD7 /* HudManager.swift in Sources */, 950D0E2D2618B2B900D17AD7 /* HelpSheet.swift in Sources */, 955E73392623568F005652FF /* Home.swift in Sources */, + 95721DA6262761E700EC527B /* CurrencyRow.swift in Sources */, 95672B8F25DDA54700DCBE4A /* LazyBearApp.swift in Sources */, 95A7C066261639E0003E2EC1 /* SearchView.swift in Sources */, 95ECCA5D2612169200A67EFA /* LineShape.swift in Sources */, @@ -432,10 +444,14 @@ 955E733326235633005652FF /* IntradayPricesModel.swift in Sources */, 951566EA2613A37C007C0F36 /* TradingDatesItem.swift in Sources */, 951490552610BD2B00BDEEB5 /* WelcomeView.swift in Sources */, + 95D308F82624B3A400A39F77 /* CurrencyItem.swift in Sources */, 9550444626111EE5000E0BCB /* SectorItem.swift in Sources */, 954D7EA7260BBA6600A13C50 /* WatchlistCompany+CoreDataClass.swift in Sources */, 95672B9B25DDA54800DCBE4A /* LazyBear.xcdatamodeld in Sources */, 95AD4A2D26078C1400498079 /* ContentView.swift in Sources */, + 95115E982625D15900BDC0F8 /* CurrencyModel.swift in Sources */, + 95721DB4262787EF00EC527B /* ExtensiveList.swift in Sources */, + 95721DBB26278EDE00EC527B /* StockListItem.swift in Sources */, 955E73362623565F005652FF /* TradingDatesModel.swift in Sources */, 952045152610C7C600A76362 /* ConvertEpoch.swift in Sources */, );
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/LazyBear/ContentView.swift Sun Apr 11 19:56:04 2021 +0200 +++ b/LazyBear/ContentView.swift Wed Apr 14 23:08:26 2021 +0200 @@ -39,12 +39,14 @@ .sheet(isPresented: $showWelcome) { } - BackgroundShadow() - HelpSheet() - .offset(y: hudManager.showSearchHelper ? 0 : 700) - .animation(.easeInOut) - .padding(.horizontal) + Group { + BackgroundShadow() + HelpSheet() + .offset(y: hudManager.showSearchHelper ? 0 : 700) + } + .animation(.easeInOut) + .padding(.horizontal) } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Global Models/CurrencyModel.swift Wed Apr 14 23:08:26 2021 +0200 @@ -0,0 +1,15 @@ +// +// CurrencyModel.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 13/4/21. +// + +import SwiftUI + + +struct CurrencyModel: Codable { + var flag: String + var name: String + var rate: Double +}
--- a/LazyBear/Global Models/IntradayPricesModel.swift Sun Apr 11 19:56:04 2021 +0200 +++ b/LazyBear/Global Models/IntradayPricesModel.swift Wed Apr 14 23:08:26 2021 +0200 @@ -8,5 +8,5 @@ import SwiftUI struct IntradayPricesModel: Codable { - var marketOpen: Double? + var open: Double? }
--- a/LazyBear/Global functions/ParseJSON.swift Sun Apr 11 19:56:04 2021 +0200 +++ b/LazyBear/Global functions/ParseJSON.swift Wed Apr 14 23:08:26 2021 +0200 @@ -7,6 +7,7 @@ import Foundation + func parseJSON<T: Decodable>(_ filename: String) -> T { let data: Data
--- a/LazyBear/Views/Global Helpers/LineView.swift Sun Apr 11 19:56:04 2021 +0200 +++ b/LazyBear/Views/Global Helpers/LineView.swift Wed Apr 14 23:08:26 2021 +0200 @@ -24,8 +24,8 @@ // Normalize data func normalize(_ data: [Double]) -> [Double] { var normalData = [Double]() - let min = data.min()! - let max = data.max()! + let min = data.min() ?? 0 + let max = data.max() ?? 0 for value in data { let normal = (value - min) / (max - min)
--- a/LazyBear/Views/Global Helpers/StockItem.swift Sun Apr 11 19:56:04 2021 +0200 +++ b/LazyBear/Views/Global Helpers/StockItem.swift Wed Apr 14 23:08:26 2021 +0200 @@ -39,7 +39,7 @@ Spacer() - if let prices = intradayPrices?.compactMap { $0.marketOpen } { + if let prices = intradayPrices?.compactMap { $0.open } { LineView(data: prices) .foregroundColor(company.changePercent < 0 ? .red: .green) .padding(.vertical) @@ -56,7 +56,7 @@ static var previews: some View { StockItem( company: QuoteModel(companyName: "apple inc", symbol: "aapl", latestPrice: 130.3, changePercent: 0.03), - intradayPrices: [IntradayPricesModel(marketOpen: 130.3)] + intradayPrices: [IntradayPricesModel(open: 130.3)] ) } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Global Helpers/StockListItem.swift Wed Apr 14 23:08:26 2021 +0200 @@ -0,0 +1,20 @@ +// +// StockListItem.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 14/4/21. +// + +import SwiftUI + +struct StockListItem: View { + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + } +} + +struct StockListItem_Previews: PreviewProvider { + static var previews: some View { + StockListItem() + } +}
--- a/LazyBear/Views/Global Helpers/StockRectangleRow.swift Sun Apr 11 19:56:04 2021 +0200 +++ b/LazyBear/Views/Global Helpers/StockRectangleRow.swift Wed Apr 14 23:08:26 2021 +0200 @@ -13,12 +13,28 @@ var list: [QuoteModel] var nestedIntradayPrices: [String: NestedIntradayPricesModel]? + @State private var showExtensiveList = false + var body: some View { VStack(alignment: .leading) { - Text(adaptTitle(listName)) - .font(.title3) - .fontWeight(.semibold) - .padding([.top, .horizontal]) + HStack(alignment: .bottom) { + VStack(alignment: .leading) { + Text(adaptTitle(listName)) + .font(.title3) + .fontWeight(.semibold) + .padding([.top, .horizontal]) + + Text("Real-time quotes") + .font(.caption) + .opacity(0.5) + .padding(.horizontal) + } + + Spacer() + Button("See all", action: { self.showExtensiveList = true }) + .buttonStyle(BorderlessButtonStyle()) + .padding(.horizontal) + } ScrollView(.horizontal, showsIndicators: false) { HStack(spacing: 20) { @@ -35,12 +51,9 @@ .frame(height: 250) } .padding(.bottom) - } - - private func testPrint(_ test: Any) -> Text { - print(test) - - return Text("") + .sheet(isPresented: $showExtensiveList) { + ExtensiveList(listName: adaptTitle(listName), list: list, nestedIntradayPrices: nestedIntradayPrices, latestCurrencies: nil) + } } } @@ -58,7 +71,7 @@ StockRectangleRow( listName: "mostactive", list: [QuoteModel(companyName: "apple inc", symbol: "aapl", latestPrice: 130.3, changePercent: 0.03)], - nestedIntradayPrices: ["AAPL": NestedIntradayPricesModel(nestedIntradayPrices: [IntradayPricesModel(marketOpen: 130.3)])] + nestedIntradayPrices: ["AAPL": NestedIntradayPricesModel(nestedIntradayPrices: [IntradayPricesModel(open: 130.3)])] ) } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Home/ExtensiveList.swift Wed Apr 14 23:08:26 2021 +0200 @@ -0,0 +1,56 @@ +// +// ExtensiveList.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 14/4/21. +// + +import SwiftUI + +struct ExtensiveList: View { + // General argument + var listName: String + + // Arguments for lists + var list: [QuoteModel]? + var nestedIntradayPrices: [String: NestedIntradayPricesModel]? + + // Arguments for currencies + var latestCurrencies: [String: CurrencyModel]? + + @Environment(\.presentationMode) var extensiveListPresent + + var body: some View { + NavigationView { + VStack { + if let list = list { + List(list, id: \.self) { company in + Text(company.companyName) + } + } + + if let latestCurrencies = latestCurrencies { + List(Array(latestCurrencies.keys), id: \.self) { currencySymbol in + CurrencyListItem(currencySymbol: currencySymbol, currency: latestCurrencies[currencySymbol]!) + } + } + } + .navigationTitle(listName) + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .navigationBarTrailing) { + Button(action: { extensiveListPresent.wrappedValue.dismiss() }) { + Image(systemName: "multiply") + .imageScale(.large) + } + } + } + } + } +} + +struct ExtensiveList_Previews: PreviewProvider { + static var previews: some View { + ExtensiveList(listName: "List name") + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Home/Helpers/CurrencyItem.swift Wed Apr 14 23:08:26 2021 +0200 @@ -0,0 +1,46 @@ +// +// CurrencyItem.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 12/4/21. +// + +import SwiftUI + +struct CurrencyItem: View { + var currencySymbol: String + var currency: CurrencyModel + + var body: some View { + RoundedRectangle(cornerRadius: 8) + .foregroundColor(Color(.secondarySystemBackground)) + .frame(width: 330, height: 50) + .overlay( + HStack { + Color("default") + .frame(width: 40) + .overlay( + Text(currency.flag) + ) + VStack(alignment: .leading) { + Text(currencySymbol) + .font(.headline) + + Text(currency.name) + .font(.callout) + } + + Spacer() + Text("$ \(currency.rate, specifier: "%.2f")") + .padding(.horizontal) + } + .clipShape(RoundedRectangle(cornerRadius: 8)) + ) + } +} + +struct CurrencyItem_Previews: PreviewProvider { + static var previews: some View { + CurrencyItem(currencySymbol: "AUD", currency: CurrencyModel(flag: "🇺🇸", name: "Australian dollar", rate: 1.3116)) + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Home/Helpers/CurrencyListItem.swift Wed Apr 14 23:08:26 2021 +0200 @@ -0,0 +1,38 @@ +// +// CurrencyListItem.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 14/4/21. +// + +import SwiftUI + +struct CurrencyListItem: View { + var currencySymbol: String + var currency: CurrencyModel + + var body: some View { + HStack { + Text(currency.flag) + .padding(.trailing) + + VStack(alignment: .leading) { + Text(currencySymbol) + .font(.headline) + + Text(currency.name) + .font(.callout) + } + + Spacer() + Text("$ \(currency.rate, specifier: "%.2f")") + .padding(.horizontal) + } + } +} + +struct CurrencyRowItem_Previews: PreviewProvider { + static var previews: some View { + CurrencyListItem(currencySymbol: "AUD", currency: CurrencyModel(flag: "🇺🇸", name: "Australian dollar", rate: 1.3116)) + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Home/Helpers/CurrencyRow.swift Wed Apr 14 23:08:26 2021 +0200 @@ -0,0 +1,56 @@ +// +// CurrencyRow.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 14/4/21. +// + +import SwiftUI +import WaterfallGrid + +struct CurrencyRow: View { + var latestCurrencies: [String: CurrencyModel] + + @State private var showExtensiveList = false + + var body: some View { + VStack(alignment: .leading) { + HStack(alignment: .bottom) { + VStack(alignment: .leading) { + Text("Currencies") + .font(.title3) + .fontWeight(.semibold) + .padding([.top, .horizontal]) + + Text("Updated at 6:00 CET on every working day") + .font(.caption) + .opacity(0.5) + .padding(.horizontal) + } + + Spacer() + Button("See all", action: { self.showExtensiveList = true }) + .buttonStyle(BorderlessButtonStyle()) + .padding(.horizontal) + } + + ScrollView(.horizontal, showsIndicators: false) { + HStack(spacing: 20) { + ForEach(Array(latestCurrencies.keys), id: \.self) { currencySymbol in + CurrencyItem(currencySymbol: currencySymbol, currency: latestCurrencies[currencySymbol]!) + } + } + .padding() + } + } + .sheet(isPresented: $showExtensiveList) { + ExtensiveList(listName: "Currencies", list: nil, nestedIntradayPrices: nil, latestCurrencies: latestCurrencies) + } + } +} + +struct CurrencyRow_Previews: PreviewProvider { + static var previews: some View { + CurrencyRow(latestCurrencies: ["AUD": CurrencyModel(flag: "🇺🇸", name: "Australian dollar", rate: 1.3116)]) + } +}
--- a/LazyBear/Views/Home/Helpers/SectorRow.swift Sun Apr 11 19:56:04 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/SectorRow.swift Wed Apr 14 23:08:26 2021 +0200 @@ -17,6 +17,11 @@ .fontWeight(.semibold) .padding([.top, .horizontal]) + Text("Real-time data") + .font(.caption) + .opacity(0.5) + .padding(.horizontal) + ScrollView(.horizontal, showsIndicators: false) { HStack(spacing: 20) { ForEach(sectorPerformance, id: \.self) { sector in
--- a/LazyBear/Views/Home/HomeView.swift Sun Apr 11 19:56:04 2021 +0200 +++ b/LazyBear/Views/Home/HomeView.swift Wed Apr 14 23:08:26 2021 +0200 @@ -41,6 +41,11 @@ } .listRowInsets(EdgeInsets()) } + + if let latestCurrencies = home.data.latestCurrencies { + CurrencyRow(latestCurrencies: latestCurrencies) + .listRowInsets(EdgeInsets()) + } } .onReceive(timer) { _ in home.request("https://api.lazybear.app/home/streaming") } .onDisappear { self.timer.upstream.connect().cancel() } // Stop timer @@ -64,10 +69,11 @@ ProgressView() .onAppear { home.request("https://api.lazybear.app/home/init") + // Restart timer self.timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() } - + } } }
--- a/LazyBear/Views/Home/Networking/HomeResponse.swift Sun Apr 11 19:56:04 2021 +0200 +++ b/LazyBear/Views/Home/Networking/HomeResponse.swift Wed Apr 14 23:08:26 2021 +0200 @@ -12,12 +12,14 @@ var sectorPerformance: [SectorPerformanceModel]? var tradingDates: [TradingDatesModel]? var intradayPrices: [String: NestedIntradayPricesModel]? // String is each company symbol + var latestCurrencies: [String: CurrencyModel]? private enum CodingKeys : String, CodingKey { case lists case sectorPerformance = "sector_performance" case tradingDates = "trading_dates" case intradayPrices = "intraday_prices" + case latestCurrencies = "latest_currencies" } }
--- a/LazyBear/Views/Home/TradingDates.swift Sun Apr 11 19:56:04 2021 +0200 +++ b/LazyBear/Views/Home/TradingDates.swift Wed Apr 14 23:08:26 2021 +0200 @@ -10,6 +10,7 @@ struct TradingDates: View { var dates: [TradingDatesModel] + @Environment(\.presentationMode) var tradingDatesPresent var body: some View { NavigationView { @@ -23,6 +24,14 @@ } .navigationTitle("Holiday dates") .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .navigationBarTrailing) { + Button(action: { tradingDatesPresent.wrappedValue.dismiss() }) { + Image(systemName: "multiply") + .imageScale(.large) + } + } + } } }