# HG changeset patch # User Dennis Concepción Martín # Date 1624796309 -7200 # Node ID 37c13ebda3811e0b000a1e6a386324c7ba8322d2 # Parent bb69f9d1d20f4da4b859e5b64291f52c51d0e452 Improve hierarchy and minor bugs fixed diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear.xcodeproj/project.pbxproj --- a/LazyBear.xcodeproj/project.pbxproj Sat Jun 26 18:45:31 2021 +0200 +++ b/LazyBear.xcodeproj/project.pbxproj Sun Jun 27 14:18:29 2021 +0200 @@ -17,7 +17,6 @@ 950B6F3D267643460029E447 /* Purchases in Frameworks */ = {isa = PBXBuildFile; productRef = 950B6F3C267643460029E447 /* Purchases */; }; 950B6F3F267643640029E447 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 950B6F3E267643640029E447 /* StoreKit.framework */; }; 950B6F422676454A0029E447 /* RevenueCatTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950B6F412676454A0029E447 /* RevenueCatTest.swift */; }; - 950C36E3260FB6180081CF53 /* HapticsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950C36E2260FB6180081CF53 /* HapticsManager.swift */; }; 950C57132629EF9100F234FE /* LazyBearTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950C57122629EF9100F234FE /* LazyBearTests.swift */; }; 950C57232629EFC200F234FE /* LazyBearUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950C57222629EFC200F234FE /* LazyBearUITests.swift */; }; 950D0E192618AA4900D17AD7 /* CompanyList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950D0E182618AA4900D17AD7 /* CompanyList.swift */; }; @@ -35,7 +34,6 @@ 951566EA2613A37C007C0F36 /* TradingDatesItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 951566E92613A37C007C0F36 /* TradingDatesItem.swift */; }; 9519BE06267E5EC3009C6015 /* ProfileStockRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9519BE05267E5EC3009C6015 /* ProfileStockRow.swift */; }; 952045152610C7C600A76362 /* ConvertEpoch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 952045142610C7C600A76362 /* ConvertEpoch.swift */; }; - 9523ED422615BDB2006D3D6F /* phrases.json in Resources */ = {isa = PBXBuildFile; fileRef = 9523ED412615BDB2006D3D6F /* phrases.json */; }; 952457D8267E339C00D5BBCB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 952457D7267E339C00D5BBCB /* Assets.xcassets */; }; 952457DF267E339C00D5BBCB /* LazyBearWatchOS Extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 952457DE267E339C00D5BBCB /* LazyBearWatchOS Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 952457E4267E339C00D5BBCB /* LazyBearApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 952457E3267E339C00D5BBCB /* LazyBearApp.swift */; }; @@ -52,6 +50,9 @@ 952994822629CA46005F0AB0 /* SearchResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 952994812629CA46005F0AB0 /* SearchResponse.swift */; }; 952FC0B8267C97BA001406B1 /* WatchlistSheetRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 952FC0B7267C97BA001406B1 /* WatchlistSheetRow.swift */; }; 952FC0BA267C9A24001406B1 /* RenameListSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 952FC0B9267C9A24001406B1 /* RenameListSheet.swift */; }; + 953C96DE2688925E0096734C /* HapticsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 953C96DD2688925E0096734C /* HapticsManager.swift */; }; + 953C96E0268898430096734C /* DefaultCompanies.json in Resources */ = {isa = PBXBuildFile; fileRef = 953C96DF268898430096734C /* DefaultCompanies.json */; }; + 953C96E2268898DC0096734C /* DefaultCompanyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 953C96E1268898DC0096734C /* DefaultCompanyModel.swift */; }; 9547482026821F7700D6A966 /* InsiderTransactionsHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9547481F26821F7700D6A966 /* InsiderTransactionsHelper.swift */; }; 9547482226821F8800D6A966 /* InsiderTransactionsRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9547482126821F8800D6A966 /* InsiderTransactionsRow.swift */; }; 9547482426821F9400D6A966 /* InsiderTransactionsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9547482326821F9400D6A966 /* InsiderTransactionsList.swift */; }; @@ -202,7 +203,6 @@ 9502BC00267F8771003B0A59 /* KeyStatsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyStatsList.swift; sourceTree = ""; }; 950B6F3E267643640029E447 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; 950B6F412676454A0029E447 /* RevenueCatTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RevenueCatTest.swift; sourceTree = ""; }; - 950C36E2260FB6180081CF53 /* HapticsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HapticsManager.swift; sourceTree = ""; }; 950C57102629EF9100F234FE /* LazyBearTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LazyBearTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 950C57122629EF9100F234FE /* LazyBearTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazyBearTests.swift; sourceTree = ""; }; 950C57142629EF9100F234FE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -225,7 +225,6 @@ 951566E92613A37C007C0F36 /* TradingDatesItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TradingDatesItem.swift; sourceTree = ""; }; 9519BE05267E5EC3009C6015 /* ProfileStockRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileStockRow.swift; sourceTree = ""; }; 952045142610C7C600A76362 /* ConvertEpoch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConvertEpoch.swift; sourceTree = ""; }; - 9523ED412615BDB2006D3D6F /* phrases.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = phrases.json; sourceTree = ""; }; 952457D5267E339B00D5BBCB /* LazyBearWatchOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LazyBearWatchOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; 952457D7267E339C00D5BBCB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 952457D9267E339C00D5BBCB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -249,6 +248,9 @@ 952994812629CA46005F0AB0 /* SearchResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResponse.swift; sourceTree = ""; }; 952FC0B7267C97BA001406B1 /* WatchlistSheetRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchlistSheetRow.swift; sourceTree = ""; }; 952FC0B9267C9A24001406B1 /* RenameListSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RenameListSheet.swift; sourceTree = ""; }; + 953C96DD2688925E0096734C /* HapticsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HapticsManager.swift; sourceTree = ""; }; + 953C96DF268898430096734C /* DefaultCompanies.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = DefaultCompanies.json; sourceTree = ""; }; + 953C96E1268898DC0096734C /* DefaultCompanyModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultCompanyModel.swift; sourceTree = ""; }; 9547481F26821F7700D6A966 /* InsiderTransactionsHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsiderTransactionsHelper.swift; sourceTree = ""; }; 9547482126821F8800D6A966 /* InsiderTransactionsRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsiderTransactionsRow.swift; sourceTree = ""; }; 9547482326821F9400D6A966 /* InsiderTransactionsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsiderTransactionsList.swift; sourceTree = ""; }; @@ -422,8 +424,8 @@ 9523ED402615BD93006D3D6F /* Resources */ = { isa = PBXGroup; children = ( - 9523ED412615BDB2006D3D6F /* phrases.json */, 95AF0FF62671320F0049C4AB /* DisplayWords.json */, + 953C96DF268898430096734C /* DefaultCompanies.json */, ); path = Resources; sourceTree = ""; @@ -505,6 +507,7 @@ 95AF0FF82671342E0049C4AB /* DisplayWordsModel.swift */, 95E8BAA22656D86E0016AE72 /* RequestType.swift */, 95C22F3E26776F010014C98A /* CompanyModel.swift */, + 953C96E1268898DC0096734C /* DefaultCompanyModel.swift */, ); path = "Global Models"; sourceTree = ""; @@ -580,7 +583,7 @@ 95672B8E25DDA54700DCBE4A /* LazyBearApp.swift */, 95AD4A2C26078C1400498079 /* ContentView.swift */, 95672B9725DDA54700DCBE4A /* Persistence.swift */, - 950C36E2260FB6180081CF53 /* HapticsManager.swift */, + 953C96DD2688925E0096734C /* HapticsManager.swift */, 95B1874925DDAC4D0068A364 /* Views */, 952045132610C7A200A76362 /* Global functions */, 954D7E9D260BBA5200A13C50 /* Global Models */, @@ -669,13 +672,13 @@ isa = PBXGroup; children = ( 9519BE05267E5EC3009C6015 /* ProfileStockRow.swift */, + 95131D4A267A15490055C6DE /* WatchlistSheet.swift */, + 952FC0B7267C97BA001406B1 /* WatchlistSheetRow.swift */, 9562404B263C766D00C6C511 /* WatchlistCreator.swift */, 9562404D263C7D8800C6C511 /* WatchlistCreatorClass.swift */, 95A4B92F263E9F530056F036 /* WatchlistCreatorList.swift */, 95A4B934263EA31C0056F036 /* WatchlistCreatorSearchBar.swift */, 95A4B936263EA5C20056F036 /* WatchlistCreatorRow.swift */, - 95131D4A267A15490055C6DE /* WatchlistSheet.swift */, - 952FC0B7267C97BA001406B1 /* WatchlistSheetRow.swift */, 952FC0B9267C9A24001406B1 /* RenameListSheet.swift */, ); path = Helpers; @@ -997,10 +1000,10 @@ buildActionMask = 2147483647; files = ( 95672B9625DDA54700DCBE4A /* Preview Assets.xcassets in Resources */, - 9523ED422615BDB2006D3D6F /* phrases.json in Resources */, 95AF0FF72671320F0049C4AB /* DisplayWords.json in Resources */, 95E2DBF82673752F007FCCB4 /* LaunchScreen.storyboard in Resources */, 95672B9325DDA54700DCBE4A /* Assets.xcassets in Resources */, + 953C96E0268898430096734C /* DefaultCompanies.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1069,7 +1072,6 @@ 95E4A2D92680931300A6FEB9 /* NewsRow.swift in Sources */, 95131D46267A03020055C6DE /* WatchlistCompany+CoreDataProperties.swift in Sources */, 9576BFEF26810719002BCAC6 /* InsiderRosterRow.swift in Sources */, - 950C36E3260FB6180081CF53 /* HapticsManager.swift in Sources */, 95FBE0DC2619CA7200440386 /* ProfileView.swift in Sources */, 95131D4B267A15490055C6DE /* WatchlistSheet.swift in Sources */, 9550444926111FC9000E0BCB /* StockRow.swift in Sources */, @@ -1112,6 +1114,7 @@ 9547482026821F7700D6A966 /* InsiderTransactionsHelper.swift in Sources */, 951490552610BD2B00BDEEB5 /* WelcomeView.swift in Sources */, 95D308F82624B3A400A39F77 /* CurrencyItem.swift in Sources */, + 953C96E2268898DC0096734C /* DefaultCompanyModel.swift in Sources */, 95131D47267A03020055C6DE /* WatchlistCompany+CoreDataClass.swift in Sources */, 9502BBF7267F5974003B0A59 /* CompanyResponse.swift in Sources */, 95A07F7126305AD5009865AA /* SectorPerformanceModel.swift in Sources */, @@ -1140,6 +1143,7 @@ 952FC0BA267C9A24001406B1 /* RenameListSheet.swift in Sources */, 95E4A2E02680A70000A6FEB9 /* NewsList.swift in Sources */, 95CCFB60266E864C00C384A1 /* ConvertStringToDate.swift in Sources */, + 953C96DE2688925E0096734C /* HapticsManager.swift in Sources */, 9502BBF9267F59A0003B0A59 /* Company.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear/ContentView.swift --- a/LazyBear/ContentView.swift Sat Jun 26 18:45:31 2021 +0200 +++ b/LazyBear/ContentView.swift Sun Jun 27 14:18:29 2021 +0200 @@ -6,15 +6,14 @@ // import SwiftUI +import CoreHaptics struct ContentView: View { @State private var showWelcome = false @State var selectedTab: Tab = .home - @StateObject var hapticsManager = HapticsManager() @Environment(\.managedObjectContext) private var moc - @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) - var watchlistCompanies: FetchedResults + @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) var watchlistCompanies: FetchedResults var body: some View { TabView(selection: $selectedTab) { @@ -37,40 +36,28 @@ } .tag(Tab.profile) } - .onAppear { -// isAppAlreadyLaunchedOnce() - hapticsManager.prepareHaptics() - createDefaultWatchlist() - } + .onAppear(perform: onAppear) .sheet(isPresented: $showWelcome) { } } /* - Check if app is already launched one -> If not show welcome + 1) Create default watchlist if it doesn't exits + 2) Show WelcomeView if is the first time that the app is opened + 3) Prepare haptics */ -// private func isAppAlreadyLaunchedOnce() { -// let defaults = UserDefaults.standard -// -// if let isAppAlreadyLaunchedOnce = defaults.string(forKey: "IsAppAlreadyLaunchedOnce") { -// print("App already launched : \(isAppAlreadyLaunchedOnce)") -// self.showWelcome = true -// } -// } - - /* - Check if exist default watchlist (Core Data) -> if not, create it - */ - private func createDefaultWatchlist() { - let defaultCompanies = [("TSLA", "Tesla Inc"), ("AAPL", "Apple Inc"), ("MSFT", "Microsoft Corporation"), ("GS", "Goldman Sachs Group, Inc.")] + private func onAppear() { + // Create watchlist if watchlistCompanies.isEmpty { - for tupleCompany in defaultCompanies { + let defaultCompanies: [DefaultCompanyModel] = parseJSON("DefaultCompanies.json") + for defaultCompany in defaultCompanies { let watchlistCompany = WatchlistCompany(context: moc) - watchlistCompany.symbol = tupleCompany.0 - watchlistCompany.name = tupleCompany.1 + watchlistCompany.name = defaultCompany.name + watchlistCompany.symbol = defaultCompany.symbol watchlistCompany.watchlistName = "Default watchlist" } + do { try moc.save() print("Default watchlist created") @@ -78,6 +65,17 @@ print(error.localizedDescription) } } + + // Show WelcomeView if is the first time that the app is opened +// let defaults = UserDefaults.standard +// +// if let isAppAlreadyLaunchedOnce = defaults.string(forKey: "IsAppAlreadyLaunchedOnce") { +// print("App already launched : \(isAppAlreadyLaunchedOnce)") +// self.showWelcome = true +// } + + // Prepare haptics +// hapticsManager.prepareHaptics() } } extension ContentView { diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear/Global Models/DefaultCompanyModel.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Global Models/DefaultCompanyModel.swift Sun Jun 27 14:18:29 2021 +0200 @@ -0,0 +1,13 @@ +// +// DefaultCompanyModel.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 27/06/2021. +// + +import SwiftUI + +struct DefaultCompanyModel: Codable { + var symbol: String + var name: String +} diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear/HapticsManager.swift --- a/LazyBear/HapticsManager.swift Sat Jun 26 18:45:31 2021 +0200 +++ b/LazyBear/HapticsManager.swift Sun Jun 27 14:18:29 2021 +0200 @@ -2,7 +2,7 @@ // HapticsManager.swift // LazyBear // -// Created by Dennis Concepción Martín on 27/3/21. +// Created by Dennis Concepción Martín on 27/06/2021. // import SwiftUI diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear/Resources/DefaultCompanies.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Resources/DefaultCompanies.json Sun Jun 27 14:18:29 2021 +0200 @@ -0,0 +1,47 @@ +[ + { + "symbol": "AAPL", + "name": "Apple Inc" + }, + { + "symbol": "AMZN", + "name": "Amazon.com Inc." + }, + { + "symbol": "WMT", + "name": "Walmart Inc" + }, + { + "symbol": "CVS", + "name": "CVS Health Corp" + }, + { + "symbol": "UNH", + "name": "Unitedhealth Group Inc" + }, + { + "symbol": "BRK.B", + "name": "Berkshire Hathaway Inc." + }, + { + "symbol": "MCK", + "name": "Mckesson Corporation" + }, + { + "symbol": "ABC", + "name": "Amerisource Bergen Corp." + }, + { + "symbol": "GOOG", + "name": "Alphabet Inc" + }, + { + "symbol": "XOM", + "name": "Exxon Mobil Corp." + }, + { + "symbol": "COST", + "name": "Costco Wholesale Corp" + } +] + diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear/Resources/phrases.json --- a/LazyBear/Resources/phrases.json Sat Jun 26 18:45:31 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -[ - { - "funny": [ - "Tomorrow is often the busiest day of the week", - "They shorted my stock, I shortened their lives", - "The stock market is still les volatile than most of my romantic relationships", - "Dear diary, today the stock market did not crash", - "If you want to trade in derivates, god bless you", - "When the market crash, just take the absolute value", - "I was losing money before the stock market crashed", - "The Lazybear of Wall Street", - "Can't lose your savings if you have no savings", - "Stonks", - "So you dont buy more when a stock goes down?", - "Hey the stock market is up AAAA It's down", - "Top 3 richest people: Musk, Bezos, not you", - "Oh no... my stock did what?", - "Are you a Redditor?", - "No I don't know what happened", - "Hey, Do you want some quantitative easing?", - "Money printer go Brrr", - "You have two cows. The State takes both of them and gives you the milk" - ] - } -] diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear/Views/Home/Helpers/CurrencyRow.swift --- a/LazyBear/Views/Home/Helpers/CurrencyRow.swift Sat Jun 26 18:45:31 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/CurrencyRow.swift Sun Jun 27 14:18:29 2021 +0200 @@ -9,8 +9,6 @@ struct CurrencyRow: View { var latestCurrencies: [CurrencyModel] - - @State private var showExtensiveList = false var body: some View { VStack(alignment: .leading) { @@ -28,8 +26,14 @@ } Spacer() - Button("See all", action: { self.showExtensiveList = true }) - .buttonStyle(BorderlessButtonStyle()) + NavigationLink(destination: CurrencySheet(latestCurrencies: latestCurrencies) + .navigationTitle("Currencies") + ) { + HStack { + Text("See all") + Image(systemName: "chevron.right") + } + } .padding(.horizontal) } @@ -42,9 +46,6 @@ .padding() } } - .sheet(isPresented: $showExtensiveList) { - CurrencySheet(latestCurrencies: latestCurrencies) - } } } diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear/Views/Home/Helpers/StockRow.swift --- a/LazyBear/Views/Home/Helpers/StockRow.swift Sat Jun 26 18:45:31 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/StockRow.swift Sun Jun 27 14:18:29 2021 +0200 @@ -11,9 +11,6 @@ struct StockRow: View { var listName: String var companies: [CompanyModel] - - @State private var showList = false - @Environment(\.managedObjectContext) private var moc var body: some View { VStack(alignment: .leading) { @@ -31,9 +28,15 @@ } Spacer() - Button("See all", action: { showList = true }) - .buttonStyle(BorderlessButtonStyle()) - .padding(.horizontal) + NavigationLink(destination: StockSheet(listName: adaptListTitle(listName), companies: companies) + .navigationTitle(adaptListTitle(listName)) + ) { + HStack { + Text("See all") + Image(systemName: "chevron.right") + } + } + .padding(.horizontal) } ScrollView(.horizontal, showsIndicators: false) { @@ -51,10 +54,6 @@ } .frame(height: 250) } - .padding(.bottom) - .sheet(isPresented: $showList) { - StockSheet(listName: adaptListTitle(listName), companies: companies) - } } /* diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear/Views/Home/Helpers/StockSheet.swift --- a/LazyBear/Views/Home/Helpers/StockSheet.swift Sat Jun 26 18:45:31 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/StockSheet.swift Sun Jun 27 14:18:29 2021 +0200 @@ -11,26 +11,14 @@ var listName: String var companies: [CompanyModel] - @Environment(\.presentationMode) private var stockSheetPresentation - var body: some View { - NavigationView { - VStack { - List(companies, id: \.self) { company in - NavigationLink(destination: - CompanyView(symbol: company.symbol, name: company.companyName) - .navigationTitle(company.symbol.uppercased()) - ) { - StockSheetRow(company: company) - } - } - } - .navigationTitle(listName) - .toolbar { - ToolbarItem(placement: .navigationBarLeading) { - Button(action: {stockSheetPresentation.wrappedValue.dismiss()}) { - Image(systemName: "multiply") - } + VStack { + List(companies, id: \.self) { company in + NavigationLink(destination: + CompanyView(symbol: company.symbol, name: company.companyName) + .navigationTitle(company.symbol.uppercased()) + ) { + StockSheetRow(company: company) } } } diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear/Views/Home/HomeView.swift --- a/LazyBear/Views/Home/HomeView.swift Sat Jun 26 18:45:31 2021 +0200 +++ b/LazyBear/Views/Home/HomeView.swift Sun Jun 27 14:18:29 2021 +0200 @@ -51,7 +51,7 @@ .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button(action: { showTradingDates = true }) { - Image(systemName: "calendar.badge.clock") + Image(systemName: "clock") } } } @@ -66,11 +66,7 @@ } } else { ProgressView() - .onAppear { - home.request("https://api.lazybear.app/home/type=initial", .initial) - - } - + .onAppear { home.request("https://api.lazybear.app/home/type=initial", .initial) } } } } diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear/Views/Home/Networking/Home.swift --- a/LazyBear/Views/Home/Networking/Home.swift Sat Jun 26 18:45:31 2021 +0200 +++ b/LazyBear/Views/Home/Networking/Home.swift Sun Jun 27 14:18:29 2021 +0200 @@ -9,8 +9,9 @@ import Alamofire class Home: ObservableObject { + @Published var data = HomeResponse() @Published var showView = false - @Published var data = HomeResponse() + @Published var triggerHaptic = false func request(_ url: String, _ requestType: RequestType) { AF.request(url).responseDecodable(of: HomeResponse.self) { response in @@ -23,6 +24,7 @@ self.data.sectorPerformance = value.sectorPerformance } + self.triggerHaptic = true self.showView = true } } diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear/Views/Profile/Helpers/ProfileStockRow.swift --- a/LazyBear/Views/Profile/Helpers/ProfileStockRow.swift Sat Jun 26 18:45:31 2021 +0200 +++ b/LazyBear/Views/Profile/Helpers/ProfileStockRow.swift Sun Jun 27 14:18:29 2021 +0200 @@ -12,9 +12,6 @@ var companies: [CompanyModel] @State private var showWatchlistSheet = false - @State private var willRenameWatchlist = false - @State private var showRenameWatchlistSheet = false - @Environment(\.managedObjectContext) private var moc var body: some View { VStack(alignment: .leading) { @@ -32,9 +29,15 @@ } Spacer() - Button("See all", action: { showWatchlistSheet = true }) - .buttonStyle(BorderlessButtonStyle()) - .padding(.horizontal) + NavigationLink(destination: WatchlistSheet(listName: watchlistName, apiCompanies: companies) + .navigationTitle(watchlistName) + ) { + HStack { + Text("See all") + Image(systemName: "chevron.right") + } + } + .padding(.horizontal) } ScrollView(.horizontal, showsIndicators: false) { @@ -48,23 +51,6 @@ .frame(height: 250) } .padding(.bottom) - .sheet(isPresented: $showWatchlistSheet, onDismiss: didDismissWatchlistSheet) { - WatchlistSheet(listName: watchlistName, apiCompanies: companies, willRenameWatchlist: $willRenameWatchlist) - .environment(\.managedObjectContext, self.moc) - } - .sheet(isPresented: $showRenameWatchlistSheet) { - RenameListSheet(oldWatchlistName: watchlistName) - .environment(\.managedObjectContext, self.moc) - } - } - - /* - If user wants to rename watchlist -> when WatchlistSheet is dismissed, show RenameListSheet - */ - private func didDismissWatchlistSheet() { - if willRenameWatchlist { - showRenameWatchlistSheet = true - } } } diff -r bb69f9d1d20f -r 37c13ebda381 LazyBear/Views/Profile/Helpers/WatchlistSheet.swift --- a/LazyBear/Views/Profile/Helpers/WatchlistSheet.swift Sat Jun 26 18:45:31 2021 +0200 +++ b/LazyBear/Views/Profile/Helpers/WatchlistSheet.swift Sun Jun 27 14:18:29 2021 +0200 @@ -10,9 +10,7 @@ struct WatchlistSheet: View { var listName: String var apiCompanies: [CompanyModel] - @Binding var willRenameWatchlist: Bool - - @Environment(\.presentationMode) private var watchlistSheetPresentation + @Environment(\.managedObjectContext) private var moc @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) var watchlistCompanies: FetchedResults @@ -20,44 +18,42 @@ @State private var showDeleteListAlert = false var body: some View { - NavigationView { - VStack { - List { - ForEach(watchlistCompanies.filter { $0.watchlistName == listName }, id: \.self) { watchlistCompany in - let apiCompany = apiCompanies.first(where: { $0.symbol == watchlistCompany.symbol }) - WatchlistSheetRow(apiCompany: apiCompany!, watchlistCompany: watchlistCompany) - } - .onDelete(perform: deleteCompany) + VStack { + List { + ForEach(watchlistCompanies.filter { $0.watchlistName == listName }, id: \.self) { watchlistCompany in + let apiCompany = apiCompanies.first(where: { $0.symbol == watchlistCompany.symbol }) + WatchlistSheetRow(apiCompany: apiCompany!, watchlistCompany: watchlistCompany) } + .onDelete(perform: deleteCompany) } - .navigationTitle(listName) - .toolbar { - ToolbarItem(placement: .navigationBarLeading) { - Button(action: { willRenameWatchlist = false; watchlistSheetPresentation.wrappedValue.dismiss()} ) { - Image(systemName: "multiply") + } + .navigationTitle(listName) + .toolbar { + ToolbarItem(placement: .navigationBarLeading) { +// Button(action: { willRenameWatchlist = false; watchlistSheetPresentation.wrappedValue.dismiss()} ) { +// Image(systemName: "multiply") +// } + } + + ToolbarItem(placement: .navigationBarTrailing) { + Menu { + Section { +// Button(action: { willRenameWatchlist = true; watchlistSheetPresentation.wrappedValue.dismiss() }) { +// Label("Rename list", systemImage: "square.and.pencil") +// } } - } - - ToolbarItem(placement: .navigationBarTrailing) { - Menu { - Section { - Button(action: { willRenameWatchlist = true; watchlistSheetPresentation.wrappedValue.dismiss() }) { - Label("Rename list", systemImage: "square.and.pencil") - } - } - - if Set(watchlistCompanies.map { $0.watchlistName }).count > 1 { /// If there are only 1 watchlist (default) -> It cannot be deleted - Section(header: Text("Secondary actions")) { - Button(action: { showDeleteListAlert = true }) { - Label("Delete list", systemImage: "trash") - } + + if Set(watchlistCompanies.map { $0.watchlistName }).count > 1 { /// If there are only 1 watchlist (default) -> It cannot be deleted + Section(header: Text("Secondary actions")) { + Button(action: { showDeleteListAlert = true }) { + Label("Delete list", systemImage: "trash") } } } - label: { - Label("Options", systemImage: "ellipsis.circle") - .imageScale(.large) - } + } + label: { + Label("Options", systemImage: "ellipsis.circle") + .imageScale(.large) } } } @@ -99,7 +95,7 @@ do { try moc.save() print("List deleted") - watchlistSheetPresentation.wrappedValue.dismiss() /// Dismiss view +// watchlistSheetPresentation.wrappedValue.dismiss() /// Dismiss view } catch { print(error.localizedDescription) } @@ -110,8 +106,7 @@ static var previews: some View { WatchlistSheet( listName: "Most active", - apiCompanies: [CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3])], - willRenameWatchlist: .constant(false) + apiCompanies: [CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3])] ) } } diff -r bb69f9d1d20f -r 37c13ebda381 LazyBearWatchOS Extension/Views/Home/HomeView.swift --- a/LazyBearWatchOS Extension/Views/Home/HomeView.swift Sat Jun 26 18:45:31 2021 +0200 +++ b/LazyBearWatchOS Extension/Views/Home/HomeView.swift Sun Jun 27 14:18:29 2021 +0200 @@ -11,8 +11,7 @@ struct HomeView: View { @ObservedObject var profile = Profile() - @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) - var watchlistCompanies: FetchedResults + @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) var watchlistCompanies: FetchedResults @State private var timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() /// Set recurrent price request @@ -49,6 +48,7 @@ switch requestType { case .initial: let url = "https://api.lazybear.app/profile/type=initial/symbols=\(symbolsString)" + print(watchlistCompanies) profile.request(url, .initial) default: