From 71c9e80a331c2b2d8926148770dd9d1db6906f29 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Lapersonne Date: Tue, 4 Jan 2022 22:10:54 +0100 Subject: [PATCH] refactor: #167 - remove items relatetd to chronodoses Signed-off-by: Pierre-Yves Lapersonne --- ViteMaDose/Helpers/Utils/FCMHelper.swift | 14 +-- ViteMaDose/Models/FollowedCentre.swift | 1 - ViteMaDose/Models/VaccinationCentre.swift | 32 ------ ViteMaDose/Networking/RemoteConfig.swift | 4 - .../Localization/fr.lproj/Localizable.strings | 2 +- .../CentresList/CentresListViewModel.swift | 17 +--- .../Views/CentresList/Cells/CentreCell.swift | 24 +---- .../Views/CentresList/Cells/CentreCell.xib | 97 +++---------------- .../CentresListViewController.swift | 7 -- ViteMaDose/remote-configuration.plist | 2 - 10 files changed, 23 insertions(+), 177 deletions(-) diff --git a/ViteMaDose/Helpers/Utils/FCMHelper.swift b/ViteMaDose/Helpers/Utils/FCMHelper.swift index 6a6f94f2..a5ba1637 100644 --- a/ViteMaDose/Helpers/Utils/FCMHelper.swift +++ b/ViteMaDose/Helpers/Utils/FCMHelper.swift @@ -16,10 +16,9 @@ struct FCMHelper { func subscribeToCentreTopic( withDepartmentCode departmentCode: String, andCentreId centreId: String, - chronoDosesOnly: Bool, completion: @escaping (Swift.Result) -> Void ) { - let topicName = centreTopicName(departmentCode: departmentCode, centreId: centreId, chronoDosesOnly: chronoDosesOnly) + let topicName = centreTopicName(departmentCode: departmentCode, centreId: centreId) Messaging.messaging().subscribe(toTopic: topicName) { error in if let error = error { Log.e("SUBSCRIBE ERROR: \(error.localizedDescription)") @@ -34,10 +33,9 @@ struct FCMHelper { func unsubscribeToCentreTopic( withDepartmentCode departmentCode: String, andCentreId centreId: String, - chronoDosesOnly: Bool, completion: @escaping (Swift.Result) -> Void ) { - let topicName = centreTopicName(departmentCode: departmentCode, centreId: centreId, chronoDosesOnly: chronoDosesOnly) + let topicName = centreTopicName(departmentCode: departmentCode, centreId: centreId) Messaging.messaging().unsubscribe(fromTopic: topicName) { error in if let error = error { Log.e("UNSUBSCRIBE ERROR: \(error.localizedDescription)") @@ -49,12 +47,8 @@ struct FCMHelper { } } - private func centreTopicName(departmentCode: String, centreId: String, chronoDosesOnly: Bool) -> String { - let topicName = "department_\(departmentCode)_center_\(centreId)" - if chronoDosesOnly { - return topicName.appending("_chronodoses") - } - return topicName + private func centreTopicName(departmentCode: String, centreId: String) -> String { + return "department_\(departmentCode)_center_\(centreId)" } func requestNotificationsAuthorizationIfNeeded( diff --git a/ViteMaDose/Models/FollowedCentre.swift b/ViteMaDose/Models/FollowedCentre.swift index 3b772f5c..f4113974 100644 --- a/ViteMaDose/Models/FollowedCentre.swift +++ b/ViteMaDose/Models/FollowedCentre.swift @@ -16,6 +16,5 @@ public extension FollowedCentre { enum NotificationsType: String, Codable, Hashable { case none case all - case chronodoses } } diff --git a/ViteMaDose/Models/VaccinationCentre.swift b/ViteMaDose/Models/VaccinationCentre.swift index 8bc69778..1dc479e4 100644 --- a/ViteMaDose/Models/VaccinationCentre.swift +++ b/ViteMaDose/Models/VaccinationCentre.swift @@ -83,10 +83,6 @@ extension VaccinationCentre { case to case total } - - enum AppointmentScheduleKey { - static let chronoDose = "chronodose" - } } } @@ -149,19 +145,6 @@ extension VaccinationCentre { ) } - var hasChronoDose: Bool { - let chronoDoseKey = AppointmentSchedule.AppointmentScheduleKey.chronoDose - guard - let chronoDose = appointmentSchedules?.first(where: { $0?.name == chronoDoseKey }), - let chronoDosesCount = chronoDose?.total, - chronoDosesCount > 0 - else { - return false - } - - return chronoDosesCount >= RemoteConfiguration.shared.chronodoseMinCount - } - var vaccinesTypeText: String? { guard let vaccineType = vaccineType, !vaccineType.isEmpty else { return nil @@ -169,17 +152,6 @@ extension VaccinationCentre { return vaccineType.joined(separator: String.commaWithSpace) } - var chronoDosesCount: Int? { - let chronoDoseKey = AppointmentSchedule.AppointmentScheduleKey.chronoDose - guard - let chronoDose = appointmentSchedules?.first(where: { $0?.name == chronoDoseKey }), - let total = chronoDose?.total - else { - return nil - } - return total - } - static var sortedByAppointment: (Self, Self) -> Bool = { guard let lhsDate = $0.nextAppointmentDate, @@ -192,10 +164,6 @@ extension VaccinationCentre { return lhsDate.isBeforeDate(rhsDate, granularity: .minute) } - static var filteredByChronoDoses: (Self) -> Bool = { - return $0.hasChronoDose - } - func formattedCentreName(selectedLocation: CLLocation?) -> String { guard var name = nom else { return Localization.Location.unavailable_name diff --git a/ViteMaDose/Networking/RemoteConfig.swift b/ViteMaDose/Networking/RemoteConfig.swift index 938b8020..89dce48c 100644 --- a/ViteMaDose/Networking/RemoteConfig.swift +++ b/ViteMaDose/Networking/RemoteConfig.swift @@ -77,10 +77,6 @@ extension RemoteConfiguration { return configuration.configValue(forKey: "vaccination_centres_list_radius_in_km").numberValue } - var chronodoseMinCount: Int { - return configuration.configValue(forKey: "chronodose_min_count").numberValue.intValue - } - var vaccinationCentresListRadiusInMeters: Double { return vaccinationCentresListRadiusInKm.doubleValue * 1000 } diff --git a/ViteMaDose/Resources/Localization/fr.lproj/Localizable.strings b/ViteMaDose/Resources/Localization/fr.lproj/Localizable.strings index 4d86c989..cf9b2d4c 100644 --- a/ViteMaDose/Resources/Localization/fr.lproj/Localizable.strings +++ b/ViteMaDose/Resources/Localization/fr.lproj/Localizable.strings @@ -69,7 +69,7 @@ // MARK: - Location start following "location.start_following_title" = "Recevoir les notifications ?"; -"location.start_following_message" = "Vous pouvez choisir d'être notifié pour chaque changement de disponibilité ou seulement lorsque des Chronodoses sont disponibles pour ce centre."; +"location.start_following_message" = "Vous pouvez choisir d'être notifié pour chaque changement de disponibilité"; "location.follow_action_title" = "Suivre"; "location.notify_button" = "Être notifié"; "location.follow_button" = "Suivre sans notifications"; diff --git a/ViteMaDose/ViewModels/CentresList/CentresListViewModel.swift b/ViteMaDose/ViewModels/CentresList/CentresListViewModel.swift index eee2825d..36974a0b 100644 --- a/ViteMaDose/ViewModels/CentresList/CentresListViewModel.swift +++ b/ViteMaDose/ViewModels/CentresList/CentresListViewModel.swift @@ -175,7 +175,6 @@ class CentresListViewModel { isAvailable: centre.isAvailable, partnerLogo: partnerLogo, partnerName: centre.plateforme, - isChronoDose: centre.hasChronoDose, notificationsType: notificationsType ) } @@ -384,15 +383,9 @@ extension CentresListViewModel: CentresListViewModelProvider { return } - var chronoDosesOnly = false - if case .chronodoses = followedCentre.notificationsType { - chronoDosesOnly = true - } - FCMHelper.shared.subscribeToCentreTopic( withDepartmentCode: departmentCode, - andCentreId: internalId, - chronoDosesOnly: chronoDosesOnly + andCentreId: internalId ) { [weak self] result in guard let self = self else { return } switch result { @@ -425,15 +418,9 @@ extension CentresListViewModel: CentresListViewModelProvider { return } - var chronoDosesOnly = false - if case .chronodoses = followedCentre.notificationsType { - chronoDosesOnly = true - } - FCMHelper.shared.unsubscribeToCentreTopic( withDepartmentCode: departmentCode, - andCentreId: internalId, - chronoDosesOnly: chronoDosesOnly + andCentreId: internalId ) { [weak self] result in guard let self = self else { return } switch result { diff --git a/ViteMaDose/Views/CentresList/Cells/CentreCell.swift b/ViteMaDose/Views/CentresList/Cells/CentreCell.swift index d59cdbe7..a52aeb79 100644 --- a/ViteMaDose/Views/CentresList/Cells/CentreCell.swift +++ b/ViteMaDose/Views/CentresList/Cells/CentreCell.swift @@ -20,7 +20,6 @@ protocol CentreViewDataProvider { var appointmentsCount: Int? { get } var isAvailable: Bool { get } var partnerLogo: UIImage? { get } - var isChronoDose: Bool { get } var notificationsType: FollowedCentre.NotificationsType? { get } } @@ -39,7 +38,6 @@ public struct CentreViewData: CentreViewDataProvider, Hashable, Identifiable { let isAvailable: Bool let partnerLogo: UIImage? let partnerName: String? - let isChronoDose: Bool let notificationsType: FollowedCentre.NotificationsType? } @@ -67,9 +65,6 @@ final class CentreCell: UITableViewCell { @IBOutlet weak private var vaccineTypeImageView: UIImageView! - @IBOutlet weak private var chronoDoseViewContainer: UIView! - @IBOutlet weak private var chronoDoseLabel: UILabel! - @IBOutlet weak private(set) var followCentreButton: UIButton! var addressTapHandler: (() -> Void)? @@ -105,7 +100,6 @@ final class CentreCell: UITableViewCell { func configure(with viewData: CentreViewData) { configureBookButton(viewData) configurePhoneNumberView(viewData) - configureChronoDoseView(viewData) configureFollowCentreButton(viewData) configureAccessibility(viewData) @@ -295,7 +289,7 @@ final class CentreCell: UITableViewCell { bookingButtonAttributedText.append(NSAttributedString(attachment: imageAttachment)) - let availableButtonColor: UIColor = viewData.isChronoDose ? .mandy : .royalBlue + let availableButtonColor: UIColor = .royalBlue bookingButton.backgroundColor = viewData.isAvailable ? availableButtonColor : .darkGray bookingButton.setTitleColor(.white, for: .normal) bookingButton.setAttributedTitle(bookingButtonAttributedText, for: .normal) @@ -308,19 +302,6 @@ final class CentreCell: UITableViewCell { bookingButton.accessibilityHint = Localization.A11y.VoiceOver.Actions.booking_button } - private func configureChronoDoseView(_ viewData: CentreViewData) { - guard viewData.isChronoDose else { - chronoDoseViewContainer.isHidden = true - return - } - - chronoDoseViewContainer.isHidden = false - chronoDoseViewContainer.clipsToBounds = false - chronoDoseViewContainer.layer.cornerRadius = 15.0 - chronoDoseViewContainer.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] - chronoDoseLabel.text = "Chronodoses disponibles" - } - private func configureFollowCentreButton(_ viewData: CentreViewData) { followCentreButton.isHidden = viewData.notificationsType == nil guard let notificationsType = viewData.notificationsType else { @@ -331,9 +312,6 @@ final class CentreCell: UITableViewCell { case .all: followCentreButton.setImage(UIImage(systemName: "bell.fill"), for: .normal) followCentreButton.backgroundColor = .royalBlue - case .chronodoses: - followCentreButton.setImage(UIImage(systemName: "bell.fill"), for: .normal) - followCentreButton.backgroundColor = .mandy case .none: followCentreButton.setImage(UIImage(systemName: "bell.slash.fill"), for: .normal) followCentreButton.backgroundColor = .darkGray diff --git a/ViteMaDose/Views/CentresList/Cells/CentreCell.xib b/ViteMaDose/Views/CentresList/Cells/CentreCell.xib index be08ab6e..5c482872 100644 --- a/ViteMaDose/Views/CentresList/Cells/CentreCell.xib +++ b/ViteMaDose/Views/CentresList/Cells/CentreCell.xib @@ -1,9 +1,9 @@ - + - + @@ -25,82 +25,18 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + @@ -136,10 +72,10 @@ - + - + @@ -168,7 +104,7 @@ - + - + @@ -226,10 +162,10 @@ - + - + @@ -259,7 +195,7 @@ - + @@ -307,7 +243,7 @@