From cb6a6be4881b32add79bb3886a131c62110c2888 Mon Sep 17 00:00:00 2001 From: Theppitak M <141404845+mmmmmob@users.noreply.github.com> Date: Tue, 4 Jun 2024 16:27:23 +0700 Subject: [PATCH 1/5] style: fix color and info shape on MyLotteryView --- Lotto Journal.xcodeproj/project.pbxproj | 6 +++--- Lotto Journal/Models/Lottery.swift | 2 +- Lotto Journal/Views/AddMyLotteryView.swift | 4 ++-- Lotto Journal/Views/MainTabView.swift | 2 +- Lotto Journal/Views/MyLotteryView.swift | 18 ++++++++++++++---- .../Views/PrizeNumberMultipleView.swift | 2 +- Lotto Journal/Views/PrizeNumberView.swift | 2 +- 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Lotto Journal.xcodeproj/project.pbxproj b/Lotto Journal.xcodeproj/project.pbxproj index 4437e03..f6daa2d 100644 --- a/Lotto Journal.xcodeproj/project.pbxproj +++ b/Lotto Journal.xcodeproj/project.pbxproj @@ -134,11 +134,11 @@ name = CheckResult; sourceTree = ""; }; - 4AD9DD4C2C04A59E00EE7866 /* MyLottery */ = { + 4AD9DD4C2C04A59E00EE7866 /* Summary */ = { isa = PBXGroup; children = ( ); - name = MyLottery; + name = Summary; sourceTree = ""; }; 4AF097502BF9DA21003A813B = { @@ -206,7 +206,7 @@ 4AF0976F2BF9DB75003A813B /* Components */ = { isa = PBXGroup; children = ( - 4AD9DD4C2C04A59E00EE7866 /* MyLottery */, + 4AD9DD4C2C04A59E00EE7866 /* Summary */, 4ABEF1992BFC716500904D3E /* CheckResult */, ); name = Components; diff --git a/Lotto Journal/Models/Lottery.swift b/Lotto Journal/Models/Lottery.swift index 3115af2..a4e9cf4 100644 --- a/Lotto Journal/Models/Lottery.swift +++ b/Lotto Journal/Models/Lottery.swift @@ -64,7 +64,7 @@ enum Status: Int, Codable, Identifiable, CaseIterable { var description: String { switch self { case .isWaiting: - "Waiting for Result🗿" + "Waiting 🗿" case .doesWon: "You Won! 🎉" case .doesNotWon: diff --git a/Lotto Journal/Views/AddMyLotteryView.swift b/Lotto Journal/Views/AddMyLotteryView.swift index f4041ac..dd732e6 100644 --- a/Lotto Journal/Views/AddMyLotteryView.swift +++ b/Lotto Journal/Views/AddMyLotteryView.swift @@ -25,7 +25,7 @@ struct AddMyLotteryView: View { var body: some View { NavigationStack { VStack { - OtpView(activeIndicatorColor: Color.teal, inactiveIndicatorColor: Color.gray, length: 6, doSomething: { numbers in + OtpView(activeIndicatorColor: Color.accentColor, inactiveIndicatorColor: Color.gray, length: 6, doSomething: { numbers in number = numbers }) .padding(.bottom) @@ -55,7 +55,7 @@ struct AddMyLotteryView: View { } .buttonStyle(.borderedProminent) .disabled(number.isEmpty) - .tint(.teal) + .tint(.accentColor) .controlSize(.large) .buttonBorderShape(.roundedRectangle) .padding(.top) diff --git a/Lotto Journal/Views/MainTabView.swift b/Lotto Journal/Views/MainTabView.swift index 9007fc4..ab25cad 100644 --- a/Lotto Journal/Views/MainTabView.swift +++ b/Lotto Journal/Views/MainTabView.swift @@ -35,7 +35,7 @@ struct MainTabView: View { } .tag(3) }) - .tint(.teal) + .tint(.brown) .onChange(of: scenePhase) { switch scenePhase { case .active: diff --git a/Lotto Journal/Views/MyLotteryView.swift b/Lotto Journal/Views/MyLotteryView.swift index 4afc56c..408dc72 100644 --- a/Lotto Journal/Views/MyLotteryView.swift +++ b/Lotto Journal/Views/MyLotteryView.swift @@ -68,7 +68,7 @@ struct MyLotteryView: View { } }) } header: { - HStack(alignment: .lastTextBaseline) { + HStack(alignment: .bottom) { if let latestResultDate = firstAPICall.result.latestResultDate.toDate() { let upcomingDate = latestResultDate.upcomingDrawDate if date.date == upcomingDate { @@ -82,15 +82,25 @@ struct MyLotteryView: View { Text(date.date.fullStringDate) // display fullStringDate while determine date from API } Spacer() - HStack { - Text("฿\(date.totalWon.delimiter)") + let totalWon = date.totalWon.delimiter + let totalInvestment = date.totalInvestment.delimiter + HStack(alignment:.center) { Text("\(Image(systemName: "checkmark.seal"))") + Text("\(totalWon)") Text("|") .font(.system(.caption, design: .default, weight: .ultraLight)) - Text("฿\(date.totalInvestment.delimiter)") Text("\(Image(systemName: "basket"))") + Text("\(totalInvestment)") } .font(.system(.caption, design: .default, weight: .regular)) + .padding(6) + .foregroundStyle(Color.white) + .background(Color.accentColor) + .clipShape(Capsule(style: .continuous)) + .overlay( + Capsule(style: .continuous) + .stroke(totalWon > totalInvestment ? .green : .red, lineWidth: 2) + ) } } .headerProminence(.increased) diff --git a/Lotto Journal/Views/PrizeNumberMultipleView.swift b/Lotto Journal/Views/PrizeNumberMultipleView.swift index fa95da6..968ff9f 100644 --- a/Lotto Journal/Views/PrizeNumberMultipleView.swift +++ b/Lotto Journal/Views/PrizeNumberMultipleView.swift @@ -26,7 +26,7 @@ struct PrizeNumberMultipleView: View { .tracking(10) .foregroundStyle(.white) .multilineTextAlignment(.center) - .background(Color.teal) + .background(Color.accentColor) .clipShape(.rect(cornerRadius: 10)) .offset(x: 0, y: -10) } diff --git a/Lotto Journal/Views/PrizeNumberView.swift b/Lotto Journal/Views/PrizeNumberView.swift index 1a4d1ce..5745a55 100644 --- a/Lotto Journal/Views/PrizeNumberView.swift +++ b/Lotto Journal/Views/PrizeNumberView.swift @@ -20,7 +20,7 @@ struct PrizeNumberView: View { .multilineTextAlignment(.center) .frame(maxWidth: .infinity, alignment: .center) .frame(height: 70) - .background(Color.teal) + .background(Color.accentColor) .clipShape(.rect(cornerRadius: 10)) .offset(x: 0, y: -10) } From ebc59d0554fbcdf1754c4aa2902a4a65dfa24219 Mon Sep 17 00:00:00 2001 From: Theppitak M <141404845+mmmmmob@users.noreply.github.com> Date: Tue, 4 Jun 2024 21:07:19 +0700 Subject: [PATCH 2/5] chore: prepare codebase and #Preview container for next steps --- Lotto Journal.xcodeproj/project.pbxproj | 4 --- Lotto Journal/Lotto_JournalApp.swift | 2 +- Lotto Journal/Models/DrawDate.swift | 2 +- Lotto Journal/Models/Lottery.swift | 2 +- Lotto Journal/Models/Summary.swift | 34 ------------------------ Lotto Journal/Views/MainTabView.swift | 2 +- Lotto Journal/Views/MyLotteryView.swift | 4 --- Lotto Journal/Views/SummaryView.swift | 35 ++++++++++++++++++++----- 8 files changed, 32 insertions(+), 53 deletions(-) delete mode 100644 Lotto Journal/Models/Summary.swift diff --git a/Lotto Journal.xcodeproj/project.pbxproj b/Lotto Journal.xcodeproj/project.pbxproj index f6daa2d..c622fee 100644 --- a/Lotto Journal.xcodeproj/project.pbxproj +++ b/Lotto Journal.xcodeproj/project.pbxproj @@ -10,7 +10,6 @@ 4A068E8D2BFD276000D06D75 /* ResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A068E8C2BFD276000D06D75 /* ResultView.swift */; }; 4A19774B2BFE02870032CC6B /* Prize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A19774A2BFE02870032CC6B /* Prize.swift */; }; 4A2BE6C62C04FA8900387819 /* DrawDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A2BE6C52C04FA8900387819 /* DrawDate.swift */; }; - 4A2BE6C82C04FC5F00387819 /* Summary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A2BE6C72C04FC5F00387819 /* Summary.swift */; }; 4A7255642C032746003D6D89 /* AddMyLotteryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A7255632C032746003D6D89 /* AddMyLotteryView.swift */; }; 4A74D1392C02170C00A5C211 /* Lottery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A74D1382C02170C00A5C211 /* Lottery.swift */; }; 4A7DFE352BFD0526003A3969 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A7DFE342BFD0525003A3969 /* StringExtension.swift */; }; @@ -55,7 +54,6 @@ 4A19774A2BFE02870032CC6B /* Prize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Prize.swift; sourceTree = ""; }; 4A19774C2BFE53DC0032CC6B /* Lotto-Journal-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = "Lotto-Journal-Info.plist"; sourceTree = SOURCE_ROOT; }; 4A2BE6C52C04FA8900387819 /* DrawDate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DrawDate.swift; sourceTree = ""; }; - 4A2BE6C72C04FC5F00387819 /* Summary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Summary.swift; sourceTree = ""; }; 4A7255632C032746003D6D89 /* AddMyLotteryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddMyLotteryView.swift; sourceTree = ""; }; 4A74D1382C02170C00A5C211 /* Lottery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Lottery.swift; sourceTree = ""; }; 4A7DFE342BFD0525003A3969 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = ""; }; @@ -188,7 +186,6 @@ 4A19774A2BFE02870032CC6B /* Prize.swift */, 4A74D1382C02170C00A5C211 /* Lottery.swift */, 4A2BE6C52C04FA8900387819 /* DrawDate.swift */, - 4A2BE6C72C04FC5F00387819 /* Summary.swift */, ); path = Models; sourceTree = ""; @@ -326,7 +323,6 @@ 4AF0975D2BF9DA21003A813B /* Lotto_JournalApp.swift in Sources */, 4A7255642C032746003D6D89 /* AddMyLotteryView.swift in Sources */, 4A2BE6C62C04FA8900387819 /* DrawDate.swift in Sources */, - 4A2BE6C82C04FC5F00387819 /* Summary.swift in Sources */, 4A8C441E2BFB675C000461B9 /* Result.swift in Sources */, 4AF097742BF9E2F0003A813B /* MainTabView.swift in Sources */, 4ABEF1922BFC42D300904D3E /* CheckResultViewModel.swift in Sources */, diff --git a/Lotto Journal/Lotto_JournalApp.swift b/Lotto Journal/Lotto_JournalApp.swift index 1956321..1ba4339 100644 --- a/Lotto Journal/Lotto_JournalApp.swift +++ b/Lotto Journal/Lotto_JournalApp.swift @@ -25,7 +25,7 @@ struct Lotto_JournalApp: App { } init() { - let schema = Schema([Summary.self]) + let schema = Schema([DrawDate.self]) let config = ModelConfiguration("LotteryDB", schema: schema) do { container = try ModelContainer(for: schema, configurations: config) diff --git a/Lotto Journal/Models/DrawDate.swift b/Lotto Journal/Models/DrawDate.swift index ea50cb0..87cc43f 100644 --- a/Lotto Journal/Models/DrawDate.swift +++ b/Lotto Journal/Models/DrawDate.swift @@ -57,7 +57,7 @@ class DrawDate { var totalWon: Int { var total: Int = 0 for lottery in lotteries { - total += lottery.prizePerLottery + total += lottery.prizePerNumber } return total } diff --git a/Lotto Journal/Models/Lottery.swift b/Lotto Journal/Models/Lottery.swift index a4e9cf4..0952742 100644 --- a/Lotto Journal/Models/Lottery.swift +++ b/Lotto Journal/Models/Lottery.swift @@ -29,7 +29,7 @@ class Lottery { return amount * 80 } - var prizePerLottery: Int { + var prizePerNumber: Int { return amountWon * amount } diff --git a/Lotto Journal/Models/Summary.swift b/Lotto Journal/Models/Summary.swift deleted file mode 100644 index d2a36f9..0000000 --- a/Lotto Journal/Models/Summary.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// Summary.swift -// Lotto Journal -// -// Created by Theppitak M. on 28.05.2024. -// - -import Foundation -import SwiftData - -@Model -class Summary { - var drawDates: [DrawDate] - - init(drawDates: [DrawDate]) { - self.drawDates = drawDates - } - - /* - var sumOfProfitAndLoss: Int { - return 0 - } - var percentageOfWinning: Int { - return 0 - } - var allTimeInvestment: Int { - return 0 - } - var allTimePrizeWon: Int { - return 0 - } - */ -} - diff --git a/Lotto Journal/Views/MainTabView.swift b/Lotto Journal/Views/MainTabView.swift index ab25cad..5f0b737 100644 --- a/Lotto Journal/Views/MainTabView.swift +++ b/Lotto Journal/Views/MainTabView.swift @@ -35,7 +35,7 @@ struct MainTabView: View { } .tag(3) }) - .tint(.brown) + .tint(.indigo) .onChange(of: scenePhase) { switch scenePhase { case .active: diff --git a/Lotto Journal/Views/MyLotteryView.swift b/Lotto Journal/Views/MyLotteryView.swift index 408dc72..c32a332 100644 --- a/Lotto Journal/Views/MyLotteryView.swift +++ b/Lotto Journal/Views/MyLotteryView.swift @@ -97,10 +97,6 @@ struct MyLotteryView: View { .foregroundStyle(Color.white) .background(Color.accentColor) .clipShape(Capsule(style: .continuous)) - .overlay( - Capsule(style: .continuous) - .stroke(totalWon > totalInvestment ? .green : .red, lineWidth: 2) - ) } } .headerProminence(.increased) diff --git a/Lotto Journal/Views/SummaryView.swift b/Lotto Journal/Views/SummaryView.swift index c4d37ad..674766c 100644 --- a/Lotto Journal/Views/SummaryView.swift +++ b/Lotto Journal/Views/SummaryView.swift @@ -6,20 +6,41 @@ // import SwiftUI +import SwiftData struct SummaryView: View { + + @Query private var drawDates: [DrawDate] + @Query private var lotteries: [Lottery] + var body: some View { NavigationStack { - ContentUnavailableView( - "Summary Unavailable", - systemImage: "chart.bar.xaxis", - description: Text("Keep using to track your progress") - ) - .navigationTitle("Summary") + Group { + if lotteries.isEmpty { + ContentUnavailableView( + "Summary Unavailable", + systemImage: "chart.bar.xaxis", + description: Text("Keep using to track your progress") + ) + } + else { + Text("Hello, World!") + } + } + .navigationTitle("Summary") } } } #Preview { - SummaryView() + let config = ModelConfiguration(isStoredInMemoryOnly: true) + let container = try! ModelContainer(for: Lottery.self, configurations: config) + + for _ in 1..<5 { + let lottery = Lottery(number: "344555", amount: 2, status: .doesWon, drawDate: DrawDate(date: Date.now), amountWon: 2000) + container.mainContext.insert(lottery) + } + + return SummaryView() + .modelContainer(container) } From 3c7ad19d856b673f53d70679c3d47e05c1ea7a27 Mon Sep 17 00:00:00 2001 From: Theppitak M <141404845+mmmmmob@users.noreply.github.com> Date: Wed, 5 Jun 2024 10:48:47 +0700 Subject: [PATCH 3/5] feat: finish SummaryView before refactoring --- Lotto Journal/Views/SummaryView.swift | 114 +++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 4 deletions(-) diff --git a/Lotto Journal/Views/SummaryView.swift b/Lotto Journal/Views/SummaryView.swift index 674766c..e3d7a4e 100644 --- a/Lotto Journal/Views/SummaryView.swift +++ b/Lotto Journal/Views/SummaryView.swift @@ -13,6 +13,38 @@ struct SummaryView: View { @Query private var drawDates: [DrawDate] @Query private var lotteries: [Lottery] + // Computed Variables for SummaryView + var totalSpending: Int { + var total: Int = 0 + for drawDate in drawDates { + total += drawDate.totalInvestment + } + return total + } + + var totalPrizeWon: Int { + var total: Int = 0 + for drawDate in drawDates { + total += drawDate.totalWon + } + return total + } + + var totalPL: Int { + return totalPrizeWon - totalSpending + } + + var chanceOfWinning: Double { + var percentage: Double = 0.00 + + let numberOfLotteryBought = Double(lotteries.count) + let numberOfLotteryWon = Double(lotteries.filter({$0.status == .doesWon}).count) + + percentage = (numberOfLotteryWon / numberOfLotteryBought) * 100 + + return percentage + } + var body: some View { NavigationStack { Group { @@ -24,7 +56,81 @@ struct SummaryView: View { ) } else { - Text("Hello, World!") + RoundedRectangle(cornerRadius: 10) + .fill(Color.accentColor.opacity(0.9)) + .padding(.horizontal) + .frame(maxWidth: .infinity, maxHeight: 150) + .overlay { + VStack(alignment: .trailing) { + Text("📈 Total Profit / Loss") + .font(.system(.caption, design: .default, weight: .regular)) + .foregroundStyle(.secondary) + Text("฿\(totalPL.delimiter)") + .font(.system(.largeTitle, design: .rounded, weight: .bold)) + .foregroundStyle(totalPL > 0 ? .green : .red) + } + .frame(maxWidth: .infinity, alignment: .trailing) + .foregroundStyle(.white) + .padding(40) + } + RoundedRectangle(cornerRadius: 10) + .fill(Color.accentColor.opacity(0.9)) + .frame(maxWidth: .infinity, maxHeight: 150) + .padding(.horizontal) + .overlay { + VStack(alignment: .trailing) { + Text("⛅️ Chance of Winning") + .font(.system(.caption, design: .default, weight: .regular)) + .foregroundStyle(.secondary) + Text("\(chanceOfWinning, specifier: "%.2f")%") + .font(.system(.largeTitle, design: .rounded, weight: .bold)) + .foregroundStyle(chanceOfWinning < 50 ? .red : .green) + } + .frame(maxWidth: .infinity, alignment: .trailing) + .foregroundStyle(.white) + .padding(40) + } + HStack { + RoundedRectangle(cornerRadius: 10) + .fill(Color.accentColor.opacity(0.9)) + .frame(maxWidth: .infinity, maxHeight: 150) + .overlay { + VStack(alignment: .trailing) { + Text("💸 Total Spending") + .font(.system(.caption, design: .default, weight: .regular)) + .foregroundStyle(.secondary) + Text("฿\(totalSpending.delimiter)") + .font(.system(.largeTitle, design: .rounded, weight: .bold)) + .foregroundStyle(.white) + .lineLimit(1) + .minimumScaleFactor(0.5) + } + .frame(maxWidth: .infinity, alignment: .trailing) + .foregroundStyle(.white) + .padding(.horizontal) + } + .padding(.leading) + RoundedRectangle(cornerRadius: 10) + .fill(Color.accentColor.opacity(0.9)) + .frame(maxWidth: .infinity, maxHeight: 150) + .overlay { + VStack(alignment: .trailing) { + Text("🏆 Total Prize Won") + .font(.system(.caption, design: .default, weight: .regular)) + .foregroundStyle(.secondary) + Text("฿\(totalPrizeWon.delimiter)") + .font(.system(.largeTitle, design: .rounded, weight: .bold)) + .foregroundStyle(.white) + .lineLimit(1) + .minimumScaleFactor(0.5) + } + .frame(maxWidth: .infinity, alignment: .trailing) + .foregroundStyle(.white) + .padding(.horizontal) + } + .padding(.trailing) + } + Spacer() } } .navigationTitle("Summary") @@ -35,12 +141,12 @@ struct SummaryView: View { #Preview { let config = ModelConfiguration(isStoredInMemoryOnly: true) let container = try! ModelContainer(for: Lottery.self, configurations: config) - + for _ in 1..<5 { let lottery = Lottery(number: "344555", amount: 2, status: .doesWon, drawDate: DrawDate(date: Date.now), amountWon: 2000) container.mainContext.insert(lottery) } - + return SummaryView() - .modelContainer(container) + .modelContainer(container) } From 936a222dcb494d843ec7f9f9425067e2c51e35bd Mon Sep 17 00:00:00 2001 From: Theppitak M <141404845+mmmmmob@users.noreply.github.com> Date: Wed, 5 Jun 2024 10:59:22 +0700 Subject: [PATCH 4/5] style: fix opacity and title text color --- Lotto Journal/Views/SummaryView.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Lotto Journal/Views/SummaryView.swift b/Lotto Journal/Views/SummaryView.swift index e3d7a4e..7acfd3d 100644 --- a/Lotto Journal/Views/SummaryView.swift +++ b/Lotto Journal/Views/SummaryView.swift @@ -57,14 +57,14 @@ struct SummaryView: View { } else { RoundedRectangle(cornerRadius: 10) - .fill(Color.accentColor.opacity(0.9)) + .fill(Color.accentColor.opacity(0.7)) .padding(.horizontal) .frame(maxWidth: .infinity, maxHeight: 150) .overlay { VStack(alignment: .trailing) { Text("📈 Total Profit / Loss") .font(.system(.caption, design: .default, weight: .regular)) - .foregroundStyle(.secondary) + .foregroundStyle(.primary) Text("฿\(totalPL.delimiter)") .font(.system(.largeTitle, design: .rounded, weight: .bold)) .foregroundStyle(totalPL > 0 ? .green : .red) @@ -74,14 +74,14 @@ struct SummaryView: View { .padding(40) } RoundedRectangle(cornerRadius: 10) - .fill(Color.accentColor.opacity(0.9)) + .fill(Color.accentColor.opacity(0.7)) .frame(maxWidth: .infinity, maxHeight: 150) .padding(.horizontal) .overlay { VStack(alignment: .trailing) { Text("⛅️ Chance of Winning") .font(.system(.caption, design: .default, weight: .regular)) - .foregroundStyle(.secondary) + .foregroundStyle(.primary) Text("\(chanceOfWinning, specifier: "%.2f")%") .font(.system(.largeTitle, design: .rounded, weight: .bold)) .foregroundStyle(chanceOfWinning < 50 ? .red : .green) @@ -92,13 +92,13 @@ struct SummaryView: View { } HStack { RoundedRectangle(cornerRadius: 10) - .fill(Color.accentColor.opacity(0.9)) + .fill(Color.accentColor.opacity(0.7)) .frame(maxWidth: .infinity, maxHeight: 150) .overlay { VStack(alignment: .trailing) { Text("💸 Total Spending") .font(.system(.caption, design: .default, weight: .regular)) - .foregroundStyle(.secondary) + .foregroundStyle(.primary) Text("฿\(totalSpending.delimiter)") .font(.system(.largeTitle, design: .rounded, weight: .bold)) .foregroundStyle(.white) @@ -111,13 +111,13 @@ struct SummaryView: View { } .padding(.leading) RoundedRectangle(cornerRadius: 10) - .fill(Color.accentColor.opacity(0.9)) + .fill(Color.accentColor.opacity(0.7)) .frame(maxWidth: .infinity, maxHeight: 150) .overlay { VStack(alignment: .trailing) { Text("🏆 Total Prize Won") .font(.system(.caption, design: .default, weight: .regular)) - .foregroundStyle(.secondary) + .foregroundStyle(.primary) Text("฿\(totalPrizeWon.delimiter)") .font(.system(.largeTitle, design: .rounded, weight: .bold)) .foregroundStyle(.white) From c242edac0a9e2ef2c0bc941e5bb32bb6f16c1934 Mon Sep 17 00:00:00 2001 From: Theppitak M <141404845+mmmmmob@users.noreply.github.com> Date: Wed, 5 Jun 2024 11:23:37 +0700 Subject: [PATCH 5/5] refactor: add SummaryWidgetHalfView --- Lotto Journal.xcodeproj/project.pbxproj | 4 ++ Lotto Journal/Views/SummaryView.swift | 38 +----------------- .../Views/SummaryWidgetHalfView.swift | 39 +++++++++++++++++++ 3 files changed, 45 insertions(+), 36 deletions(-) create mode 100644 Lotto Journal/Views/SummaryWidgetHalfView.swift diff --git a/Lotto Journal.xcodeproj/project.pbxproj b/Lotto Journal.xcodeproj/project.pbxproj index c622fee..917ad83 100644 --- a/Lotto Journal.xcodeproj/project.pbxproj +++ b/Lotto Journal.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ 4AADFB5C2C03816F00AE57E6 /* OTPView in Frameworks */ = {isa = PBXBuildFile; productRef = 4AADFB5B2C03816F00AE57E6 /* OTPView */; }; 4AADFB5F2C0392C100AE57E6 /* OTPView in Frameworks */ = {isa = PBXBuildFile; productRef = 4AADFB5E2C0392C100AE57E6 /* OTPView */; }; 4ABEDA8B2C0EBB4E00D4174B /* IntExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ABEDA8A2C0EBB4E00D4174B /* IntExtension.swift */; }; + 4ABEDA8F2C101B4300D4174B /* SummaryWidgetHalfView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ABEDA8E2C101B4300D4174B /* SummaryWidgetHalfView.swift */; }; 4ABEF1922BFC42D300904D3E /* CheckResultViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ABEF1912BFC42D300904D3E /* CheckResultViewModel.swift */; }; 4ABEF1962BFC6F5500904D3E /* PrizeHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ABEF1952BFC6F5500904D3E /* PrizeHeaderView.swift */; }; 4ABEF1982BFC715E00904D3E /* PrizeNumberView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ABEF1972BFC715E00904D3E /* PrizeNumberView.swift */; }; @@ -62,6 +63,7 @@ 4A8C440C2BFAFA75000461B9 /* DateExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateExtension.swift; sourceTree = ""; }; 4A8C441D2BFB675B000461B9 /* Result.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = ""; }; 4ABEDA8A2C0EBB4E00D4174B /* IntExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntExtension.swift; sourceTree = ""; }; + 4ABEDA8E2C101B4300D4174B /* SummaryWidgetHalfView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SummaryWidgetHalfView.swift; sourceTree = ""; }; 4ABEF1912BFC42D300904D3E /* CheckResultViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckResultViewModel.swift; sourceTree = ""; }; 4ABEF1952BFC6F5500904D3E /* PrizeHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrizeHeaderView.swift; sourceTree = ""; }; 4ABEF1972BFC715E00904D3E /* PrizeNumberView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrizeNumberView.swift; sourceTree = ""; }; @@ -135,6 +137,7 @@ 4AD9DD4C2C04A59E00EE7866 /* Summary */ = { isa = PBXGroup; children = ( + 4ABEDA8E2C101B4300D4174B /* SummaryWidgetHalfView.swift */, ); name = Summary; sourceTree = ""; @@ -312,6 +315,7 @@ 4ABEF1962BFC6F5500904D3E /* PrizeHeaderView.swift in Sources */, 4A74D1392C02170C00A5C211 /* Lottery.swift in Sources */, 4ABEF1982BFC715E00904D3E /* PrizeNumberView.swift in Sources */, + 4ABEDA8F2C101B4300D4174B /* SummaryWidgetHalfView.swift in Sources */, 4AF0975F2BF9DA21003A813B /* MyLotteryView.swift in Sources */, 4AFEAC382BFF795100BA40AD /* QuickActionType.swift in Sources */, 4ABEDA8B2C0EBB4E00D4174B /* IntExtension.swift in Sources */, diff --git a/Lotto Journal/Views/SummaryView.swift b/Lotto Journal/Views/SummaryView.swift index 7acfd3d..884135a 100644 --- a/Lotto Journal/Views/SummaryView.swift +++ b/Lotto Journal/Views/SummaryView.swift @@ -91,43 +91,9 @@ struct SummaryView: View { .padding(40) } HStack { - RoundedRectangle(cornerRadius: 10) - .fill(Color.accentColor.opacity(0.7)) - .frame(maxWidth: .infinity, maxHeight: 150) - .overlay { - VStack(alignment: .trailing) { - Text("💸 Total Spending") - .font(.system(.caption, design: .default, weight: .regular)) - .foregroundStyle(.primary) - Text("฿\(totalSpending.delimiter)") - .font(.system(.largeTitle, design: .rounded, weight: .bold)) - .foregroundStyle(.white) - .lineLimit(1) - .minimumScaleFactor(0.5) - } - .frame(maxWidth: .infinity, alignment: .trailing) - .foregroundStyle(.white) - .padding(.horizontal) - } + SummaryWidgetHalfView(numberToShow: totalSpending, headerText: "💸 Total Spending") .padding(.leading) - RoundedRectangle(cornerRadius: 10) - .fill(Color.accentColor.opacity(0.7)) - .frame(maxWidth: .infinity, maxHeight: 150) - .overlay { - VStack(alignment: .trailing) { - Text("🏆 Total Prize Won") - .font(.system(.caption, design: .default, weight: .regular)) - .foregroundStyle(.primary) - Text("฿\(totalPrizeWon.delimiter)") - .font(.system(.largeTitle, design: .rounded, weight: .bold)) - .foregroundStyle(.white) - .lineLimit(1) - .minimumScaleFactor(0.5) - } - .frame(maxWidth: .infinity, alignment: .trailing) - .foregroundStyle(.white) - .padding(.horizontal) - } + SummaryWidgetHalfView(numberToShow: totalPrizeWon, headerText: "🏆 Total Prize Won") .padding(.trailing) } Spacer() diff --git a/Lotto Journal/Views/SummaryWidgetHalfView.swift b/Lotto Journal/Views/SummaryWidgetHalfView.swift new file mode 100644 index 0000000..d780749 --- /dev/null +++ b/Lotto Journal/Views/SummaryWidgetHalfView.swift @@ -0,0 +1,39 @@ +// +// SummaryWidgetHalfView.swift +// Lotto Journal +// +// Created by Theppitak M. on 05.06.2024. +// + +import SwiftUI + +struct SummaryWidgetHalfView: View { + + var numberToShow: Int + var headerText: String + + var body: some View { + RoundedRectangle(cornerRadius: 10) + .fill(Color.accentColor.opacity(0.7)) + .frame(maxWidth: .infinity, maxHeight: 150) + .overlay { + VStack(alignment: .trailing) { + Text(headerText) + .font(.system(.caption, design: .default, weight: .regular)) + .foregroundStyle(.primary) + Text("฿\(numberToShow.delimiter)") + .font(.system(.largeTitle, design: .rounded, weight: .bold)) + .foregroundStyle(.white) + .lineLimit(1) + .minimumScaleFactor(0.5) + } + .frame(maxWidth: .infinity, alignment: .trailing) + .foregroundStyle(.white) + .padding(.horizontal) + } + } +} + +#Preview { + SummaryWidgetHalfView(numberToShow: 30000, headerText: "💸 Total Spending") +}