Mercurial > public > lazybear
changeset 374:d402bfa367c2
Implementing ProfileView
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sat, 17 Apr 2021 00:01:59 +0200 |
parents | efd1e529f167 |
children | f3cb5bdea8e5 |
files | LazyBear.xcodeproj/project.pbxproj LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate LazyBear/ContentView.swift LazyBear/Persistence.swift LazyBear/Preview Content/Home/Networking/HomeDataPreview.swift LazyBear/Views/Profile/Networking/Profile.swift LazyBear/Views/Profile/Networking/ProfileResponse.swift LazyBear/Views/Profile/ProfileView.swift |
diffstat | 8 files changed, 102 insertions(+), 100 deletions(-) [+] |
line wrap: on
line diff
--- a/LazyBear.xcodeproj/project.pbxproj Fri Apr 16 19:57:59 2021 +0200 +++ b/LazyBear.xcodeproj/project.pbxproj Sat Apr 17 00:01:59 2021 +0200 @@ -52,8 +52,9 @@ 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 */; }; + 95C8C0DB262A36990082D1D9 /* Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C8C0DA262A36990082D1D9 /* Profile.swift */; }; + 95C8C0E0262A369F0082D1D9 /* ProfileResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C8C0DF262A369F0082D1D9 /* ProfileResponse.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 */; }; 95FBE0DC2619CA7200440386 /* ProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95FBE0DB2619CA7200440386 /* ProfileView.swift */; }; @@ -129,8 +130,9 @@ 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>"; }; + 95C8C0DA262A36990082D1D9 /* Profile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Profile.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>"; }; - 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>"; }; 95FBE0DB2619CA7200440386 /* ProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = "<group>"; }; @@ -310,7 +312,6 @@ 95672B9425DDA54700DCBE4A /* Preview Content */ = { isa = PBXGroup; children = ( - 95E745D72614622C00744A1E /* Home */, 95672B9525DDA54700DCBE4A /* Preview Assets.xcassets */, ); path = "Preview Content"; @@ -370,18 +371,11 @@ path = Views; sourceTree = "<group>"; }; - 95E745D72614622C00744A1E /* Home */ = { + 95C8C0D9262A31DA0082D1D9 /* Networking */ = { isa = PBXGroup; children = ( - 95E745D82614623700744A1E /* Networking */, - ); - path = Home; - sourceTree = "<group>"; - }; - 95E745D82614623700744A1E /* Networking */ = { - isa = PBXGroup; - children = ( - 95E745D92614624500744A1E /* HomeDataPreview.swift */, + 95C8C0DA262A36990082D1D9 /* Profile.swift */, + 95C8C0DF262A369F0082D1D9 /* ProfileResponse.swift */, ); path = Networking; sourceTree = "<group>"; @@ -390,6 +384,7 @@ isa = PBXGroup; children = ( 95FBE0DB2619CA7200440386 /* ProfileView.swift */, + 95C8C0D9262A31DA0082D1D9 /* Networking */, ); path = Profile; sourceTree = "<group>"; @@ -549,7 +544,6 @@ 950C36E3260FB6180081CF53 /* HapticsManager.swift in Sources */, 95FBE0DC2619CA7200440386 /* ProfileView.swift in Sources */, 95A5186A26185AAB0002D27C /* GenericRequest.swift in Sources */, - 95E745DA2614624500744A1E /* HomeDataPreview.swift in Sources */, 95A5188626186F590002D27C /* PriceView.swift in Sources */, 9550444926111FC9000E0BCB /* StockRow.swift in Sources */, 9550444326111E7A000E0BCB /* SectorRow.swift in Sources */, @@ -584,9 +578,11 @@ 9550444626111EE5000E0BCB /* SectorItem.swift in Sources */, 954D7EA7260BBA6600A13C50 /* WatchlistCompany+CoreDataClass.swift in Sources */, 95672B9B25DDA54800DCBE4A /* LazyBear.xcdatamodeld in Sources */, + 95C8C0E0262A369F0082D1D9 /* ProfileResponse.swift in Sources */, 95AD4A2D26078C1400498079 /* ContentView.swift in Sources */, 95115E982625D15900BDC0F8 /* CurrencyModel.swift in Sources */, 95721DB4262787EF00EC527B /* ExtensiveList.swift in Sources */, + 95C8C0DB262A36990082D1D9 /* Profile.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 Fri Apr 16 19:57:59 2021 +0200 +++ b/LazyBear/ContentView.swift Sat Apr 17 00:01:59 2021 +0200 @@ -24,11 +24,11 @@ Image(systemName: "magnifyingglass") Text("Search") } -// ProfileView() -// .tabItem { -// Image(systemName: "person") -// Text("Profile") -// } + ProfileView() + .tabItem { + Image(systemName: "person") + Text("Profile") + } // Text("The Last Tab") // .tabItem { // Image(systemName: "4.square.fill")
--- a/LazyBear/Persistence.swift Fri Apr 16 19:57:59 2021 +0200 +++ b/LazyBear/Persistence.swift Sat Apr 17 00:01:59 2021 +0200 @@ -16,7 +16,13 @@ for _ in 0..<10 { let entity = Entity(context: viewContext) entity.attribute = 1 - + } + + for _ in 0..<10 { + let watchlistCompany = WatchlistCompany(context: viewContext) + watchlistCompany.name = "Apple Inc" + watchlistCompany.symbol = "AAPL" + watchlistCompany.watchlist = "Technologies" } do { try viewContext.save()
--- a/LazyBear/Preview Content/Home/Networking/HomeDataPreview.swift Fri Apr 16 19:57:59 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -// -// HomeDataPreview.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 31/3/21. -// - -//import SwiftUI -// -//class HomeDataPreview: ObservableObject { -// @Published var sectorPerformance = [ -// SectorPerformanceModel(name: "Communication Services", performance: 0.043, lastUpdated: 1617177387000), -// SectorPerformanceModel(name: "Consumer Discretionary", performance: 0.043, lastUpdated: 1617177387000), -// SectorPerformanceModel(name: "Consumer Staples", performance: 0.043, lastUpdated: 1617177387000), -// SectorPerformanceModel(name: "Energy", performance: 0.043, lastUpdated: 1617177387000), -// SectorPerformanceModel(name: "Financials", performance: 0.043, lastUpdated: 1617177387000), -// SectorPerformanceModel(name: "Health Care", performance: 0.043, lastUpdated: 1617177387000), -// SectorPerformanceModel(name: "Industrials", performance: 0.043, lastUpdated: 1617177387000), -// SectorPerformanceModel(name: "Materials", performance: 0.043, lastUpdated: 1617177387000), -// SectorPerformanceModel(name: "Real Estate", performance: 0.043, lastUpdated: 1617177387000), -// SectorPerformanceModel(name: "Technology", performance: 0.043, lastUpdated: 1617177387000), -// SectorPerformanceModel(name: "Utilities", performance: 0.043, lastUpdated: 1617177387000), -// ] -// -// -// -//}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Profile/Networking/Profile.swift Sat Apr 17 00:01:59 2021 +0200 @@ -0,0 +1,30 @@ +// +// Profile.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 16/4/21. +// + +import SwiftUI + +class Profile: ObservableObject { + @Published var showView = false + @Published var data = ProfileResponse() + + var streamingRequests = 0 // Count streaming requests + + func request(_ url: String) { + genericRequest(url: url, model: ProfileResponse.self) { response in + print(response) + self.streamingRequests += 1 + + // If is the first request -> init() + if self.streamingRequests == 1 { + self.data = response + } else { + // If not, request streaming data (without intradayPrices) + self.data.quotes = response.quotes + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Profile/Networking/ProfileResponse.swift Sat Apr 17 00:01:59 2021 +0200 @@ -0,0 +1,27 @@ +// +// ProfileResponse.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 16/4/21. +// + +import SwiftUI + +struct ProfileResponse: Codable { + var intradayPrices: [String: NestedIntradayPricesModel]? // String is each company symbol + var quotes: [String: NestedQuoteModel]? // String is each company symbol + + private enum CodingKeys : String, CodingKey { + case intradayPrices = "intraday_prices" + case quotes + } +} + + +struct NestedQuoteModel: Codable { + var nestedQuoteModel: QuoteModel + + private enum CodingKeys : String, CodingKey { + case nestedQuoteModel = "quote" + } +}
--- a/LazyBear/Views/Profile/ProfileView.swift Fri Apr 16 19:57:59 2021 +0200 +++ b/LazyBear/Views/Profile/ProfileView.swift Sat Apr 17 00:01:59 2021 +0200 @@ -7,56 +7,26 @@ import SwiftUI -//struct ProfileView: View { -// @ObservedObject var profileData = ProfileData() -// @Environment(\.managedObjectContext) private var moc -// @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) -// var watchlistCompanies: FetchedResults<WatchlistCompany> -// -// var body: some View { -// NavigationView { -// List { -// Text("Hello World") -// Button("Save company", action: addCompany) -// Button("Delete company", action: removeCompany) -// Button("Request", action: {profileData.get(watchlistCompanies)}) -// Button("Print watchlist", action: {print(watchlistCompanies.map {$0.symbol})}) -// } -// .navigationTitle("My profile") -// .navigationBarTitleDisplayMode(.inline) -// } -// } -// -// // REMOVE IN PRODUCTION -// private func addCompany() { -// let watchlistCompany = WatchlistCompany(context: moc) -// watchlistCompany.symbol = "FB" -// watchlistCompany.name = "Facebook Inc" -// watchlistCompany.watchlist = "MyWatchlist" -// do { -// try moc.save() -// print("Company saved") -// } catch { -// print(error.localizedDescription) -// } -// } -// -// private func removeCompany() { -// let symbols = watchlistCompanies.map { $0.symbol } -// let index = symbols.firstIndex(of: "aapl") -// let company = watchlistCompanies[index!] -// moc.delete(company) -// do { -// try moc.save() -// print("Company deleted") -// } catch { -// // Error -// } -// } -//} -// -//struct ProfileView_Previews: PreviewProvider { -// static var previews: some View { -// ProfileView() -// } -//} +struct ProfileView: View { + @ObservedObject var profile = Profile() + + var body: some View { + NavigationView { + List { + + + } + .navigationTitle("My profile") + .navigationBarTitleDisplayMode(.inline) + .onAppear { + profile.request("https://api.lazybear.app/profile/init/symbols/aapl") + } + } + } +} + +struct ProfileView_Previews: PreviewProvider { + static var previews: some View { + ProfileView() + } +}