Skip to content

Commit

Permalink
Merge pull request #170 from CovidTrackerFr/refactoring/167_RemoveChr…
Browse files Browse the repository at this point in the history
…onodoses

[Refactoring] [#167] Remove items relatetd to chronodoses
  • Loading branch information
victor-sarda committed Jan 11, 2022
2 parents 22ebfd1 + 71c9e80 commit 579ed69
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 177 deletions.
14 changes: 4 additions & 10 deletions ViteMaDose/Helpers/Utils/FCMHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ struct FCMHelper {
func subscribeToCentreTopic(
withDepartmentCode departmentCode: String,
andCentreId centreId: String,
chronoDosesOnly: Bool,
completion: @escaping (Swift.Result<Void, Error>) -> 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)")
Expand All @@ -34,10 +33,9 @@ struct FCMHelper {
func unsubscribeToCentreTopic(
withDepartmentCode departmentCode: String,
andCentreId centreId: String,
chronoDosesOnly: Bool,
completion: @escaping (Swift.Result<Void, Error>) -> 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)")
Expand All @@ -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(
Expand Down
1 change: 0 additions & 1 deletion ViteMaDose/Models/FollowedCentre.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ public extension FollowedCentre {
enum NotificationsType: String, Codable, Hashable {
case none
case all
case chronodoses
}
}
32 changes: 0 additions & 32 deletions ViteMaDose/Models/VaccinationCentre.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ extension VaccinationCentre {
case to
case total
}

enum AppointmentScheduleKey {
static let chronoDose = "chronodose"
}
}

}
Expand Down Expand Up @@ -149,37 +145,13 @@ 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
}
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,
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions ViteMaDose/Networking/RemoteConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
17 changes: 2 additions & 15 deletions ViteMaDose/ViewModels/CentresList/CentresListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ class CentresListViewModel {
isAvailable: centre.isAvailable,
partnerLogo: partnerLogo,
partnerName: centre.plateforme,
isChronoDose: centre.hasChronoDose,
notificationsType: notificationsType
)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 1 addition & 23 deletions ViteMaDose/Views/CentresList/Cells/CentreCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand All @@ -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?
}

Expand Down Expand Up @@ -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)?
Expand Down Expand Up @@ -105,7 +100,6 @@ final class CentreCell: UITableViewCell {
func configure(with viewData: CentreViewData) {
configureBookButton(viewData)
configurePhoneNumberView(viewData)
configureChronoDoseView(viewData)
configureFollowCentreButton(viewData)
configureAccessibility(viewData)

Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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
Expand Down
Loading

0 comments on commit 579ed69

Please sign in to comment.