# HG changeset patch # User Dennis Concepción Martín # Date 1624373661 -7200 # Node ID 428109b1e3f0a9c590d97fe8bc101639d7bdfe8c # Parent ffbb1dbab531ffdea39e047a1c3c4c1550e34804 InsiderTransactions implemented diff -r ffbb1dbab531 -r 428109b1e3f0 LazyBear.xcodeproj/project.pbxproj --- a/LazyBear.xcodeproj/project.pbxproj Mon Jun 21 20:17:46 2021 +0200 +++ b/LazyBear.xcodeproj/project.pbxproj Tue Jun 22 16:54:21 2021 +0200 @@ -52,7 +52,10 @@ 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 */; }; - 954572EC267A3D6A00C33A20 /* StockCharts in Frameworks */ = {isa = PBXBuildFile; productRef = 954572EB267A3D6A00C33A20 /* StockCharts */; }; + 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 */; }; + 9547482A26822F0700D6A966 /* StockCharts in Frameworks */ = {isa = PBXBuildFile; productRef = 9547482926822F0700D6A966 /* StockCharts */; }; 954D7EC2260BE70C00A13C50 /* SwiftlySearch in Frameworks */ = {isa = PBXBuildFile; productRef = 954D7EC1260BE70C00A13C50 /* SwiftlySearch */; }; 9550443A26111B2B000E0BCB /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9550443926111B2B000E0BCB /* HomeView.swift */; }; 9550444326111E7A000E0BCB /* SectorRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9550444226111E7A000E0BCB /* SectorRow.swift */; }; @@ -233,6 +236,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 = ""; }; + 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 = ""; }; 9550443926111B2B000E0BCB /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = ""; }; 9550444226111E7A000E0BCB /* SectorRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectorRow.swift; sourceTree = ""; }; 9550444526111EE5000E0BCB /* SectorItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectorItem.swift; sourceTree = ""; }; @@ -330,7 +336,7 @@ 958A735225E0170900FD7ECA /* CloudKit.framework in Frameworks */, 950B6F3F267643640029E447 /* StoreKit.framework in Frameworks */, 9594331326691789004A0339 /* Bazooka in Frameworks */, - 954572EC267A3D6A00C33A20 /* StockCharts in Frameworks */, + 9547482A26822F0700D6A966 /* StockCharts in Frameworks */, 95A4B933263E9F810056F036 /* Introspect in Frameworks */, 950B6F3D267643460029E447 /* Purchases in Frameworks */, 954D7EC2260BE70C00A13C50 /* SwiftlySearch in Frameworks */, @@ -663,6 +669,9 @@ 9576BFEA26810661002BCAC6 /* InsiderRosterHelper.swift */, 9576BFEE26810719002BCAC6 /* InsiderRosterRow.swift */, 9576BFEC26810713002BCAC6 /* InsiderRosterList.swift */, + 9547481F26821F7700D6A966 /* InsiderTransactionsHelper.swift */, + 9547482126821F8800D6A966 /* InsiderTransactionsRow.swift */, + 9547482326821F9400D6A966 /* InsiderTransactionsList.swift */, ); path = Helpers; sourceTree = ""; @@ -815,7 +824,7 @@ 95A4B932263E9F810056F036 /* Introspect */, 9594331226691789004A0339 /* Bazooka */, 950B6F3C267643460029E447 /* Purchases */, - 954572EB267A3D6A00C33A20 /* StockCharts */, + 9547482926822F0700D6A966 /* StockCharts */, ); productName = LazyBear; productReference = 95672B8B25DDA54700DCBE4A /* LazyBear.app */; @@ -871,7 +880,7 @@ 95A4B931263E9F810056F036 /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */, 9594331126691789004A0339 /* XCRemoteSwiftPackageReference "Bazooka" */, 950B6F3B267643460029E447 /* XCRemoteSwiftPackageReference "purchases-ios" */, - 954572EA267A3D6A00C33A20 /* XCRemoteSwiftPackageReference "StockCharts" */, + 9547482826822F0700D6A966 /* XCRemoteSwiftPackageReference "StockCharts" */, ); productRefGroup = 95672B8C25DDA54700DCBE4A /* Products */; projectDirPath = ""; @@ -1014,6 +1023,7 @@ 95A7C0742616409D003E2EC1 /* ParseJSON.swift in Sources */, 95E4A2D7268091F900A6FEB9 /* NewsHelper.swift in Sources */, 9576BFED26810713002BCAC6 /* InsiderRosterList.swift in Sources */, + 9547482426821F9400D6A966 /* InsiderTransactionsList.swift in Sources */, 95E8BAA32656D86E0016AE72 /* RequestType.swift in Sources */, 95CCFB56266E7A0F00C384A1 /* InsiderTransactionModel.swift in Sources */, 951566E72613A2B6007C0F36 /* TradingDatesSheet.swift in Sources */, @@ -1038,6 +1048,7 @@ 950D0E292618AEC800D17AD7 /* SearchedCompanyItem.swift in Sources */, 955E733C262356F3005652FF /* HomeResponse.swift in Sources */, 951566EA2613A37C007C0F36 /* TradingDatesItem.swift in Sources */, + 9547482026821F7700D6A966 /* InsiderTransactionsHelper.swift in Sources */, 951490552610BD2B00BDEEB5 /* WelcomeView.swift in Sources */, 95D308F82624B3A400A39F77 /* CurrencyItem.swift in Sources */, 95131D47267A03020055C6DE /* WatchlistCompany+CoreDataClass.swift in Sources */, @@ -1063,6 +1074,7 @@ 95A4B930263E9F530056F036 /* WatchlistCreatorList.swift in Sources */, 95123ABA2676658E001BFAF3 /* StockSheet.swift in Sources */, 9562404E263C7D8800C6C511 /* WatchlistCreatorClass.swift in Sources */, + 9547482226821F8800D6A966 /* InsiderTransactionsRow.swift in Sources */, 952045152610C7C600A76362 /* ConvertEpoch.swift in Sources */, 952FC0BA267C9A24001406B1 /* RenameListSheet.swift in Sources */, 95E4A2E02680A70000A6FEB9 /* NewsList.swift in Sources */, @@ -1192,7 +1204,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 6; + CURRENT_PROJECT_VERSION = 7; DEVELOPMENT_TEAM = MTX83R5H8X; IBSC_MODULE = LazyBearWatchOS_Extension; INFOPLIST_FILE = LazyBearWatchOS/Info.plist; @@ -1214,7 +1226,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 6; + CURRENT_PROJECT_VERSION = 7; DEVELOPMENT_TEAM = MTX83R5H8X; IBSC_MODULE = LazyBearWatchOS_Extension; INFOPLIST_FILE = LazyBearWatchOS/Info.plist; @@ -1234,7 +1246,7 @@ buildSettings = { ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 6; + CURRENT_PROJECT_VERSION = 7; DEVELOPMENT_ASSET_PATHS = "\"LazyBearWatchOS Extension/Preview Content\""; DEVELOPMENT_TEAM = MTX83R5H8X; ENABLE_PREVIEWS = YES; @@ -1260,7 +1272,7 @@ buildSettings = { ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 6; + CURRENT_PROJECT_VERSION = 7; DEVELOPMENT_ASSET_PATHS = "\"LazyBearWatchOS Extension/Preview Content\""; DEVELOPMENT_TEAM = MTX83R5H8X; ENABLE_PREVIEWS = YES; @@ -1494,7 +1506,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = LazyBear/LazyBear.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 6; + CURRENT_PROJECT_VERSION = 7; DEVELOPMENT_ASSET_PATHS = "\"LazyBear/Preview Content\""; DEVELOPMENT_TEAM = MTX83R5H8X; ENABLE_PREVIEWS = YES; @@ -1519,7 +1531,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = LazyBear/LazyBear.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 6; + CURRENT_PROJECT_VERSION = 7; DEVELOPMENT_ASSET_PATHS = "\"LazyBear/Preview Content\""; DEVELOPMENT_TEAM = MTX83R5H8X; ENABLE_PREVIEWS = YES; @@ -1623,12 +1635,12 @@ minimumVersion = 3.11.1; }; }; - 954572EA267A3D6A00C33A20 /* XCRemoteSwiftPackageReference "StockCharts" */ = { + 9547482826822F0700D6A966 /* XCRemoteSwiftPackageReference "StockCharts" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/denniscm190/StockCharts.git"; requirement = { kind = upToNextMajorVersion; - minimumVersion = 1.2.3; + minimumVersion = 1.2.5; }; }; 954D7EC0260BE70C00A13C50 /* XCRemoteSwiftPackageReference "SwiftlySearch" */ = { @@ -1663,9 +1675,9 @@ package = 950B6F3B267643460029E447 /* XCRemoteSwiftPackageReference "purchases-ios" */; productName = Purchases; }; - 954572EB267A3D6A00C33A20 /* StockCharts */ = { + 9547482926822F0700D6A966 /* StockCharts */ = { isa = XCSwiftPackageProductDependency; - package = 954572EA267A3D6A00C33A20 /* XCRemoteSwiftPackageReference "StockCharts" */; + package = 9547482826822F0700D6A966 /* XCRemoteSwiftPackageReference "StockCharts" */; productName = StockCharts; }; 954D7EC1260BE70C00A13C50 /* SwiftlySearch */ = { diff -r ffbb1dbab531 -r 428109b1e3f0 LazyBear.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved --- a/LazyBear.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved Mon Jun 21 20:17:46 2021 +0200 +++ b/LazyBear.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved Tue Jun 22 16:54:21 2021 +0200 @@ -24,8 +24,8 @@ "repositoryURL": "https://github.com/denniscm190/StockCharts.git", "state": { "branch": null, - "revision": "4911cd3aa1ab73545ff90553e4dd35513c9c47dd", - "version": "1.2.3" + "revision": "647f282b1d9d91372043cdcee747c7ed59d927d3", + "version": "1.2.5" } }, { @@ -33,8 +33,8 @@ "repositoryURL": "https://github.com/thislooksfun/SwiftlySearch.git", "state": { "branch": null, - "revision": "7741806e979e59e9583962da43d09ec92f598026", - "version": "1.2.4" + "revision": "a7184413250a91f012d5d26eed874b5b2fdaeaac", + "version": "1.2.5" } }, { diff -r ffbb1dbab531 -r 428109b1e3f0 LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed diff -r ffbb1dbab531 -r 428109b1e3f0 LazyBear/Global Models/InsiderTransactionModel.swift --- a/LazyBear/Global Models/InsiderTransactionModel.swift Mon Jun 21 20:17:46 2021 +0200 +++ b/LazyBear/Global Models/InsiderTransactionModel.swift Tue Jun 22 16:54:21 2021 +0200 @@ -10,7 +10,7 @@ struct InsiderTransactionModel: Codable, Hashable { var filingDate: String var fullName: String - var postShares: Int? + var postShares: Float? var reportedTitle: String? var transactionCode: String var transactionPrice: Float? diff -r ffbb1dbab531 -r 428109b1e3f0 LazyBear/Views/Company/CompanyView.swift --- a/LazyBear/Views/Company/CompanyView.swift Mon Jun 21 20:17:46 2021 +0200 +++ b/LazyBear/Views/Company/CompanyView.swift Tue Jun 22 16:54:21 2021 +0200 @@ -51,6 +51,11 @@ InsiderRosterHelper(insiderRoster: insiderRoster) .padding([.horizontal, .bottom]) } + + if let insiderTransactions = company.data.insiderTransactions { + InsiderTransactionsHelper(insiderTransactions: insiderTransactions) + .padding([.horizontal, .bottom]) + } } } .background(Color("customBackground").edgesIgnoringSafeArea(.all)) diff -r ffbb1dbab531 -r 428109b1e3f0 LazyBear/Views/Company/Helpers/ChartHelper.swift --- a/LazyBear/Views/Company/Helpers/ChartHelper.swift Mon Jun 21 20:17:46 2021 +0200 +++ b/LazyBear/Views/Company/Helpers/ChartHelper.swift Tue Jun 22 16:54:21 2021 +0200 @@ -17,19 +17,26 @@ .overlay( VStack { if let quote = company.data.quote?.first { - HStack(alignment: .center) { - Text("\(quote.latestPrice ?? 0, specifier: "%.2f")") - .foregroundColor(quote.changePercent ?? 0 < 0 ? .red: .green) - .fontWeight(.semibold) + Text("\(quote.latestPrice ?? 0, specifier: "%.2f")") + .font(.title2) + .fontWeight(.semibold) + .foregroundColor(quote.changePercent ?? 0 < 0 ? .red: .green) + .padding(.top) + HStack { Text("\(quote.changePercent ?? 0 * 100, specifier: "%.2f")%") .foregroundColor(quote.changePercent ?? 0 < 0 ? .red: .green) - .font(.callout) + .font(.caption) .fontWeight(.semibold) - Spacer() + Text("1 day") + .font(.caption) + .opacity(0.5) } - .padding() + .padding(.horizontal) + + Spacer() + if let historicalPrices = company.data.historicalPrices { let prices = historicalPrices.compactMap { $0.close } diff -r ffbb1dbab531 -r 428109b1e3f0 LazyBear/Views/Company/Helpers/InsiderTransactionsHelper.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Company/Helpers/InsiderTransactionsHelper.swift Tue Jun 22 16:54:21 2021 +0200 @@ -0,0 +1,59 @@ +// +// InsiderTransactionsHelper.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 22/6/21. +// + +import SwiftUI + +struct InsiderTransactionsHelper: View { + var insiderTransactions: [InsiderTransactionModel] + @State private var showList = false + + var body: some View { + VStack(alignment: .leading) { + HStack { + Text("Insider Transactions") + .font(.title) + .fontWeight(.semibold) + + Spacer() + Button("See all", action: { showList = true } ) + } + .padding(.bottom) + + ForEach(insiderTransactions.prefix(4), id: \.self) { insiderTransaction in + InsiderTransactionsRow(insiderTransaction: insiderTransaction) + Divider() + } + } + .padding() + .background( + CustomRectangleBox() + ) + .sheet(isPresented: $showList) { + InsiderTransactionsList(insiderTransactions: insiderTransactions) + } + } +} + +struct InsiderTransactionsHelper_Previews: PreviewProvider { + static var previews: some View { + InsiderTransactionsHelper( + insiderTransactions: + [ + InsiderTransactionModel( + filingDate: "2020-01-01", + fullName: "Dennis Concepcion", + postShares: 1234, + reportedTitle: "Director", + transactionCode: "S", + transactionPrice: 20.08, + transactionShares: 12345, + transactionValue: 1234567.0 + ) + ] + ) + } +} diff -r ffbb1dbab531 -r 428109b1e3f0 LazyBear/Views/Company/Helpers/InsiderTransactionsList.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Company/Helpers/InsiderTransactionsList.swift Tue Jun 22 16:54:21 2021 +0200 @@ -0,0 +1,55 @@ +// +// InsiderTransactionsList.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 22/6/21. +// + +import SwiftUI + +struct InsiderTransactionsList: View { + var insiderTransactions: [InsiderTransactionModel] + @Environment(\.presentationMode) private var insiderTransactionsListPresentation + + var body: some View { + NavigationView { + ScrollView(showsIndicators: false) { + VStack { + ForEach(insiderTransactions, id: \.self) { insiderTransaction in + InsiderTransactionsRow(insiderTransaction: insiderTransaction) + Divider() + } + } + .padding() + } + .navigationTitle("Insider Transactions") + .toolbar { + ToolbarItem(placement: .cancellationAction) { + Button(action: { insiderTransactionsListPresentation.wrappedValue.dismiss() }) { + Image(systemName: "multiply") + } + } + } + } + } +} + +struct InsiderTransactionsList_Previews: PreviewProvider { + static var previews: some View { + InsiderTransactionsList( + insiderTransactions: + [ + InsiderTransactionModel( + filingDate: "2020-01-01", + fullName: "Dennis Concepcion", + postShares: 1234, + reportedTitle: "Director", + transactionCode: "S", + transactionPrice: 20.08, + transactionShares: 12345, + transactionValue: 1234567.0 + ) + ] + ) + } +} diff -r ffbb1dbab531 -r 428109b1e3f0 LazyBear/Views/Company/Helpers/InsiderTransactionsRow.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Company/Helpers/InsiderTransactionsRow.swift Tue Jun 22 16:54:21 2021 +0200 @@ -0,0 +1,69 @@ +// +// InsiderTransactionsRow.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 22/6/21. +// + +import SwiftUI + +struct InsiderTransactionsRow: View { + var insiderTransaction: InsiderTransactionModel + + var body: some View { + HStack { + VStack { + let date = convertStringToDate(insiderTransaction.filingDate) + Text(getDateComponents(.month, date)) + .fontWeight(.semibold) + + Text(getDateComponents(.day, date)) + .font(.title) + .fontWeight(.semibold) + .foregroundColor(Color(.systemBlue)) + + Text(getDateComponents(.year, date)) + .font(.caption) + .fontWeight(.semibold) + } + .padding(.trailing) + + VStack(alignment: .leading) { + Text(insiderTransaction.fullName.capitalized) + .lineLimit(1) + .font(.headline) + + if let reportedTitle = insiderTransaction.reportedTitle { + Text(reportedTitle.capitalized) + } + } + + Spacer() + if let transactionShares = insiderTransaction.transactionShares { + VStack(alignment: .trailing) { + Text("\(transactionShares)") + .foregroundColor(transactionShares < 0 ? Color(.systemRed): Color(.systemGreen)) + } + .padding(.leading) + } + } + } +} + +struct InsiderTransactionsRow_Previews: PreviewProvider { + static var previews: some View { + InsiderTransactionsRow( + insiderTransaction: + InsiderTransactionModel( + filingDate: "2020-01-01", + fullName: "Dennis Concepcion", + postShares: 1234, + reportedTitle: "Director", + transactionCode: "S", + transactionPrice: 20.08, + transactionShares: 12345, + transactionValue: 1234567.0 + ) + ) + } +}