Mercurial > public > lazybear
changeset 448:f71761f166f2
Handle when data is empty
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Wed, 23 Jun 2021 11:47:14 +0200 |
parents | 8621ba6fd457 |
children | 4255f94d0767 |
files | LazyBear.xcodeproj/project.pbxproj LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate LazyBear/Global functions/ConvertEpoch.swift LazyBear/Global functions/UnwrapAnyOptional.swift LazyBear/Views/Company/CompanyView.swift LazyBear/Views/Company/Helpers/KeyStatsHelper.swift LazyBear/Views/Company/Helpers/KeyStatsList.swift LazyBear/Views/Company/Helpers/KeyStatsRow.swift LazyBear/Views/Company/Helpers/NewsRow.swift |
diffstat | 9 files changed, 107 insertions(+), 78 deletions(-) [+] |
line wrap: on
line diff
--- a/LazyBear.xcodeproj/project.pbxproj Wed Jun 23 10:54:47 2021 +0200 +++ b/LazyBear.xcodeproj/project.pbxproj Wed Jun 23 11:47:14 2021 +0200 @@ -98,6 +98,8 @@ 95AF0FF92671342E0049C4AB /* DisplayWordsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95AF0FF82671342E0049C4AB /* DisplayWordsModel.swift */; }; 95B85AB6267FAE7A0080CF39 /* ConditionalModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B85AB5267FAE7A0080CF39 /* ConditionalModifier.swift */; }; 95BB05B22670B8C3005A2029 /* KeyStatsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BB05B12670B8C3005A2029 /* KeyStatsModel.swift */; }; + 95BC1C642683326C00F94373 /* KeyStatsRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BC1C632683326C00F94373 /* KeyStatsRow.swift */; }; + 95BC1C66268336A200F94373 /* UnwrapAnyOptional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BC1C65268336A200F94373 /* UnwrapAnyOptional.swift */; }; 95C22F3F26776F010014C98A /* CompanyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C22F3E26776F010014C98A /* CompanyModel.swift */; }; 95C8C0E0262A369F0082D1D9 /* ProfileResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C8C0DF262A369F0082D1D9 /* ProfileResponse.swift */; }; 95CCFB56266E7A0F00C384A1 /* InsiderTransactionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95CCFB55266E7A0F00C384A1 /* InsiderTransactionModel.swift */; }; @@ -284,6 +286,8 @@ 95AF0FF82671342E0049C4AB /* DisplayWordsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayWordsModel.swift; sourceTree = "<group>"; }; 95B85AB5267FAE7A0080CF39 /* ConditionalModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConditionalModifier.swift; sourceTree = "<group>"; }; 95BB05B12670B8C3005A2029 /* KeyStatsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyStatsModel.swift; sourceTree = "<group>"; }; + 95BC1C632683326C00F94373 /* KeyStatsRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyStatsRow.swift; sourceTree = "<group>"; }; + 95BC1C65268336A200F94373 /* UnwrapAnyOptional.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnwrapAnyOptional.swift; sourceTree = "<group>"; }; 95C22F3E26776F010014C98A /* CompanyModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanyModel.swift; sourceTree = "<group>"; }; 95C8C0DF262A369F0082D1D9 /* ProfileResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileResponse.swift; sourceTree = "<group>"; }; 95CCFB55266E7A0F00C384A1 /* InsiderTransactionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsiderTransactionModel.swift; sourceTree = "<group>"; }; @@ -402,6 +406,7 @@ 95CCFB5D266E855800C384A1 /* GetDateComponents.swift */, 95CCFB5F266E864C00C384A1 /* ConvertStringToDate.swift */, 95B85AB5267FAE7A0080CF39 /* ConditionalModifier.swift */, + 95BC1C65268336A200F94373 /* UnwrapAnyOptional.swift */, ); path = "Global functions"; sourceTree = "<group>"; @@ -701,6 +706,7 @@ 9502BBFC267F63F3003B0A59 /* CustomRectangleBox.swift */, 9502BBFA267F5EE8003B0A59 /* ChartHelper.swift */, 9502BBFE267F6454003B0A59 /* KeyStatsHelper.swift */, + 95BC1C632683326C00F94373 /* KeyStatsRow.swift */, 9502BC00267F8771003B0A59 /* KeyStatsList.swift */, 95E4A2D6268091F900A6FEB9 /* NewsHelper.swift */, 95E4A2D82680931300A6FEB9 /* NewsRow.swift */, @@ -1063,6 +1069,7 @@ 95123ABE267669C6001BFAF3 /* StockSheetRow.swift in Sources */, 9550443A26111B2B000E0BCB /* HomeView.swift in Sources */, 95672B9825DDA54700DCBE4A /* Persistence.swift in Sources */, + 95BC1C66268336A200F94373 /* UnwrapAnyOptional.swift in Sources */, 95123ABC2676676B001BFAF3 /* CurrencySheetRow.swift in Sources */, 95A7C0742616409D003E2EC1 /* ParseJSON.swift in Sources */, 95E4A2D7268091F900A6FEB9 /* NewsHelper.swift in Sources */, @@ -1084,6 +1091,7 @@ 95A4B937263EA5C20056F036 /* WatchlistCreatorRow.swift in Sources */, 950D0E192618AA4900D17AD7 /* CompanyList.swift in Sources */, 9502BBFB267F5EE8003B0A59 /* ChartHelper.swift in Sources */, + 95BC1C642683326C00F94373 /* KeyStatsRow.swift in Sources */, 952994822629CA46005F0AB0 /* SearchResponse.swift in Sources */, 95A07F6C26305AC6009865AA /* QuoteModel.swift in Sources */, 95A07F6226305A9B009865AA /* CurrencyModel.swift in Sources */,
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/LazyBear/Global functions/ConvertEpoch.swift Wed Jun 23 10:54:47 2021 +0200 +++ b/LazyBear/Global functions/ConvertEpoch.swift Wed Jun 23 11:47:14 2021 +0200 @@ -17,7 +17,7 @@ let convertedDate = Date(timeIntervalSince1970: TimeInterval(miliseconds/1000)) let formatter = DateComponentsFormatter() - formatter.unitsStyle = .abbreviated + formatter.unitsStyle = .short let dateFormatter = DateFormatter() dateFormatter.dateStyle = .medium
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Global functions/UnwrapAnyOptional.swift Wed Jun 23 11:47:14 2021 +0200 @@ -0,0 +1,21 @@ +// +// UnwrapAnyOptional.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 23/6/21. +// + +import SwiftUI + +/* + Unwrap optional Int, Double, String into String + */ +func unwrapAnyOptional(value: Any) -> String? { + if let value = value as? Int { + return "\(value)" + } else if let value = value as? Double { + return String(format: "%.3f", value) + } else { + return value as? String + } +}
--- a/LazyBear/Views/Company/CompanyView.swift Wed Jun 23 10:54:47 2021 +0200 +++ b/LazyBear/Views/Company/CompanyView.swift Wed Jun 23 11:47:14 2021 +0200 @@ -44,22 +44,29 @@ ChartHelper(company: company) if let keyStats = company.data.keyStats { - KeyStatsHelper(keyStats: keyStats) + KeyStatsHelper(keyStats: keyStats) + } if let latestNews = company.data.latestNews { - NewsHelper(latestNews: latestNews) - .padding([.horizontal, .bottom]) + if !latestNews.isEmpty { + NewsHelper(latestNews: latestNews) + .padding([.horizontal, .bottom]) + } } if let insiderRoster = company.data.insiderRoster { - InsiderRosterHelper(insiderRoster: insiderRoster) - .padding([.horizontal, .bottom]) + if !insiderRoster.isEmpty { + InsiderRosterHelper(insiderRoster: insiderRoster) + .padding([.horizontal, .bottom]) + } } if let insiderTransactions = company.data.insiderTransactions { - InsiderTransactionsHelper(insiderTransactions: insiderTransactions) - .padding([.horizontal, .bottom]) + if !insiderTransactions.isEmpty { + InsiderTransactionsHelper(insiderTransactions: insiderTransactions) + .padding([.horizontal, .bottom]) + } } } }
--- a/LazyBear/Views/Company/Helpers/KeyStatsHelper.swift Wed Jun 23 10:54:47 2021 +0200 +++ b/LazyBear/Views/Company/Helpers/KeyStatsHelper.swift Wed Jun 23 11:47:14 2021 +0200 @@ -8,65 +8,31 @@ import SwiftUI struct KeyStatsHelper: View { - var keyStats: KeyStatsModel? + var keyStats: KeyStatsModel let displayWords: DisplayWordsModel = parseJSON("DisplayWords.json") - @Environment(\.colorScheme) private var colorScheme var body: some View { - if let keyStats = keyStats { - ScrollView(.horizontal, showsIndicators: false) { - HStack(spacing: 20) { - - let mirror = Mirror(reflecting: keyStats) - ForEach(Array(mirror.children), id: \.label) { child in /// Iterate over each variable within the class - - if let unwrappedValue = unwrapAnyOptional(value: child.value) { + ScrollView(.horizontal, showsIndicators: false) { + HStack(spacing: 20) { + + let mirror = Mirror(reflecting: keyStats) + ForEach(Array(mirror.children), id: \.label) { child in /// Iterate over each variable within the class + if let unwrappedValue = unwrapAnyOptional(value: child.value) { + if unwrappedValue != "0.000" && unwrappedValue != "0" && !unwrappedValue.isEmpty { let label = String(child.label!) NavigationLink(destination: KeyStatsList(keyStats: keyStats) .navigationTitle("Key Stats") ) { - Capsule() - .frame(width: 250, height: 40) - .foregroundColor(Color("customSecondaryBackground")) - .if(colorScheme == .light) { content in - content.shadow(color: Color(.systemGray).opacity(0.25), radius: 10, x: 0.0, y: 0.0) - } - .overlay( - HStack { - Text("\(displayWords.keyStats[label]!):") - .font(.callout) - .fontWeight(.semibold) - .lineLimit(1) - - Spacer() - Text(unwrappedValue) - .font(.callout) - .lineLimit(1) - } - .padding() - ) + KeyStatsRow(label: displayWords.keyStats[label]!) } .buttonStyle(PlainButtonStyle()) } } } - .frame(height: 70) - .padding(.horizontal) } - } - } - - /* - Unwrap optional Int, Double, String into String - */ - private func unwrapAnyOptional(value: Any) -> String? { - if let value = value as? Int { - return "\(value)" - } else if let value = value as? Double { - return String(format: "%.3f", value) - } else { - return value as? String + .frame(height: 70) + .padding(.horizontal) } } }
--- a/LazyBear/Views/Company/Helpers/KeyStatsList.swift Wed Jun 23 10:54:47 2021 +0200 +++ b/LazyBear/Views/Company/Helpers/KeyStatsList.swift Wed Jun 23 11:47:14 2021 +0200 @@ -16,35 +16,24 @@ let mirror = Mirror(reflecting: keyStats) ForEach(Array(mirror.children), id: \.label) { child in /// Iterate over each variable within the class if let unwrappedValue = unwrapAnyOptional(value: child.value) { - let label = String(child.label!) - HStack { - Text("\(displayWords.keyStats[label]!):") - .font(.callout) - .fontWeight(.semibold) - .lineLimit(1) - - Spacer() - Text(unwrappedValue) - .font(.callout) - .lineLimit(1) + if unwrappedValue != "0.000" && unwrappedValue != "0" && !unwrappedValue.isEmpty { + let label = String(child.label!) + HStack { + Text("\(displayWords.keyStats[label]!):") + .font(.callout) + .fontWeight(.semibold) + .lineLimit(1) + + Spacer() + Text(unwrappedValue) + .font(.callout) + .lineLimit(1) + } } } } } } - - /* - Unwrap optional Int, Double, String into String - */ - private func unwrapAnyOptional(value: Any) -> String? { - if let value = value as? Int { - return "\(value)" - } else if let value = value as? Double { - return String(format: "%.3f", value) - } else { - return value as? String - } - } } struct KeyStatsList_Previews: PreviewProvider {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Company/Helpers/KeyStatsRow.swift Wed Jun 23 11:47:14 2021 +0200 @@ -0,0 +1,38 @@ +// +// KeyStatsRow.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 23/6/21. +// + +import SwiftUI + +struct KeyStatsRow: View { + var label: String + @Environment(\.colorScheme) private var colorScheme + + var body: some View { + HStack { + Text("\(label)") + .font(.callout) + .fontWeight(.semibold) + .lineLimit(1) + + } + .padding() + .background( + Capsule() + .frame(height: 40) + .foregroundColor(Color("customSecondaryBackground")) + .if(colorScheme == .light) { content in + content.shadow(color: Color(.systemGray).opacity(0.25), radius: 10, x: 0.0, y: 0.0) + } + ) + } +} + +struct KeyStatsRow_Previews: PreviewProvider { + static var previews: some View { + KeyStatsRow(label: "Company Name") + } +}
--- a/LazyBear/Views/Company/Helpers/NewsRow.swift Wed Jun 23 10:54:47 2021 +0200 +++ b/LazyBear/Views/Company/Helpers/NewsRow.swift Wed Jun 23 11:47:14 2021 +0200 @@ -22,7 +22,7 @@ .font(.headline) .fontWeight(.semibold) .fixedSize(horizontal: false, vertical: true) /// I need to add this to make lineLimit works correctly - .lineLimit(3) + .lineLimit(2) } Spacer()