changeset 413:2984d8946342

Minor UI changes
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Wed, 09 Jun 2021 10:23:52 +0200
parents a7c9dd0c5822
children b93172662988
files LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate LazyBear/Global Models/InsiderRosterModel.swift LazyBear/Styles/PriceViewStyle.swift LazyBear/Views/Company/Chart.swift LazyBear/Views/Company/Helpers/InsiderList.swift LazyBear/Views/Company/Helpers/InsiderRow.swift LazyBear/Views/Company/Helpers/TransactionRow.swift LazyBear/Views/Global Helpers/PriceView.swift LazyBear/Views/Global Helpers/RowShape.swift LazyBear/Views/Global Helpers/StockItem.swift LazyBear/Views/Home/Helpers/CurrencyItem.swift LazyBear/Views/Home/Helpers/TradingDatesItem.swift
diffstat 12 files changed, 98 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/LazyBear/Global Models/InsiderRosterModel.swift	Tue Jun 08 11:46:58 2021 +0200
+++ b/LazyBear/Global Models/InsiderRosterModel.swift	Wed Jun 09 10:23:52 2021 +0200
@@ -9,6 +9,6 @@
 
 struct InsiderRosterModel: Codable, Hashable {
     var entityName: String
-    var position: Int
+    var position: Int?
     var reportDate: Int
 }
--- a/LazyBear/Styles/PriceViewStyle.swift	Tue Jun 08 11:46:58 2021 +0200
+++ b/LazyBear/Styles/PriceViewStyle.swift	Wed Jun 09 10:23:52 2021 +0200
@@ -8,17 +8,27 @@
 import SwiftUI
 
 class PriceViewStyle {
-    var alignment: HorizontalAlignment
+    var horizontalAlignment: HorizontalAlignment
+    var verticalAlignment: VerticalAlignment
+    var orientation: Orientation
     var priceFont: Font
     var priceFontWeight: Font.Weight
     var percentFont: Font
     var percentFontWeight: Font.Weight
+    var showBackground: Bool
     
-    init(alignment: HorizontalAlignment, priceFont: Font, priceFontWeight: Font.Weight, percentFont: Font, percentFontWeight: Font.Weight) {
-        self.alignment = alignment
+    init(horizontalAlignment: HorizontalAlignment, verticalAlignment: VerticalAlignment, orientation: Orientation, priceFont: Font, priceFontWeight: Font.Weight, percentFont: Font, percentFontWeight: Font.Weight, showBackground: Bool) {
+        self.horizontalAlignment = horizontalAlignment
+        self.verticalAlignment = verticalAlignment
+        self.orientation = orientation
         self.priceFont = priceFont
         self.priceFontWeight = priceFontWeight
         self.percentFont = percentFont
         self.percentFontWeight = percentFontWeight
+        self.showBackground = showBackground
     }
 }
+
+enum Orientation {
+    case HStack, VStack
+}
--- a/LazyBear/Views/Company/Chart.swift	Tue Jun 08 11:46:58 2021 +0200
+++ b/LazyBear/Views/Company/Chart.swift	Wed Jun 09 10:23:52 2021 +0200
@@ -38,11 +38,14 @@
                                     let latestPrice = quote.latestPrice ?? 0
                                     let changePercent = quote.changePercent ?? 0
                                     let priceViewStyle = PriceViewStyle(
-                                        alignment: .leading,
+                                        horizontalAlignment: .leading,
+                                        verticalAlignment: .center,
+                                        orientation: .HStack,
                                         priceFont: .title3,
                                         priceFontWeight: .semibold,
                                         percentFont: .headline,
-                                        percentFontWeight: .medium
+                                        percentFontWeight: .medium,
+                                        showBackground: true
                                     )
                                     PriceView(latestPrice: latestPrice, changePercent: changePercent, style: priceViewStyle)
                                 }
--- a/LazyBear/Views/Company/Helpers/InsiderList.swift	Tue Jun 08 11:46:58 2021 +0200
+++ b/LazyBear/Views/Company/Helpers/InsiderList.swift	Wed Jun 09 10:23:52 2021 +0200
@@ -23,12 +23,12 @@
             }
         
             // Get total shares owned by the top 10 insiders
-            let totalPositions =  insiderSummary.map { $0.position }.reduce(0, +)
+            let totalPositions =  insiderSummary.map { $0.position ?? 0 }.reduce(0, +)
             VStack(alignment: .leading, spacing: 20) {
                 ForEach(insiderSummary.prefix(3), id: \.self) { insider in
                     
                     // Compute percentage of ownership for each insider
-                    let percentage = Double(insider.position) / Double(totalPositions)
+                    let percentage = Double(insider.position ?? 0) / Double(totalPositions)
                     
                     InsiderRow(percentageOfWidth: CGFloat(percentage), insiderRoster: insider)
                 }
@@ -56,12 +56,12 @@
         NavigationView {
             ScrollView {
                 // Get total shares owned by the top 10 insiders
-                let totalPositions =  insiderSummary.map { $0.position }.reduce(0, +)
+                let totalPositions =  insiderSummary.map { $0.position ?? 0 }.reduce(0, +)
                 VStack(alignment: .leading, spacing: 20) {
                     ForEach(insiderSummary, id: \.self) { insider in
                         
                         // Compute percentage of ownership for each insider
-                        let percentage = Double(insider.position) / Double(totalPositions)
+                        let percentage = Double(insider.position ?? 0) / Double(totalPositions)
                         
                         InsiderRow(percentageOfWidth: CGFloat(percentage), insiderRoster: insider)
                     }
--- a/LazyBear/Views/Company/Helpers/InsiderRow.swift	Tue Jun 08 11:46:58 2021 +0200
+++ b/LazyBear/Views/Company/Helpers/InsiderRow.swift	Wed Jun 09 10:23:52 2021 +0200
@@ -27,7 +27,7 @@
                     
                     HStack {
                         Spacer()
-                        Text("\(insiderRoster.position) shares owned")
+                        Text("\(insiderRoster.position ?? 0) shares owned")
                             .font(.caption)
                             .opacity(0.5)
                     }
--- a/LazyBear/Views/Company/Helpers/TransactionRow.swift	Tue Jun 08 11:46:58 2021 +0200
+++ b/LazyBear/Views/Company/Helpers/TransactionRow.swift	Wed Jun 09 10:23:52 2021 +0200
@@ -23,7 +23,7 @@
                         Text(getDateComponents(.day, date))
                             .font(.title)
                             .fontWeight(.semibold)
-                            .foregroundColor(Color("default"))
+                            .foregroundColor(Color(.systemBlue))
                         
                         Text(getDateComponents(.year, date))
                             .font(.caption)
@@ -36,7 +36,7 @@
                             .lineLimit(1)
                             .font(.headline)
                         
-                        Text(transaction.reportedTitle ?? "-")
+                        Text(transaction.reportedTitle?.capitalized ?? "-")
                     }
                     
                     Spacer()
--- a/LazyBear/Views/Global Helpers/PriceView.swift	Tue Jun 08 11:46:58 2021 +0200
+++ b/LazyBear/Views/Global Helpers/PriceView.swift	Wed Jun 09 10:23:52 2021 +0200
@@ -13,20 +13,58 @@
     var style: PriceViewStyle
     
     var body: some View {
-        VStack(alignment: style.alignment) {
-            Text("\(latestPrice, specifier: "%.2f")")
-                .foregroundColor(changePercent < 0 ? .red: .green)
-                .font(style.priceFont)
-                .fontWeight(style.priceFontWeight)
-            
-            Text("\(changePercent*100, specifier: "%.2f")%")
-                .foregroundColor(changePercent < 0 ? .red: .green)
-                .font(style.percentFont)
-                .fontWeight(style.percentFontWeight)
+        if style.orientation == .VStack {
+            VStack(alignment: style.horizontalAlignment) {
+                Price(latestPrice: latestPrice, changePercent: changePercent, style: style)
+            }
+        } else {
+            HStack(alignment: style.verticalAlignment) {
+                Price(latestPrice: latestPrice, changePercent: changePercent, style: style)
+            }
+            .if(style.showBackground) { content in
+                content
+                    .padding(10)
+                    .background(
+                        RoundedRectangle(cornerRadius: 15)
+                            .foregroundColor(Color(.tertiarySystemBackground))
+                    )
+            }
         }
     }
 }
 
+/*
+ Apply modifiers to the passed view on some condition
+ */
+extension View {
+   @ViewBuilder
+   func `if`<Content: View>(_ conditional: Bool, content: (Self) -> Content) -> some View {
+        if conditional {
+            content(self)
+        } else {
+            self
+        }
+    }
+}
+
+struct Price: View {
+    var latestPrice: Double
+    var changePercent: Double
+    var style: PriceViewStyle
+    
+    var body: some View {
+        Text("\(latestPrice, specifier: "%.2f")")
+            .foregroundColor(changePercent < 0 ? .red: .green)
+            .font(style.priceFont)
+            .fontWeight(style.priceFontWeight)
+        
+        Text("\(changePercent*100, specifier: "%.2f")%")
+            .foregroundColor(changePercent < 0 ? .red: .green)
+            .font(style.percentFont)
+            .fontWeight(style.percentFontWeight)
+    }
+}
+
 
 struct PriceView_Previews: PreviewProvider {
     static var previews: some View {
@@ -34,11 +72,14 @@
             latestPrice: 120.30,
             changePercent: 0.03,
             style: PriceViewStyle(
-                alignment: .leading,
+                horizontalAlignment: .leading,
+                verticalAlignment: .center,
+                orientation: .VStack,
                 priceFont: .body,
                 priceFontWeight: .semibold,
                 percentFont: .callout,
-                percentFontWeight: .semibold
+                percentFontWeight: .semibold,
+                showBackground: true
             )
         )
     }
--- a/LazyBear/Views/Global Helpers/RowShape.swift	Tue Jun 08 11:46:58 2021 +0200
+++ b/LazyBear/Views/Global Helpers/RowShape.swift	Wed Jun 09 10:23:52 2021 +0200
@@ -8,10 +8,16 @@
 import SwiftUI
 
 struct RowShape: View {
+    @Environment(\.colorScheme) var colorScheme
+    
     var body: some View {
         RoundedRectangle(cornerRadius: 25)
             .foregroundColor(Color("CustomSecondaryBackground"))
-            .shadow(color: Color(.gray).opacity(0.15), radius: 10)
+            .if(colorScheme == .light) { content in
+                // Apply shadow only when is not dark mode
+                content
+                    .shadow(color: Color(.gray).opacity(0.15), radius: 10)
+            }
     }
 }
 
--- a/LazyBear/Views/Global Helpers/StockItem.swift	Tue Jun 08 11:46:58 2021 +0200
+++ b/LazyBear/Views/Global Helpers/StockItem.swift	Wed Jun 09 10:23:52 2021 +0200
@@ -73,11 +73,14 @@
                             .lineLimit(1)
                         
                         let priceViewStyle = PriceViewStyle(
-                            alignment: .leading,
+                            horizontalAlignment: .leading,
+                            verticalAlignment: .center,
+                            orientation: .VStack,
                             priceFont: .body,
                             priceFontWeight: .semibold,
                             percentFont: .callout,
-                            percentFontWeight: .semibold
+                            percentFontWeight: .semibold,
+                            showBackground: false
                         )
                         
                         PriceView(latestPrice: company.latestPrice ?? 0,
@@ -132,11 +135,14 @@
                 }
                 
                 let priceViewStyle = PriceViewStyle(
-                    alignment: .leading,
+                    horizontalAlignment: .leading,
+                    verticalAlignment: .center,
+                    orientation: .VStack,
                     priceFont: .body,
                     priceFontWeight: .semibold,
                     percentFont: .callout,
-                    percentFontWeight: .semibold
+                    percentFontWeight: .semibold,
+                    showBackground: false
                 )
                 
                 PriceView(latestPrice: company.latestPrice ?? 0,
--- a/LazyBear/Views/Home/Helpers/CurrencyItem.swift	Tue Jun 08 11:46:58 2021 +0200
+++ b/LazyBear/Views/Home/Helpers/CurrencyItem.swift	Wed Jun 09 10:23:52 2021 +0200
@@ -17,7 +17,7 @@
             .frame(width: 330, height: 50)
             .overlay(
                 HStack {
-                    Color("default")
+                    Color(.systemBlue)
                         .frame(width: 40)
                         .overlay(
                             Text(currency.flag)
--- a/LazyBear/Views/Home/Helpers/TradingDatesItem.swift	Tue Jun 08 11:46:58 2021 +0200
+++ b/LazyBear/Views/Home/Helpers/TradingDatesItem.swift	Wed Jun 09 10:23:52 2021 +0200
@@ -23,7 +23,7 @@
                     Text(getDateComponents(.day, date))
                         .font(.title)
                         .fontWeight(.semibold)
-                        .foregroundColor(Color("default"))
+                        .foregroundColor(Color(.systemBlue))
                     
                     Text(getDateComponents(.year, date))
                         .font(.caption)