# HG changeset patch # User Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> # Date 1613845771 -3600 # Node ID 8ed956c01a540d9a81fb90e3049fb4b2df651711 # Parent be5f5cabf78948a5d1703ba344d068eca96d0cfb Update UI diff -r be5f5cabf789 -r 8ed956c01a54 LazyBear.xcodeproj/project.pbxproj --- a/LazyBear.xcodeproj/project.pbxproj Sat Feb 20 19:29:08 2021 +0100 +++ b/LazyBear.xcodeproj/project.pbxproj Sat Feb 20 19:29:31 2021 +0100 @@ -16,7 +16,7 @@ 958A733A25E00C3100FD7ECA /* Company+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 958A733825E00C3100FD7ECA /* Company+CoreDataClass.swift */; }; 958A733B25E00C3100FD7ECA /* Company+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 958A733925E00C3100FD7ECA /* Company+CoreDataProperties.swift */; }; 958A734225E00C9900FD7ECA /* Watchlist.swift in Sources */ = {isa = PBXBuildFile; fileRef = 958A734125E00C9900FD7ECA /* Watchlist.swift */; }; - 958A734525E00D3D00FD7ECA /* Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = 958A734425E00D3D00FD7ECA /* Row.swift */; }; + 958A734525E00D3D00FD7ECA /* CompanyRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 958A734425E00D3D00FD7ECA /* CompanyRow.swift */; }; 958A734925E010F900FD7ECA /* Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = 958A734825E010F900FD7ECA /* Search.swift */; }; 958A734C25E010FF00FD7ECA /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 958A734B25E010FF00FD7ECA /* SearchBar.swift */; }; 958A735225E0170900FD7ECA /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 958A735125E0170900FD7ECA /* CloudKit.framework */; }; @@ -25,6 +25,10 @@ 958A735F25E0311B00FD7ECA /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 958A735E25E0311B00FD7ECA /* Settings.swift */; }; 958A736325E0320B00FD7ECA /* UserSettings+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 958A736125E0320B00FD7ECA /* UserSettings+CoreDataClass.swift */; }; 958A736425E0320B00FD7ECA /* UserSettings+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 958A736225E0320B00FD7ECA /* UserSettings+CoreDataProperties.swift */; }; + 95ABDD3125E1602D00310776 /* PriceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95ABDD3025E1602D00310776 /* PriceView.swift */; }; + 95ABDD3525E166BA00310776 /* NewsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95ABDD3425E166BA00310776 /* NewsView.swift */; }; + 95ABDD3825E167E500310776 /* NewsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95ABDD3725E167E500310776 /* NewsModel.swift */; }; + 95ABDD3C25E1717300310776 /* NewsRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95ABDD3B25E1717300310776 /* NewsRow.swift */; }; 95ACB5A925E0397B00A3CCC8 /* CompanyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95ACB5A825E0397B00A3CCC8 /* CompanyView.swift */; }; 95ACB5AC25E03A7D00A3CCC8 /* themes.json in Resources */ = {isa = PBXBuildFile; fileRef = 95ACB5AB25E03A7D00A3CCC8 /* themes.json */; }; 95ACB5AF25E03AA100A3CCC8 /* ThemeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95ACB5AE25E03AA100A3CCC8 /* ThemeModel.swift */; }; @@ -44,7 +48,7 @@ 958A733825E00C3100FD7ECA /* Company+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Company+CoreDataClass.swift"; sourceTree = ""; }; 958A733925E00C3100FD7ECA /* Company+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Company+CoreDataProperties.swift"; sourceTree = ""; }; 958A734125E00C9900FD7ECA /* Watchlist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Watchlist.swift; sourceTree = ""; }; - 958A734425E00D3D00FD7ECA /* Row.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Row.swift; sourceTree = ""; }; + 958A734425E00D3D00FD7ECA /* CompanyRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanyRow.swift; sourceTree = ""; }; 958A734825E010F900FD7ECA /* Search.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Search.swift; sourceTree = ""; }; 958A734B25E010FF00FD7ECA /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = ""; }; 958A734E25E016FD00FD7ECA /* LazyBear.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LazyBear.entitlements; sourceTree = ""; }; @@ -56,6 +60,10 @@ 958A736225E0320B00FD7ECA /* UserSettings+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserSettings+CoreDataProperties.swift"; sourceTree = ""; }; 9594152A25DDA5CA00BCE299 /* Production.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Production.xcconfig; sourceTree = ""; }; 9594152B25DDA5D800BCE299 /* Sandbox.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Sandbox.xcconfig; sourceTree = ""; }; + 95ABDD3025E1602D00310776 /* PriceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PriceView.swift; sourceTree = ""; }; + 95ABDD3425E166BA00310776 /* NewsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewsView.swift; sourceTree = ""; }; + 95ABDD3725E167E500310776 /* NewsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewsModel.swift; sourceTree = ""; }; + 95ABDD3B25E1717300310776 /* NewsRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewsRow.swift; sourceTree = ""; }; 95ACB5A825E0397B00A3CCC8 /* CompanyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanyView.swift; sourceTree = ""; }; 95ACB5AB25E03A7D00A3CCC8 /* themes.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = themes.json; sourceTree = ""; }; 95ACB5AE25E03AA100A3CCC8 /* ThemeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeModel.swift; sourceTree = ""; }; @@ -156,6 +164,7 @@ children = ( 958A735A25E0264E00FD7ECA /* CompanyModel.swift */, 95ACB5AE25E03AA100A3CCC8 /* ThemeModel.swift */, + 95ABDD3725E167E500310776 /* NewsModel.swift */, ); path = Models; sourceTree = ""; @@ -164,11 +173,14 @@ isa = PBXGroup; children = ( 958A734125E00C9900FD7ECA /* Watchlist.swift */, - 958A734425E00D3D00FD7ECA /* Row.swift */, + 958A734425E00D3D00FD7ECA /* CompanyRow.swift */, 958A734825E010F900FD7ECA /* Search.swift */, 958A734B25E010FF00FD7ECA /* SearchBar.swift */, 958A735E25E0311B00FD7ECA /* Settings.swift */, + 95ABDD3025E1602D00310776 /* PriceView.swift */, 95ACB5A825E0397B00A3CCC8 /* CompanyView.swift */, + 95ABDD3425E166BA00310776 /* NewsView.swift */, + 95ABDD3B25E1717300310776 /* NewsRow.swift */, ); path = UI; sourceTree = ""; @@ -256,6 +268,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 95ABDD3825E167E500310776 /* NewsModel.swift in Sources */, + 95ABDD3C25E1717300310776 /* NewsRow.swift in Sources */, 958A735725E01F9E00FD7ECA /* ReadJson.swift in Sources */, 958A734925E010F900FD7ECA /* Search.swift in Sources */, 958A735F25E0311B00FD7ECA /* Settings.swift in Sources */, @@ -268,9 +282,11 @@ 958A733B25E00C3100FD7ECA /* Company+CoreDataProperties.swift in Sources */, 95ACB5AF25E03AA100A3CCC8 /* ThemeModel.swift in Sources */, 95672B8F25DDA54700DCBE4A /* LazyBearApp.swift in Sources */, - 958A734525E00D3D00FD7ECA /* Row.swift in Sources */, + 958A734525E00D3D00FD7ECA /* CompanyRow.swift in Sources */, + 95ABDD3525E166BA00310776 /* NewsView.swift in Sources */, 95672B9B25DDA54800DCBE4A /* LazyBear.xcdatamodeld in Sources */, 958A734C25E010FF00FD7ECA /* SearchBar.swift in Sources */, + 95ABDD3125E1602D00310776 /* PriceView.swift in Sources */, 958A733A25E00C3100FD7ECA /* Company+CoreDataClass.swift in Sources */, 95ACB5A925E0397B00A3CCC8 /* CompanyView.swift in Sources */, 958A734225E00C9900FD7ECA /* Watchlist.swift in Sources */, diff -r be5f5cabf789 -r 8ed956c01a54 LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed diff -r be5f5cabf789 -r 8ed956c01a54 LazyBear/Models/CompanyModel.swift --- a/LazyBear/Models/CompanyModel.swift Sat Feb 20 19:29:08 2021 +0100 +++ b/LazyBear/Models/CompanyModel.swift Sat Feb 20 19:29:31 2021 +0100 @@ -8,13 +8,7 @@ import SwiftUI struct CompanyModel: Codable { - var symbol: String? - var cik: String? + var symbol: String var securityName: String? - var securityType: String? - var region: String? - var exchange: String? - var sector: String? - } diff -r be5f5cabf789 -r 8ed956c01a54 LazyBear/UI/CompanyRow.swift --- a/LazyBear/UI/CompanyRow.swift Sat Feb 20 19:29:08 2021 +0100 +++ b/LazyBear/UI/CompanyRow.swift Sat Feb 20 19:29:31 2021 +0100 @@ -1,5 +1,5 @@ // -// Row.swift +// CompanyRow.swift // LazyBear // // Created by Dennis Concepción Martín on 19/2/21. @@ -8,8 +8,8 @@ import SwiftUI struct CompanyRow: View { - var baseText: String - var subText: String? + var symbol: String + var name: String var lefView: AnyView? var rightView: AnyView? @@ -17,10 +17,10 @@ HStack { lefView VStack(alignment: .leading) { - Text(baseText.uppercased()) + Text(symbol.uppercased()) .fontWeight(.semibold) - Text(subText?.capitalized ?? "") + Text(name.capitalized) .lineLimit(1) } @@ -32,6 +32,6 @@ struct Row_Previews: PreviewProvider { static var previews: some View { - CompanyRow(baseText: "aapl", subText: "apple inc") + CompanyRow(symbol: "aapl", name: "apple inc") } } diff -r be5f5cabf789 -r 8ed956c01a54 LazyBear/UI/CompanyView.swift --- a/LazyBear/UI/CompanyView.swift Sat Feb 20 19:29:08 2021 +0100 +++ b/LazyBear/UI/CompanyView.swift Sat Feb 20 19:29:31 2021 +0100 @@ -8,13 +8,53 @@ import SwiftUI struct CompanyView: View { + @FetchRequest(entity: Company.entity(), sortDescriptors: []) var companies: FetchedResults + @Environment(\.managedObjectContext) private var moc + + var name: String + var symbol: String + var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + ScrollView { + PriceView(symbol: symbol) + NewsView(symbol: symbol) + } + .toolbar { + ToolbarItem(placement: .principal) { + Text("Change view") + } + + ToolbarItem(placement: .navigationBarTrailing) { + let symbols = companies.map { $0.symbol } + if !symbols.contains(symbol) { + Button(action: { add() }) { + Image(systemName: "star") + .imageScale(.large) + } + } + } + } + } + + // Add to watchlist + private func add() { + let company = Company(context: moc) + company.symbol = symbol + company.name = name + do { + try moc.save() + print("Company saved.") + } catch { + print(error.localizedDescription) + } } } struct CompanyView_Previews: PreviewProvider { static var previews: some View { - CompanyView() + NavigationView { + CompanyView(name: "apple inc", symbol: "aapl") + } + .navigationViewStyle(StackNavigationViewStyle()) } } diff -r be5f5cabf789 -r 8ed956c01a54 LazyBear/UI/PriceView.swift --- a/LazyBear/UI/PriceView.swift Sat Feb 20 19:29:08 2021 +0100 +++ b/LazyBear/UI/PriceView.swift Sat Feb 20 19:29:31 2021 +0100 @@ -8,13 +8,15 @@ import SwiftUI struct PriceView: View { + var symbol: String + var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + Text("Price View") } } struct PriceView_Previews: PreviewProvider { static var previews: some View { - PriceView() + PriceView(symbol: "aapl") } } diff -r be5f5cabf789 -r 8ed956c01a54 LazyBear/UI/Search.swift --- a/LazyBear/UI/Search.swift Sat Feb 20 19:29:08 2021 +0100 +++ b/LazyBear/UI/Search.swift Sat Feb 20 19:29:31 2021 +0100 @@ -15,7 +15,11 @@ var body: some View { NavigationView { List(companies, id: \.symbol) { company in - Row(baseText: company.symbol ?? "-", subText: company.securityName ?? "") + NavigationLink(destination: CompanyView(name: company.securityName ?? "-", symbol: company.symbol) + .navigationTitle(company.symbol) + ) { + CompanyRow(symbol: company.symbol, name: company.securityName ?? "-") + } } .navigationBarSearch(self.$company) .onChange(of: company, perform: { company in @@ -23,6 +27,8 @@ }) .navigationTitle("Search 🔍") } + // Empty list + .onDisappear { self.companies = [CompanyModel]() } } private func getUrl() -> String { diff -r be5f5cabf789 -r 8ed956c01a54 LazyBear/UI/Watchlist.swift --- a/LazyBear/UI/Watchlist.swift Sat Feb 20 19:29:08 2021 +0100 +++ b/LazyBear/UI/Watchlist.swift Sat Feb 20 19:29:31 2021 +0100 @@ -14,8 +14,10 @@ var body: some View { NavigationView { List { - ForEach(companies, id: \.cik) { company in - Row(baseText: company.symbol, subText: company.name) + ForEach(companies, id: \.self) { company in + NavigationLink(destination: CompanyView(name: company.name, symbol: company.symbol)) { + CompanyRow(symbol: company.symbol, name: company.name) + } } .onDelete(perform: removeCompany) }