Skip to content

Commit

Permalink
Merge pull request #15 from mmmmmob/summary-view
Browse files Browse the repository at this point in the history
Daily Merge: Finish SummaryView
  • Loading branch information
mmmmmob authored Jun 5, 2024
2 parents 922abec + c242eda commit 14ca6f3
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 61 deletions.
14 changes: 7 additions & 7 deletions Lotto Journal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -23,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 */; };
Expand Down Expand Up @@ -55,7 +55,6 @@
4A19774A2BFE02870032CC6B /* Prize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Prize.swift; sourceTree = "<group>"; };
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 = "<group>"; };
4A2BE6C72C04FC5F00387819 /* Summary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Summary.swift; sourceTree = "<group>"; };
4A7255632C032746003D6D89 /* AddMyLotteryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddMyLotteryView.swift; sourceTree = "<group>"; };
4A74D1382C02170C00A5C211 /* Lottery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Lottery.swift; sourceTree = "<group>"; };
4A7DFE342BFD0525003A3969 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
Expand All @@ -64,6 +63,7 @@
4A8C440C2BFAFA75000461B9 /* DateExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateExtension.swift; sourceTree = "<group>"; };
4A8C441D2BFB675B000461B9 /* Result.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = "<group>"; };
4ABEDA8A2C0EBB4E00D4174B /* IntExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntExtension.swift; sourceTree = "<group>"; };
4ABEDA8E2C101B4300D4174B /* SummaryWidgetHalfView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SummaryWidgetHalfView.swift; sourceTree = "<group>"; };
4ABEF1912BFC42D300904D3E /* CheckResultViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckResultViewModel.swift; sourceTree = "<group>"; };
4ABEF1952BFC6F5500904D3E /* PrizeHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrizeHeaderView.swift; sourceTree = "<group>"; };
4ABEF1972BFC715E00904D3E /* PrizeNumberView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrizeNumberView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -134,11 +134,12 @@
name = CheckResult;
sourceTree = "<group>";
};
4AD9DD4C2C04A59E00EE7866 /* MyLottery */ = {
4AD9DD4C2C04A59E00EE7866 /* Summary */ = {
isa = PBXGroup;
children = (
4ABEDA8E2C101B4300D4174B /* SummaryWidgetHalfView.swift */,
);
name = MyLottery;
name = Summary;
sourceTree = "<group>";
};
4AF097502BF9DA21003A813B = {
Expand Down Expand Up @@ -188,7 +189,6 @@
4A19774A2BFE02870032CC6B /* Prize.swift */,
4A74D1382C02170C00A5C211 /* Lottery.swift */,
4A2BE6C52C04FA8900387819 /* DrawDate.swift */,
4A2BE6C72C04FC5F00387819 /* Summary.swift */,
);
path = Models;
sourceTree = "<group>";
Expand All @@ -206,7 +206,7 @@
4AF0976F2BF9DB75003A813B /* Components */ = {
isa = PBXGroup;
children = (
4AD9DD4C2C04A59E00EE7866 /* MyLottery */,
4AD9DD4C2C04A59E00EE7866 /* Summary */,
4ABEF1992BFC716500904D3E /* CheckResult */,
);
name = Components;
Expand Down Expand Up @@ -315,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 */,
Expand All @@ -326,7 +327,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 */,
Expand Down
2 changes: 1 addition & 1 deletion Lotto Journal/Lotto_JournalApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Lotto Journal/Models/DrawDate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions Lotto Journal/Models/Lottery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Lottery {
return amount * 80
}

var prizePerLottery: Int {
var prizePerNumber: Int {
return amountWon * amount
}

Expand Down Expand Up @@ -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:
Expand Down
34 changes: 0 additions & 34 deletions Lotto Journal/Models/Summary.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Lotto Journal/Views/AddMyLotteryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -55,7 +55,7 @@ struct AddMyLotteryView: View {
}
.buttonStyle(.borderedProminent)
.disabled(number.isEmpty)
.tint(.teal)
.tint(.accentColor)
.controlSize(.large)
.buttonBorderShape(.roundedRectangle)
.padding(.top)
Expand Down
2 changes: 1 addition & 1 deletion Lotto Journal/Views/MainTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct MainTabView: View {
}
.tag(3)
})
.tint(.teal)
.tint(.indigo)
.onChange(of: scenePhase) {
switch scenePhase {
case .active:
Expand Down
14 changes: 10 additions & 4 deletions Lotto Journal/Views/MyLotteryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -82,15 +82,21 @@ 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))
}
}
.headerProminence(.increased)
Expand Down
2 changes: 1 addition & 1 deletion Lotto Journal/Views/PrizeNumberMultipleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Lotto Journal/Views/PrizeNumberView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
107 changes: 100 additions & 7 deletions Lotto Journal/Views/SummaryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,113 @@
//

import SwiftUI
import SwiftData

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 {
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 {
RoundedRectangle(cornerRadius: 10)
.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(.primary)
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.7))
.frame(maxWidth: .infinity, maxHeight: 150)
.padding(.horizontal)
.overlay {
VStack(alignment: .trailing) {
Text("⛅️ Chance of Winning")
.font(.system(.caption, design: .default, weight: .regular))
.foregroundStyle(.primary)
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 {
SummaryWidgetHalfView(numberToShow: totalSpending, headerText: "💸 Total Spending")
.padding(.leading)
SummaryWidgetHalfView(numberToShow: totalPrizeWon, headerText: "🏆 Total Prize Won")
.padding(.trailing)
}
Spacer()
}
}
.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)
}
39 changes: 39 additions & 0 deletions Lotto Journal/Views/SummaryWidgetHalfView.swift
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 14ca6f3

Please sign in to comment.