diff --git a/Sources/AllInApp/AllIn/Components/AllcoinsCounter.swift b/Sources/AllInApp/AllIn/Components/AllcoinsCounter.swift index 8dd954a..efd2e6b 100644 --- a/Sources/AllInApp/AllIn/Components/AllcoinsCounter.swift +++ b/Sources/AllInApp/AllIn/Components/AllcoinsCounter.swift @@ -19,6 +19,7 @@ struct AllcoinsCounter: View { .resizable() .frame(width: 17, height: 17, alignment: .leading) Text(String(appStateContainer.user?.nbCoins ?? 0)) + .contentTransition(.numericText()) .fontWeight(.black) .foregroundColor(foregroundColor) } diff --git a/Sources/AllInApp/AllIn/Components/BetLineLoading.swift b/Sources/AllInApp/AllIn/Components/BetLineLoading.swift index 2855892..95ac55d 100644 --- a/Sources/AllInApp/AllIn/Components/BetLineLoading.swift +++ b/Sources/AllInApp/AllIn/Components/BetLineLoading.swift @@ -10,6 +10,7 @@ import Model struct BetLineLoading: View { + @State var showInfos: Bool = false var participations: [Participation] var value: CGFloat { @@ -33,7 +34,7 @@ struct BetLineLoading: View { var body: some View { GeometryReader { geometry in - VStack(alignment: .leading,spacing: 0){ + VStack(alignment: .leading,spacing: 0) { HStack(spacing: 5){ Text("OUI") .font(.system(size: 25)) @@ -44,7 +45,6 @@ struct BetLineLoading: View { .font(.system(size: 25)) .fontWeight(.bold) .foregroundColor(AllInColors.pink100) - } ZStack(alignment: .leading) { HStack{ @@ -66,83 +66,104 @@ struct BetLineLoading: View { } } - VStack(spacing: 1){ - HStack(spacing: 5){ - Image("blueAllCoinIcon") - .resizable() - .frame(width:12, height: 12) - Text(yesParticipations.reduce(0, {x,y in x + y.stake}).description) - .font(.system(size: 15)) - .fontWeight(.bold) - .foregroundColor(AllInColors.blue200) - Spacer() - Text(noParticipations.reduce(0, {x,y in x + y.stake}).description) - .font(.system(size: 15)) - .fontWeight(.bold) - .foregroundColor(AllInColors.pink100) - Image("pinkAllCoinIcon") - .resizable() - .frame(width: 12, height: 12) - - } - HStack(spacing: 5){ - Image("bluePersonIcon") - .resizable() - .frame(width: 12, height: 12) - Text(yesParticipations.count.description) - .font(.system(size: 15)) - .fontWeight(.bold) - .foregroundColor(AllInColors.blue200) - Spacer() - Text(noParticipations.count.description) - .font(.system(size: 15)) - .fontWeight(.bold) - .foregroundColor(AllInColors.pink100) - Image("pinkPersonIcon") - .resizable() - .frame(width: 12, height: 12) - - } - HStack(spacing: 5){ - Image("blueBadgeIcon") - .resizable() - .frame(width: 12, height: 12) - Text(yesParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0") - .font(.system(size: 15)) - .fontWeight(.bold) - .foregroundColor(AllInColors.blue200) - Spacer() - Text(noParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0") - .font(.system(size: 15)) - .fontWeight(.bold) - .foregroundColor(AllInColors.pink100) - Image("pinkBadgeIcon") - .resizable() - .frame(width: 12, height: 12) - + .padding(.bottom, 5) + + HStack { + Spacer() + Text("Détails") + .textStyle(weight: .medium, color: AllInColors.primaryTextColor, size: 10) + Image(showInfos ? "chevronUpIcon" : "chevronDownIcon") + .resizable() + .frame(width: 10, height: 7) + .scaledToFill() + } + .onTapGesture { + withAnimation { + showInfos.toggle() } - HStack(spacing: 5){ - Image("blueTrophyIcon") - .resizable() - .frame(width: 12, height: 12) - Text("1.2") - .font(.system(size: 15)) - .fontWeight(.bold) - .foregroundColor(AllInColors.blue200) - Spacer() - Text("1.2") - .font(.system(size: 15)) - .fontWeight(.bold) - .foregroundColor(AllInColors.pink100) - Image("pinkTrophyIcon") - .resizable() - .frame(width:12, height: 12) - + } + .padding(.bottom, 5) + .padding(.trailing, 5) + + if showInfos { + VStack(spacing: 1){ + HStack(spacing: 5){ + Image("blueAllCoinIcon") + .resizable() + .frame(width:12, height: 12) + Text(yesParticipations.reduce(0, {x,y in x + y.stake}).description) + .font(.system(size: 15)) + .fontWeight(.bold) + .foregroundColor(AllInColors.blue200) + Spacer() + Text(noParticipations.reduce(0, {x,y in x + y.stake}).description) + .font(.system(size: 15)) + .fontWeight(.bold) + .foregroundColor(AllInColors.pink100) + Image("pinkAllCoinIcon") + .resizable() + .frame(width: 12, height: 12) + + } + HStack(spacing: 5){ + Image("bluePersonIcon") + .resizable() + .frame(width: 12, height: 12) + Text(yesParticipations.count.description) + .font(.system(size: 15)) + .fontWeight(.bold) + .foregroundColor(AllInColors.blue200) + Spacer() + Text(noParticipations.count.description) + .font(.system(size: 15)) + .fontWeight(.bold) + .foregroundColor(AllInColors.pink100) + Image("pinkPersonIcon") + .resizable() + .frame(width: 12, height: 12) + + } + HStack(spacing: 5){ + Image("blueBadgeIcon") + .resizable() + .frame(width: 12, height: 12) + Text(yesParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0") + .font(.system(size: 15)) + .fontWeight(.bold) + .foregroundColor(AllInColors.blue200) + Spacer() + Text(noParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0") + .font(.system(size: 15)) + .fontWeight(.bold) + .foregroundColor(AllInColors.pink100) + Image("pinkBadgeIcon") + .resizable() + .frame(width: 12, height: 12) + + } + HStack(spacing: 5){ + Image("blueTrophyIcon") + .resizable() + .frame(width: 12, height: 12) + Text("1.2") + .font(.system(size: 15)) + .fontWeight(.bold) + .foregroundColor(AllInColors.blue200) + Spacer() + Text("1.2") + .font(.system(size: 15)) + .fontWeight(.bold) + .foregroundColor(AllInColors.pink100) + Image("pinkTrophyIcon") + .resizable() + .frame(width:12, height: 12) + + } } } + Spacer() } - - }.frame(height: 140) + } } } diff --git a/Sources/AllInApp/AllIn/ContentView.swift b/Sources/AllInApp/AllIn/ContentView.swift index a8f4a2d..96958ea 100644 --- a/Sources/AllInApp/AllIn/ContentView.swift +++ b/Sources/AllInApp/AllIn/ContentView.swift @@ -7,11 +7,14 @@ import SwiftUI import DependencyInjection +import Model struct ContentView: View { @State private var show = false + @State private var gain = 0 @Inject var authService: IAuthService + @Inject var manager: Manager @ObservedObject var loggedState = AppStateContainer.shared.loggedState var body: some View { @@ -30,16 +33,23 @@ struct ContentView: View { } .onAppear { authService.refreshAuthentication() - DispatchQueue.main.asyncAfter(deadline: .now() + 2) { - withAnimation { - show = true + } + .onChange(of: loggedState.connectedUser) { _ in + if loggedState.connectedUser { + manager.getTodayGifts() { status, gained in + if status == 200 { + withAnimation { + show = true + gain = gained + } + } } } } .overlay( Group { if show { - DailyGiftPage(show: $show) + DailyGiftPage(show: $show, gain: $gain) .transition(.opacity) } } diff --git a/Sources/AllInApp/AllIn/Services/IAuthService.swift b/Sources/AllInApp/AllIn/Services/Protocols/IAuthService.swift similarity index 100% rename from Sources/AllInApp/AllIn/Services/IAuthService.swift rename to Sources/AllInApp/AllIn/Services/Protocols/IAuthService.swift diff --git a/Sources/AllInApp/AllIn/Views/DailyGiftPage.swift b/Sources/AllInApp/AllIn/Views/DailyGiftPage.swift index 62e9390..fa455bd 100644 --- a/Sources/AllInApp/AllIn/Views/DailyGiftPage.swift +++ b/Sources/AllInApp/AllIn/Views/DailyGiftPage.swift @@ -19,6 +19,7 @@ struct DailyGiftPage: View { @State private var scale2: CGFloat = 0 @State private var rotate: CGFloat = 1 @Binding var show: Bool + @Binding var gain: Int var body: some View { GeometryReader { geometry in @@ -94,6 +95,9 @@ struct DailyGiftPage: View { switch step { case .first: step = .end + withAnimation { + AppStateContainer.shared.user?.nbCoins += gain + } case .end: show = false step = .first @@ -115,6 +119,6 @@ struct DailyGiftPage: View { struct DailyGiftPage_Previews: PreviewProvider { static var previews: some View { - DailyGiftPage(show: .constant(false)) + DailyGiftPage(show: .constant(false), gain: .constant(20)) } } diff --git a/Sources/AllInApp/AllIn/Views/MainView.swift b/Sources/AllInApp/AllIn/Views/MainView.swift index 5dae676..eceb420 100644 --- a/Sources/AllInApp/AllIn/Views/MainView.swift +++ b/Sources/AllInApp/AllIn/Views/MainView.swift @@ -67,8 +67,3 @@ struct MainView: View { } } } -struct MainView_Previews: PreviewProvider { - static var previews: some View { - MainView(page: "Bet") - } -} diff --git a/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj b/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj index 292d1f0..d5a9890 100644 --- a/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj +++ b/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj @@ -212,6 +212,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + EC1D15402B715A7A0094833E /* Protocols */ = { + isa = PBXGroup; + children = ( + EC6B96CB2B24B7E500FC1C58 /* IAuthService.swift */, + ); + path = Protocols; + sourceTree = ""; + }; EC6B968F2B24B4CC00FC1C58 = { isa = PBXGroup; children = ( @@ -281,7 +289,7 @@ EC6B96CA2B24B7B300FC1C58 /* Services */ = { isa = PBXGroup; children = ( - EC6B96CB2B24B7E500FC1C58 /* IAuthService.swift */, + EC1D15402B715A7A0094833E /* Protocols */, EC6B96D02B24BAE800FC1C58 /* AuthService.swift */, ); path = Services; diff --git a/Sources/Api/Sources/Api/UserApiManager.swift b/Sources/Api/Sources/Api/UserApiManager.swift index c10fe43..d5d5a33 100644 --- a/Sources/Api/Sources/Api/UserApiManager.swift +++ b/Sources/Api/Sources/Api/UserApiManager.swift @@ -29,7 +29,7 @@ public struct UserApiManager: UserDataManager { request.httpMethod = "POST" request.setValue("application/json", forHTTPHeaderField: "Content-Type") request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") - + let json = FactoryApiBet().toResponse(bet: bet) if let jsonData = try? JSONSerialization.data(withJSONObject: json, options: []){ @@ -47,20 +47,45 @@ public struct UserApiManager: UserDataManager { fatalError("Not implemented yet") } + public func getGifts(completion : @escaping (Int, Int)-> ()) { + let url = URL(string: allInApi + "users/gift")! + + var request = URLRequest(url: url) + request.httpMethod = "GET" + request.setValue("application/json", forHTTPHeaderField: "Content-Type") + request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") + + URLSession.shared.dataTask(with: request) { data, response, error in + if let data = data { + print ("ALLIN : get gifts of the day") + if let httpResponse = response as? HTTPURLResponse { + if httpResponse.statusCode == 200 { + if let stringValue = String(data: data, encoding: .utf8), let intValue = Int(stringValue) { + completion(httpResponse.statusCode, intValue) + } + } else { + completion(httpResponse.statusCode, 0) + } + print(httpResponse.statusCode) + } + } + }.resume() + } + public func getOldBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) { fatalError("Not implemented yet") } public func getCurrentBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) { let url = URL(string: allInApi + "bets/current")! - + var request = URLRequest(url: url) request.httpMethod = "GET" request.setValue("application/json", forHTTPHeaderField: "Content-Type") request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") - + var bets: [Bet] = [] - + URLSession.shared.dataTask(with: request) { data, response, error in if let data = data { print ("ALLIN : get current bets") @@ -87,7 +112,7 @@ public struct UserApiManager: UserDataManager { request.httpMethod = "POST" request.setValue("application/json", forHTTPHeaderField: "Content-Type") request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") - + let json: [String: Any] = [ "betId": id, "answer": answer, diff --git a/Sources/Model/Sources/Model/Manager.swift b/Sources/Model/Sources/Model/Manager.swift index 5f65694..c619123 100644 --- a/Sources/Model/Sources/Model/Manager.swift +++ b/Sources/Model/Sources/Model/Manager.swift @@ -51,4 +51,10 @@ public struct Manager { completion(status) } } + + public func getTodayGifts(completion : @escaping (Int, Int)-> ()) { + userDataManager.getGifts() { status, gain in + completion(status, gain) + } + } } diff --git a/Sources/Model/Sources/Model/UserDataManager.swift b/Sources/Model/Sources/Model/UserDataManager.swift index ff132db..c72af02 100644 --- a/Sources/Model/Sources/Model/UserDataManager.swift +++ b/Sources/Model/Sources/Model/UserDataManager.swift @@ -11,6 +11,7 @@ public protocol UserDataManager { func getBets(withIndex index: Int, withCount count: Int) -> [Bet] func addBet(bet: Bet, completion : @escaping (Int)-> ()) func getFriends() -> [User] + func getGifts(completion : @escaping (Int, Int)-> ()) func getOldBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) func getCurrentBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) func addParticipation(withId id: String, withAnswer answer: String, andStake stake: Int, completion : @escaping (Int)-> ())