From 9e2674e210e683eedd15e405a9781569ff608024 Mon Sep 17 00:00:00 2001 From: Raz Date: Wed, 8 Jan 2025 09:53:13 +0100 Subject: [PATCH] fix issue with locationbutton --- PadelClub.xcodeproj/project.pbxproj | 24 +++++++++--- PadelClub/Data/PlayerRegistration.swift | 25 ++++++++++++- PadelClub/Data/Tournament.swift | 13 ++++++- .../Agenda/TournamentLookUpView.swift | 30 +++++++++++++-- .../Components/UpdateSourceRankDateView.swift | 37 +++++++++---------- 5 files changed, 98 insertions(+), 31 deletions(-) diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index b6a7ba5..40c031f 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -3262,7 +3262,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 2; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; @@ -3275,7 +3275,10 @@ INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES; INFOPLIST_KEY_NSCalendarsUsageDescription = "Padel Club a besoin d'avoir accès à votre calendrier pour pouvoir y inscrire ce tournoi"; INFOPLIST_KEY_NSCameraUsageDescription = "En autorisant l'application à utiliser la caméra, vous pourrez prendre des photos des rencontres"; - INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "En utilisant votre position, Padel Club peut trouver plus rapidement les clubs et les tournois autour de vous."; + INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; + INFOPLIST_KEY_NSLocationAlwaysUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; + INFOPLIST_KEY_NSLocationUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = "Launch Screen"; @@ -3307,7 +3310,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 2; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; @@ -3319,7 +3322,10 @@ INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES; INFOPLIST_KEY_NSCalendarsUsageDescription = "Padel Club a besoin d'avoir accès à votre calendrier pour pouvoir y inscrire ce tournoi"; INFOPLIST_KEY_NSCameraUsageDescription = "En autorisant l'application à utiliser la caméra, vous pourrez prendre des photos des rencontres"; - INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "En utilisant votre position, Padel Club peut trouver plus rapidement les clubs et les tournois autour de vous."; + INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; + INFOPLIST_KEY_NSLocationAlwaysUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; + INFOPLIST_KEY_NSLocationUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = "Launch Screen"; @@ -3436,7 +3442,10 @@ INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES; INFOPLIST_KEY_NSCalendarsUsageDescription = "Padel Club a besoin d'avoir accès à votre calendrier pour pouvoir y inscrire ce tournoi"; INFOPLIST_KEY_NSCameraUsageDescription = "En autorisant l'application à utiliser la caméra, vous pourrez prendre des photos des rencontres"; - INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "Padel Club a besoin de votre position pour rechercher les clubs autour de vous."; + INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; + INFOPLIST_KEY_NSLocationAlwaysUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; + INFOPLIST_KEY_NSLocationUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = "Launch Screen"; @@ -3480,7 +3489,10 @@ INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES; INFOPLIST_KEY_NSCalendarsUsageDescription = "Padel Club a besoin d'avoir accès à votre calendrier pour pouvoir y inscrire ce tournoi"; INFOPLIST_KEY_NSCameraUsageDescription = "En autorisant l'application à utiliser la caméra, vous pourrez prendre des photos des rencontres"; - INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "Padel Club a besoin de votre position pour rechercher les clubs autour de vous."; + INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; + INFOPLIST_KEY_NSLocationAlwaysUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; + INFOPLIST_KEY_NSLocationUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "Padel Club utilise votre position simplement pour faciliter la recherche de tournois et de clubs autour de vous."; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = "Launch Screen"; diff --git a/PadelClub/Data/PlayerRegistration.swift b/PadelClub/Data/PlayerRegistration.swift index 4dbc043..e3dd433 100644 --- a/PadelClub/Data/PlayerRegistration.swift +++ b/PadelClub/Data/PlayerRegistration.swift @@ -239,8 +239,15 @@ final class PlayerRegistration: ModelObject, Storable { } } - @MainActor func updateRank(from sources: [CSVParser], lastRank: Int) async throws { +#if DEBUG_TIME //DEBUGING TIME +let start = Date() +defer { + let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) + print("func updateRank()", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) +} +#endif + if let dataFound = try await history(from: sources) { rank = dataFound.rankValue?.toInt() points = dataFound.points @@ -251,6 +258,14 @@ final class PlayerRegistration: ModelObject, Storable { } func history(from sources: [CSVParser]) async throws -> Line? { +#if DEBUG_TIME //DEBUGING TIME +let start = Date() +defer { + let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) + print("func history()", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) +} +#endif + guard let license = licenceId?.strippedLicense else { return try await historyFromName(from: sources) } @@ -276,6 +291,14 @@ final class PlayerRegistration: ModelObject, Storable { } func historyFromName(from sources: [CSVParser]) async throws -> Line? { +#if DEBUG_TIME //DEBUGING TIME +let start = Date() +defer { + let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) + print("func historyFromName()", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) +} +#endif + return await withTaskGroup(of: Line?.self) { group in for source in sources.filter({ $0.maleData == isMalePlayer() }) { group.addTask { [lastName, firstName] in diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 189c987..5f6ee07 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -1449,6 +1449,15 @@ defer { } func updateRank(to newDate: Date?) async throws { + +#if DEBUG_TIME //DEBUGING TIME +let start = Date() +defer { + let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) + print("func updateRank()", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) +} +#endif + guard let newDate else { return } rankSourceDate = newDate @@ -1472,8 +1481,8 @@ defer { let lastRankWoman = currentMonthData()?.femaleUnrankedValue let dataURLs = SourceFileManager.shared.allFiles.filter { $0.dateFromPath == newDate } let sources = dataURLs.map { CSVParser(url: $0) } - - try await unsortedPlayers().concurrentForEach { player in + let players = unsortedPlayers() + try await players.concurrentForEach { player in try await player.updateRank(from: sources, lastRank: (player.sex == .female ? lastRankWoman : lastRankMan) ?? 0) } } diff --git a/PadelClub/Views/Navigation/Agenda/TournamentLookUpView.swift b/PadelClub/Views/Navigation/Agenda/TournamentLookUpView.swift index 783359c..f7228f6 100644 --- a/PadelClub/Views/Navigation/Agenda/TournamentLookUpView.swift +++ b/PadelClub/Views/Navigation/Agenda/TournamentLookUpView.swift @@ -18,7 +18,7 @@ struct TournamentLookUpView: View { @State private var searchField: String = "" @State var page: Int = 0 @State var total: Int = 0 - + @State private var showingSettingsAlert = false @State private var searching: Bool = false @State private var requestedToGetAllPages: Bool = false @State private var revealSearchParameters: Bool = true @@ -57,6 +57,16 @@ struct TournamentLookUpView: View { } message: { Text("Aucune ville n'a été indiqué, il est préférable de se localiser ou d'indiquer une ville pour réduire le nombre de résultat.") } + .alert(isPresented: $showingSettingsAlert) { + Alert( + title: Text("Réglages"), + message: Text("Pour trouver les clubs autour de vous, vous devez l'autorisation à Padel Club de récupérer votre position."), + primaryButton: .default(Text("Ouvrir les réglages"), action: { + _openSettings() + }), + secondaryButton: .cancel() + ) + } .alert("Attention", isPresented: $presentAlert, actions: { Button { presentAlert = false @@ -305,9 +315,15 @@ struct TournamentLookUpView: View { } if locationManager.requestStarted { ProgressView() - } else { + } else if locationManager.manager.authorizationStatus != .restricted { LocationButton { - locationManager.requestLocation() + if locationManager.manager.authorizationStatus == .notDetermined { + locationManager.manager.requestWhenInUseAuthorization() + } else if locationManager.manager.authorizationStatus == .denied { + showingSettingsAlert = true + } else { + locationManager.requestLocation() + } } .symbolVariant(.fill) .foregroundColor (Color.white) @@ -485,4 +501,12 @@ struct TournamentLookUpView: View { return "Distance" } } + + private func _openSettings() { + guard let settingsURL = URL(string: UIApplication.openSettingsURLString) else { + return + } + UIApplication.shared.open(settingsURL) + } + } diff --git a/PadelClub/Views/Tournament/Screen/Components/UpdateSourceRankDateView.swift b/PadelClub/Views/Tournament/Screen/Components/UpdateSourceRankDateView.swift index 07f95d5..ceed51f 100644 --- a/PadelClub/Views/Tournament/Screen/Components/UpdateSourceRankDateView.swift +++ b/PadelClub/Views/Tournament/Screen/Components/UpdateSourceRankDateView.swift @@ -43,30 +43,29 @@ struct UpdateSourceRankDateView: View { Task { do { try await tournament.updateRank(to: currentRankSourceDate) - try await MainActor.run { - tournament.unsortedPlayers().forEach { player in - player.setComputedRank(in: tournament) - } - - try tournamentStore.playerRegistrations.addOrUpdate(contentOfs: tournament.unsortedPlayers()) - - tournament.unsortedTeams().forEach { team in - team.setWeight(from: team.players(), inTournamentCategory: tournament.tournamentCategory) - if forceRefreshLockWeight { - team.lockedWeight = team.weight - } + let unsortedPlayers = tournament.unsortedPlayers() + tournament.unsortedPlayers().forEach { player in + player.setComputedRank(in: tournament) + } + + try tournamentStore.playerRegistrations.addOrUpdate(contentOfs: unsortedPlayers) + + let unsortedTeams = tournament.unsortedTeams() + unsortedTeams.forEach { team in + team.setWeight(from: team.players(), inTournamentCategory: tournament.tournamentCategory) + if forceRefreshLockWeight { + team.lockedWeight = team.weight } - - try tournamentStore.teamRegistrations.addOrUpdate(contentOfs: tournament.unsortedTeams()) - - try dataStore.tournaments.addOrUpdate(instance: tournament) - - updatingRank = false - confirmUpdateRank = false } + + try tournamentStore.teamRegistrations.addOrUpdate(contentOfs: unsortedTeams) + + try dataStore.tournaments.addOrUpdate(instance: tournament) } catch { Logger.error(error) } + updatingRank = false + confirmUpdateRank = false } }.disabled(updatingRank)