Skip to content

Commit

Permalink
Adjust Modern Slider Day Range based on user preference.
Browse files Browse the repository at this point in the history
  • Loading branch information
n0shake committed Feb 6, 2022
1 parent e9716d0 commit 5007a22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Clocker/Panel/ParentPanelController+ModernSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion Clocker/Panel/ParentPanelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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()
}
}
}
Expand Down

0 comments on commit 5007a22

Please sign in to comment.