changeset 220:062fcab540ee

Implementing row colour mark
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sun, 28 Feb 2021 12:19:13 +0000
parents 317422422d1d
children f83d3f2d5e1a
files LazyBear/UI/CompanyRow.swift LazyBear/UI/Search.swift LazyBear/UI/Watchlist.swift
diffstat 3 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/LazyBear/UI/CompanyRow.swift	Sun Feb 28 12:19:00 2021 +0000
+++ b/LazyBear/UI/CompanyRow.swift	Sun Feb 28 12:19:13 2021 +0000
@@ -10,12 +10,20 @@
 struct CompanyRow: View {
     var symbol: String
     var name: String
-    var lefView: AnyView?
-    var rightView: AnyView?
+    var rowNumber: Int
+    
+    // Fetch user appearence settings (the last one made first)
+    @FetchRequest(entity: UserSettings.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \UserSettings.changedAt, ascending: false)])
+    var userSettings: FetchedResults<UserSettings>
     
     var body: some View {
         HStack {
-            lefView
+            let theme = userSettings.first?.theme?.lowercased() ?? "default"
+            RoundedRectangle(cornerRadius: 15)
+                .foregroundColor(Color("\(theme)Row\(rowNumber)"))
+                .frame(width: 10)
+                .offset(x: -25)
+            
             VStack(alignment: .leading) {
                 Text(symbol.uppercased())
                     .fontWeight(.semibold)
@@ -23,15 +31,14 @@
                 Text(name.capitalized)
                     .lineLimit(1)
             }
-            
-            Spacer()
-            rightView
         }
     }
 }
 
 struct Row_Previews: PreviewProvider {
     static var previews: some View {
-        CompanyRow(symbol: "aapl", name: "apple inc")
+        List {
+            CompanyRow(symbol: "aapl", name: "apple inc", rowNumber: 2)
+        }
     }
 }
--- a/LazyBear/UI/Search.swift	Sun Feb 28 12:19:00 2021 +0000
+++ b/LazyBear/UI/Search.swift	Sun Feb 28 12:19:13 2021 +0000
@@ -19,7 +19,7 @@
                 NavigationLink(destination: CompanyView(hudManager: hudManager, name: company.securityName ?? "-", symbol: company.symbol)
                                 .navigationTitle(company.symbol)
                 ) {
-                    CompanyRow(symbol: company.symbol, name: company.securityName ?? "-")
+                    CompanyRow(symbol: company.symbol, name: company.securityName ?? "-", rowNumber: 1)
                 }
             }
             .navigationBarSearch(self.$company)
--- a/LazyBear/UI/Watchlist.swift	Sun Feb 28 12:19:00 2021 +0000
+++ b/LazyBear/UI/Watchlist.swift	Sun Feb 28 12:19:13 2021 +0000
@@ -6,6 +6,7 @@
 //
 
 import SwiftUI
+import CoreData
 
 struct Watchlist: View {
     @ObservedObject var hudManager: HUDManager
@@ -19,7 +20,7 @@
                     NavigationLink(destination: CompanyView(hudManager: hudManager, name: company.name, symbol: company.symbol)
                                     .navigationTitle(company.symbol)
                     ) {
-                        CompanyRow(symbol: company.symbol, name: company.name)
+                        CompanyRow(symbol: company.symbol, name: company.name, rowNumber: 1)
                     }
                 }
                 .onDelete(perform: removeCompany)