From 5007a2254ef22fbf096a8738f95584cd95c49dd6 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 5 Feb 2022 21:19:12 -0500 Subject: [PATCH] Adjust Modern Slider Day Range based on user preference. --- Clocker/Panel/ParentPanelController+ModernSlider.swift | 8 ++++++-- Clocker/Panel/ParentPanelController.swift | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Clocker/Panel/ParentPanelController+ModernSlider.swift b/Clocker/Panel/ParentPanelController+ModernSlider.swift index 944c719..7d2d75e 100644 --- a/Clocker/Panel/ParentPanelController+ModernSlider.swift +++ b/Clocker/Panel/ParentPanelController+ModernSlider.swift @@ -5,7 +5,9 @@ import Foundation extension ParentPanelController: NSCollectionViewDataSource { func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int { - return (PanelConstants.modernSliderPointsInADay * PanelConstants.modernSliderDaySupport * 2) + 1 + let futureSliderDayPreference = DataStore.shared().retrieve(key: CLFutureSliderRange) as? NSNumber ?? 5 + let futureSliderDayRange = (futureSliderDayPreference.intValue + 1) + return (PanelConstants.modernSliderPointsInADay * futureSliderDayRange * 2) + 1 } func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem { @@ -125,7 +127,9 @@ extension ParentPanelController { } public func setDefaultDateLabel(_ index: Int) -> Int { - let totalCount = (PanelConstants.modernSliderPointsInADay * PanelConstants.modernSliderDaySupport * 2) + 1 + let futureSliderDayPreference = DataStore.shared().retrieve(key: CLFutureSliderRange) as? NSNumber ?? 5 + let futureSliderDayRange = (futureSliderDayPreference.intValue + 1) + let totalCount = (PanelConstants.modernSliderPointsInADay * futureSliderDayRange * 2) + 1 let centerPoint = Int(ceil(Double(totalCount / 2))) if index > (centerPoint + 1) { let remainder = (index % (centerPoint + 1)) diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index 0c28f7a..bd14813 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -11,7 +11,6 @@ struct PanelConstants { static let noThanksTitle = "No, thanks" static let yesWithQuestionMark = "Yes?" static let yesWithExclamation = "Yes!" - static let modernSliderDaySupport = 5 static let modernSliderPointsInADay = 96 } @@ -144,6 +143,7 @@ class ParentPanelController: NSWindowController { futureSliderRangeObserver = UserDefaults.standard.observe(\.sliderDayRange, options: [.new]) { _, change in if change.newValue != nil { self.adjustFutureSliderBasedOnPreferences() + self.modernSlider.reloadData() } } }