From 3a447e62d5acb03fce2a43175fe7b0f342bef7f7 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Wed, 19 Jun 2024 11:10:38 +0200 Subject: [PATCH 1/4] fix parallel groupstage --- .../Views/Planning/PlanningSettingsView.swift | 72 +++++++++++-------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/PadelClub/Views/Planning/PlanningSettingsView.swift b/PadelClub/Views/Planning/PlanningSettingsView.swift index 633c918..4a005f1 100644 --- a/PadelClub/Views/Planning/PlanningSettingsView.swift +++ b/PadelClub/Views/Planning/PlanningSettingsView.swift @@ -18,18 +18,20 @@ struct PlanningSettingsView: View { @State private var schedulingDone: Bool = false @State private var showOptions: Bool = false @State private var issueFound: Bool = false + @State private var parallelType: Bool = false init(tournament: Tournament) { self.tournament = tournament if let matchScheduler = tournament.matchScheduler() { - if matchScheduler.groupStageChunkCount == nil { - matchScheduler.groupStageChunkCount = tournament.getGroupStageChunkValue() - } - self.matchScheduler = matchScheduler - self._groupStageChunkCount = State(wrappedValue: matchScheduler.groupStageChunkCount ?? tournament.getGroupStageChunkValue()) + if matchScheduler.groupStageChunkCount != nil { + _parallelType = .init(wrappedValue: true) + _groupStageChunkCount = State(wrappedValue: matchScheduler.groupStageChunkCount!) + } else { + _groupStageChunkCount = State(wrappedValue: tournament.getGroupStageChunkValue()) + } } else { - self.matchScheduler = MatchScheduler(tournament: tournament.id, groupStageChunkCount: tournament.getGroupStageChunkValue()) + self.matchScheduler = MatchScheduler(tournament: tournament.id) self._groupStageChunkCount = State(wrappedValue: tournament.getGroupStageChunkValue()) } } @@ -93,28 +95,11 @@ struct PlanningSettingsView: View { .foregroundStyle(.logoRed) } - if tournament.groupStageCount > 0 { - Section { - TournamentFieldsManagerView(localizedStringKey: "Poule en parallèle", count: $groupStageChunkCount, max: tournament.groupStageCount) - .onChange(of: groupStageChunkCount) { - matchScheduler.groupStageChunkCount = groupStageChunkCount - } - } footer: { - NavigationLink { - _optionsView() - } label: { - Text("Voir les options avancées") - .underline() - .foregroundStyle(.master) - } - } - } else { - Section { - NavigationLink { - _optionsView() - } label: { - Text("Voir les options avancées") - } + Section { + NavigationLink { + _optionsView() + } label: { + Text("Voir les options avancées") } } @@ -219,6 +204,37 @@ struct PlanningSettingsView: View { @ViewBuilder private func _optionsView() -> some View { List { + if tournament.groupStageCount > 0 { + Section { + Picker(selection: $parallelType) { + Text("Auto.").tag(false) + Text("Manuel").tag(true) + } label: { + Text("Poules en parallèle") + let value = tournament.getGroupStageChunkValue() + if parallelType == false, value > 1 { + Text("\(value.formatted()) poules commenceront en parallèle") + } + } + .onChange(of: parallelType) { + if parallelType { + groupStageChunkCount = tournament.getGroupStageChunkValue() + } else { + matchScheduler.groupStageChunkCount = nil + } + } + + if parallelType { + TournamentFieldsManagerView(localizedStringKey: "Poule en parallèle", count: $groupStageChunkCount, max: tournament.groupStageCount) + .onChange(of: groupStageChunkCount) { + matchScheduler.groupStageChunkCount = groupStageChunkCount + } + } + } footer: { + Text("Vous pouvez indiquer le nombre de poule démarrant en même temps.") + } + } + Section { Toggle(isOn: $matchScheduler.overrideCourtsUnavailability) { Text("Ne pas tenir compte des autres épreuves") From 9d1e3e7bbcb91d132a203a26c5ae51c322f836b5 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Wed, 19 Jun 2024 16:08:09 +0200 Subject: [PATCH 2/4] add contact support --- PadelClub.xcodeproj/project.pbxproj | 4 ++++ PadelClub/Info.plist | 4 ++-- .../Navigation/Agenda/ActivityView.swift | 4 +++- .../Navigation/Toolbox/ToolboxView.swift | 11 +++++---- .../Views/Shared/SupportButtonView.swift | 23 +++++++++++++++++++ PadelClub/Views/Subscription/Guard.swift | 16 ++++++------- 6 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 PadelClub/Views/Shared/SupportButtonView.swift diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index e6b082c..f5c3bdf 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -237,6 +237,7 @@ FFDDD40C2B93B2BB00C91A49 /* DeferredViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFDDD40B2B93B2BB00C91A49 /* DeferredViewModifier.swift */; }; FFE2D2D52C216B5000D0C7BE /* FirebaseCrashlytics in Frameworks */ = {isa = PBXBuildFile; productRef = FFE2D2D42C216B5000D0C7BE /* FirebaseCrashlytics */; }; FFE2D2D82C216D4800D0C7BE /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = FFE2D2D72C216D4800D0C7BE /* GoogleService-Info.plist */; }; + FFE2D2E22C231BEE00D0C7BE /* SupportButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFE2D2E12C231BEE00D0C7BE /* SupportButtonView.swift */; }; FFEF7F4E2BDE69130033D0F0 /* MenuWarningView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEF7F4D2BDE69130033D0F0 /* MenuWarningView.swift */; }; FFF0241E2BF48B15001F14B4 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = FFF0241D2BF48B15001F14B4 /* Localizable.strings */; }; FFF03C942BD91D0C00B516FC /* ButtonValidateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFF03C932BD91D0C00B516FC /* ButtonValidateView.swift */; }; @@ -562,6 +563,7 @@ FFDB1C722BB2CFE900F1E467 /* MySortDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MySortDescriptor.swift; sourceTree = ""; }; FFDDD40B2B93B2BB00C91A49 /* DeferredViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeferredViewModifier.swift; sourceTree = ""; }; FFE2D2D72C216D4800D0C7BE /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; + FFE2D2E12C231BEE00D0C7BE /* SupportButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportButtonView.swift; sourceTree = ""; }; FFEF7F4D2BDE69130033D0F0 /* MenuWarningView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuWarningView.swift; sourceTree = ""; }; FFF0241C2BF48B15001F14B4 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = ""; }; FFF0241F2BF48B1A001F14B4 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; @@ -1060,6 +1062,7 @@ FF5D0D6F2BB3EFA5005CB568 /* LearnMoreSheetView.swift */, FFCFC0192BBC5A8500B82851 /* MatchTypeSmallSelectionView.swift */, FF663FBD2BE019EC0031AE83 /* TournamentFilterView.swift */, + FFE2D2E12C231BEE00D0C7BE /* SupportButtonView.swift */, ); path = Shared; sourceTree = ""; @@ -1520,6 +1523,7 @@ FF025AE12BD0EB9000A86CF8 /* TournamentClubSettingsView.swift in Sources */, FFBF065C2BBD2657009D6715 /* GroupStageTeamView.swift in Sources */, FF5DA1932BB9279B00A33061 /* RoundSettingsView.swift in Sources */, + FFE2D2E22C231BEE00D0C7BE /* SupportButtonView.swift in Sources */, FFB1C98B2C10255100B154A7 /* TournamentBroadcastRowView.swift in Sources */, FF025ADF2BD0CE0A00A86CF8 /* TeamWeightView.swift in Sources */, FF9268012BCE94920080F940 /* SeedsCallingView.swift in Sources */, diff --git a/PadelClub/Info.plist b/PadelClub/Info.plist index 17dc2c2..9dcd617 100644 --- a/PadelClub/Info.plist +++ b/PadelClub/Info.plist @@ -2,8 +2,6 @@ - UIFileSharingEnabled - CFBundleDocumentTypes @@ -22,5 +20,7 @@ ITSAppUsesNonExemptEncryption + UIFileSharingEnabled + diff --git a/PadelClub/Views/Navigation/Agenda/ActivityView.swift b/PadelClub/Views/Navigation/Agenda/ActivityView.swift index 050bd91..ccc4d2d 100644 --- a/PadelClub/Views/Navigation/Agenda/ActivityView.swift +++ b/PadelClub/Views/Navigation/Agenda/ActivityView.swift @@ -309,7 +309,7 @@ struct ActivityView: View { Image(.padelClubLogoFondclairTransparent) .resizable() .scaledToFit() - .frame(width: 128) + .frame(width: 100) } } description: { Text("Aucun événement en cours ou à venir dans votre agenda.") @@ -326,6 +326,8 @@ struct ActivityView: View { navigation.agendaDestination = .tenup } } + + SupportButtonView() } } diff --git a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift index 8a7a5c7..f8f2de4 100644 --- a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift +++ b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift @@ -16,6 +16,13 @@ struct ToolboxView: View { @Bindable var navigation = navigation NavigationStack(path: $navigation.toolboxPath) { List { + + Section { + Text("Version de l'application").badge(PadelClubApp.appVersion) + } footer: { + SupportButtonView() + } + #if DEBUG Section { @@ -113,10 +120,6 @@ struct ToolboxView: View { Section { Link("Accéder au guide de la compétition", destination: URLs.padelRules.url) } - - Section { - Text("Version de l'application").badge(PadelClubApp.appVersion) - } } .navigationTitle(TabDestination.toolbox.title) } diff --git a/PadelClub/Views/Shared/SupportButtonView.swift b/PadelClub/Views/Shared/SupportButtonView.swift new file mode 100644 index 0000000..3bce884 --- /dev/null +++ b/PadelClub/Views/Shared/SupportButtonView.swift @@ -0,0 +1,23 @@ +// +// SupportButtonView.swift +// PadelClub +// +// Created by Razmig Sarkissian on 19/06/2024. +// + +import SwiftUI + +struct SupportButtonView: View { + + var body: some View { + FooterButtonView("Besoin d'aide ? Un problème ? Contactez-nous !") { + openMail() + } + } + + func openMail(emailTo: String = "support@padelclub.app", subject: String = "Support Padel Club") { + if let url = URL(string: "mailto:\(emailTo)?subject=\(subject)"), UIApplication.shared.canOpenURL(url) { + UIApplication.shared.open(url, options: [:], completionHandler: nil) + } + } +} diff --git a/PadelClub/Views/Subscription/Guard.swift b/PadelClub/Views/Subscription/Guard.swift index dc27aa3..da6b45f 100644 --- a/PadelClub/Views/Subscription/Guard.swift +++ b/PadelClub/Views/Subscription/Guard.swift @@ -140,14 +140,14 @@ import LeStorage } var currentPlan: StoreItem? { -// #if DEBUG - return .monthlyUnlimited -// #else -// if let currentBestPlan = self.currentBestPlan, let plan = StoreItem(rawValue: currentBestPlan.productID) { -// return plan -// } -// return nil -// #endif + #if DEBUG + return .monthlyUnlimited + #else + if let currentBestPlan = self.currentBestPlan, let plan = StoreItem(rawValue: currentBestPlan.productID) { + return plan + } + return nil + #endif } func userFilteredPurchases() -> [StoreKit.Transaction] { From e4dd5077bf579eb1d2d351b46ae3c02b937acb32 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Thu, 20 Jun 2024 10:13:45 +0200 Subject: [PATCH 3/4] support email button --- PadelClub.xcodeproj/project.pbxproj | 4 ++-- PadelClub/PadelClubApp.swift | 5 +++++ PadelClub/Views/Calling/CallView.swift | 2 +- PadelClub/Views/GroupStage/GroupStagesView.swift | 5 ----- PadelClub/Views/Navigation/Agenda/ActivityView.swift | 4 +++- PadelClub/Views/Navigation/Toolbox/ToolboxView.swift | 5 +++-- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index f5c3bdf..fdf44ce 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -1897,7 +1897,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 57; + CURRENT_PROJECT_VERSION = 58; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; @@ -1937,7 +1937,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 57; + CURRENT_PROJECT_VERSION = 58; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; diff --git a/PadelClub/PadelClubApp.swift b/PadelClub/PadelClubApp.swift index c79c829..043c4aa 100644 --- a/PadelClub/PadelClubApp.swift +++ b/PadelClub/PadelClubApp.swift @@ -53,6 +53,11 @@ struct PadelClubApp: App { UserDefaults.standard.set(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable") } + static func openMail(emailTo: String = "support@padelclub.app", subject: String = "Support Padel Club") { + if let url = URL(string: "mailto:\(emailTo)?subject=\(subject)"), UIApplication.shared.canOpenURL(url) { + UIApplication.shared.open(url, options: [:], completionHandler: nil) + } + } } class AppDelegate: NSObject, UIApplicationDelegate { diff --git a/PadelClub/Views/Calling/CallView.swift b/PadelClub/Views/Calling/CallView.swift index 606e61c..7462768 100644 --- a/PadelClub/Views/Calling/CallView.swift +++ b/PadelClub/Views/Calling/CallView.swift @@ -186,7 +186,7 @@ struct CallView: View { .underline() } } else { - Button(byMessage ? "sms" : "mail") { + FooterButtonView(byMessage ? "sms" : "mail") { _summon(byMessage: byMessage, reSummon: false) } } diff --git a/PadelClub/Views/GroupStage/GroupStagesView.swift b/PadelClub/Views/GroupStage/GroupStagesView.swift index 248ce5c..7827c32 100644 --- a/PadelClub/Views/GroupStage/GroupStagesView.swift +++ b/PadelClub/Views/GroupStage/GroupStagesView.swift @@ -107,11 +107,6 @@ struct GroupStagesView: View { availableToStart = await tournament.availableToStart(allMatches, in: runningMatches ?? []) readyMatches = await tournament.readyMatches(allMatches) } - .overlay { - if availableToStart?.isEmpty == true && runningMatches?.isEmpty == true && readyMatches?.isEmpty == true && finishedMatches.isEmpty == true { - ContentUnavailableView("Aucun match à afficher", systemImage: "tennisball") - } - } .navigationTitle("Toutes les poules") case .groupStage(let groupStage): GroupStageView(groupStage: groupStage).id(groupStage.id) diff --git a/PadelClub/Views/Navigation/Agenda/ActivityView.swift b/PadelClub/Views/Navigation/Agenda/ActivityView.swift index ccc4d2d..b3fbae2 100644 --- a/PadelClub/Views/Navigation/Agenda/ActivityView.swift +++ b/PadelClub/Views/Navigation/Agenda/ActivityView.swift @@ -327,7 +327,9 @@ struct ActivityView: View { } } - SupportButtonView() + FooterButtonView("Besoin d'aide ? Un problème ? Contactez-nous !") { + PadelClubApp.openMail() + } } } diff --git a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift index f8f2de4..9a9bd77 100644 --- a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift +++ b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift @@ -19,8 +19,9 @@ struct ToolboxView: View { Section { Text("Version de l'application").badge(PadelClubApp.appVersion) - } footer: { - SupportButtonView() + Button("Contactez-nous") { + PadelClubApp.openMail() + } } #if DEBUG From f5ee4e72f3710aafda4c692dfa626b2c3150c900 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Thu, 20 Jun 2024 15:12:06 +0200 Subject: [PATCH 4/4] add support backup --- PadelClub.xcodeproj/project.pbxproj | 17 ++++ PadelClub/PadelClubApp.swift | 6 -- PadelClub/Utils/ContactManager.swift | 10 +++ .../Navigation/Agenda/ActivityView.swift | 4 +- .../Navigation/Toolbox/ToolboxView.swift | 4 +- .../Views/Shared/SupportButtonView.swift | 87 +++++++++++++++++-- PadelClub/Views/Subscription/Guard.swift | 17 ++-- 7 files changed, 120 insertions(+), 25 deletions(-) diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index fdf44ce..b7c42a2 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -170,6 +170,7 @@ FF8F264F2BAE0B9600650388 /* MatchTypeSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF8F264E2BAE0B9600650388 /* MatchTypeSelectionView.swift */; }; FF8F26512BAE0BAD00650388 /* MatchFormatPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF8F26502BAE0BAD00650388 /* MatchFormatPickerView.swift */; }; FF8F26542BAE1E4400650388 /* TableStructureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF8F26532BAE1E4400650388 /* TableStructureView.swift */; }; + FF92660D2C241CE0002361A4 /* Zip in Frameworks */ = {isa = PBXBuildFile; productRef = FF92660C2C241CE0002361A4 /* Zip */; }; FF9267F82BCE78C70080F940 /* CashierView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF9267F72BCE78C70080F940 /* CashierView.swift */; }; FF9267FA2BCE78EC0080F940 /* CashierDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF9267F92BCE78EB0080F940 /* CashierDetailView.swift */; }; FF9267FC2BCE84870080F940 /* PlayerPayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF9267FB2BCE84870080F940 /* PlayerPayView.swift */; }; @@ -591,6 +592,7 @@ files = ( FFE2D2D52C216B5000D0C7BE /* FirebaseCrashlytics in Frameworks */, FFCFBFFE2BBBE86600B82851 /* Algorithms in Frameworks */, + FF92660D2C241CE0002361A4 /* Zip in Frameworks */, C49EF0392BDFF4600077B5AA /* LeStorage.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1340,6 +1342,7 @@ packageProductDependencies = ( FFCFBFFD2BBBE86600B82851 /* Algorithms */, FFE2D2D42C216B5000D0C7BE /* FirebaseCrashlytics */, + FF92660C2C241CE0002361A4 /* Zip */, ); productName = PadelClub; productReference = C425D3FD2B6D249D002A7B48 /* PadelClub.app */; @@ -1417,6 +1420,7 @@ packageReferences = ( FF4C7F052BBBE6B90031B6A3 /* XCRemoteSwiftPackageReference "swift-algorithms" */, FFE2D2D32C216B5000D0C7BE /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */, + FF92660B2C241CE0002361A4 /* XCRemoteSwiftPackageReference "Zip" */, ); productRefGroup = C425D3FE2B6D249D002A7B48 /* Products */; projectDirPath = ""; @@ -2096,6 +2100,14 @@ minimumVersion = 1.2.0; }; }; + FF92660B2C241CE0002361A4 /* XCRemoteSwiftPackageReference "Zip" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/marmelroy/Zip"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 2.1.2; + }; + }; FFE2D2D32C216B5000D0C7BE /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/firebase/firebase-ios-sdk.git"; @@ -2107,6 +2119,11 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + FF92660C2C241CE0002361A4 /* Zip */ = { + isa = XCSwiftPackageProductDependency; + package = FF92660B2C241CE0002361A4 /* XCRemoteSwiftPackageReference "Zip" */; + productName = Zip; + }; FFCFBFFD2BBBE86600B82851 /* Algorithms */ = { isa = XCSwiftPackageProductDependency; package = FF4C7F052BBBE6B90031B6A3 /* XCRemoteSwiftPackageReference "swift-algorithms" */; diff --git a/PadelClub/PadelClubApp.swift b/PadelClub/PadelClubApp.swift index 043c4aa..3bd835b 100644 --- a/PadelClub/PadelClubApp.swift +++ b/PadelClub/PadelClubApp.swift @@ -52,12 +52,6 @@ struct PadelClubApp: App { Logger.log("doc dir = \(docURL.absoluteString)") UserDefaults.standard.set(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable") } - - static func openMail(emailTo: String = "support@padelclub.app", subject: String = "Support Padel Club") { - if let url = URL(string: "mailto:\(emailTo)?subject=\(subject)"), UIApplication.shared.canOpenURL(url) { - UIApplication.shared.open(url, options: [:], completionHandler: nil) - } - } } class AppDelegate: NSObject, UIApplicationDelegate { diff --git a/PadelClub/Utils/ContactManager.swift b/PadelClub/Utils/ContactManager.swift index f972aff..dd74dd5 100644 --- a/PadelClub/Utils/ContactManager.swift +++ b/PadelClub/Utils/ContactManager.swift @@ -151,6 +151,7 @@ struct MailComposeView: UIViewControllerRepresentable { let bccRecipients: [String]? let body: String? let subject: String? + var attachmentURL: URL? let completion: Completion? func makeUIViewController(context: Context) -> UIViewController { @@ -163,6 +164,15 @@ struct MailComposeView: UIViewControllerRepresentable { controller.mailComposeDelegate = context.coordinator controller.setToRecipients(recipients) controller.setBccRecipients(bccRecipients) + if let attachmentURL { + do { + let attachmentData = try Data(contentsOf: attachmentURL) + controller.addAttachmentData(attachmentData, mimeType: "application/zip", fileName: "backup.zip") + } catch { + print("Could not attach file: \(error)") + } + } + if let body { controller.setMessageBody(body, isHTML: false) } diff --git a/PadelClub/Views/Navigation/Agenda/ActivityView.swift b/PadelClub/Views/Navigation/Agenda/ActivityView.swift index b3fbae2..685abe0 100644 --- a/PadelClub/Views/Navigation/Agenda/ActivityView.swift +++ b/PadelClub/Views/Navigation/Agenda/ActivityView.swift @@ -327,9 +327,7 @@ struct ActivityView: View { } } - FooterButtonView("Besoin d'aide ? Un problème ? Contactez-nous !") { - PadelClubApp.openMail() - } + SupportButtonView(contentIsUnavailable: true) } } diff --git a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift index 9a9bd77..731f8a5 100644 --- a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift +++ b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift @@ -19,9 +19,7 @@ struct ToolboxView: View { Section { Text("Version de l'application").badge(PadelClubApp.appVersion) - Button("Contactez-nous") { - PadelClubApp.openMail() - } + SupportButtonView(contentIsUnavailable: false) } #if DEBUG diff --git a/PadelClub/Views/Shared/SupportButtonView.swift b/PadelClub/Views/Shared/SupportButtonView.swift index 3bce884..70b9d55 100644 --- a/PadelClub/Views/Shared/SupportButtonView.swift +++ b/PadelClub/Views/Shared/SupportButtonView.swift @@ -6,18 +6,95 @@ // import SwiftUI +import LeStorage +import Zip +extension URL: Identifiable { + public var id: String { + return self.absoluteString + } +} struct SupportButtonView: View { + let contentIsUnavailable: Bool + @State private var sentError: ContactManagerError? = nil + @State private var zipFilePath: URL? + @EnvironmentObject var networkMonitor: NetworkMonitor + + var messageSentFailed: Binding { + Binding { + sentError != nil + } set: { newValue in + if newValue == false { + sentError = nil + } + } + } + var body: some View { - FooterButtonView("Besoin d'aide ? Un problème ? Contactez-nous !") { - openMail() + Group { + if contentIsUnavailable { + FooterButtonView("Besoin d'aide ? Un problème ? Contactez-nous !") { + _zip() + } + } else { + Button("Signaler un problème") { + _zip() + } + } + } + .alert("Un problème est survenu", isPresented: messageSentFailed) { + Button("OK") { + } + } message: { + let message = [networkMonitor.connected == false ? "L'appareil n'est pas connecté à internet." as String? : nil, sentError == .mailNotSent ? "Le mail est dans la boîte d'envoi de l'app Mail. Vérifiez son état dans l'app Mail avant d'essayer de le renvoyer." as String? : nil, (sentError == .messageFailed || sentError == .messageNotSent) ? "Le SMS n'a pas été envoyé" as String? : nil, sentError == .mailFailed ? "Le mail n'a pas été envoyé" as String? : nil].compacted().joined(separator: "\n") + Text(message) + } + .sheet(item: $zipFilePath) { zipFilePath in + MailComposeView(recipients: ["support@padelclub.app"], bccRecipients: nil, body: nil, subject: _getSubject(), attachmentURL: zipFilePath) { result in + switch result { + case .cancelled, .saved: + self.zipFilePath = nil + case .failed: + self.zipFilePath = nil + self.sentError = .mailFailed + case .sent: + if networkMonitor.connected == false { + self.zipFilePath = nil + self.sentError = .mailNotSent + } + @unknown default: + break + } + } + .tint(.master) + } + } + + private func _getSubject() -> String { + let device = UIDevice.current + let iOSVersion = device.systemVersion + return "[\(PadelClubApp.appVersion), \(iOSVersion), \(_getDeviceIdentifier())] Support Padel Club" + + } + + private func _getDeviceIdentifier() -> String { + var systemInfo = utsname() + uname(&systemInfo) + let machineMirror = Mirror(reflecting: systemInfo.machine) + let identifier = machineMirror.children.reduce("") { identifier, element in + guard let value = element.value as? Int8, value != 0 else { return identifier } + return identifier + String(UnicodeScalar(UInt8(value))) } + return identifier } - func openMail(emailTo: String = "support@padelclub.app", subject: String = "Support Padel Club") { - if let url = URL(string: "mailto:\(emailTo)?subject=\(subject)"), UIApplication.shared.canOpenURL(url) { - UIApplication.shared.open(url, options: [:], completionHandler: nil) + private func _zip() { + do { + let filePath = try Club.storageDirectoryPath() + self.zipFilePath = try Zip.quickZipFiles([filePath], fileName: "backup") // Zip + } catch { + Logger.error(error) } } } diff --git a/PadelClub/Views/Subscription/Guard.swift b/PadelClub/Views/Subscription/Guard.swift index da6b45f..c7fc264 100644 --- a/PadelClub/Views/Subscription/Guard.swift +++ b/PadelClub/Views/Subscription/Guard.swift @@ -140,14 +140,15 @@ import LeStorage } var currentPlan: StoreItem? { - #if DEBUG - return .monthlyUnlimited - #else - if let currentBestPlan = self.currentBestPlan, let plan = StoreItem(rawValue: currentBestPlan.productID) { - return plan - } - return nil - #endif + return .monthlyUnlimited +// #if DEBUG +// return .monthlyUnlimited +// #else +// if let currentBestPlan = self.currentBestPlan, let plan = StoreItem(rawValue: currentBestPlan.productID) { +// return plan +// } +// return nil +// #endif } func userFilteredPurchases() -> [StoreKit.Transaction] {