Browse Source

Adjust Modern Slider Day Range based on user preference.

pull/113/head
Abhishek 3 years ago
parent
commit
5007a2254e
  1. 8
      Clocker/Panel/ParentPanelController+ModernSlider.swift
  2. 2
      Clocker/Panel/ParentPanelController.swift

8
Clocker/Panel/ParentPanelController+ModernSlider.swift

@ -5,7 +5,9 @@ import Foundation
extension ParentPanelController: NSCollectionViewDataSource { extension ParentPanelController: NSCollectionViewDataSource {
func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int { 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 { func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
@ -125,7 +127,9 @@ extension ParentPanelController {
} }
public func setDefaultDateLabel(_ index: Int) -> Int { 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))) let centerPoint = Int(ceil(Double(totalCount / 2)))
if index > (centerPoint + 1) { if index > (centerPoint + 1) {
let remainder = (index % (centerPoint + 1)) let remainder = (index % (centerPoint + 1))

2
Clocker/Panel/ParentPanelController.swift

@ -11,7 +11,6 @@ struct PanelConstants {
static let noThanksTitle = "No, thanks" static let noThanksTitle = "No, thanks"
static let yesWithQuestionMark = "Yes?" static let yesWithQuestionMark = "Yes?"
static let yesWithExclamation = "Yes!" static let yesWithExclamation = "Yes!"
static let modernSliderDaySupport = 5
static let modernSliderPointsInADay = 96 static let modernSliderPointsInADay = 96
} }
@ -144,6 +143,7 @@ class ParentPanelController: NSWindowController {
futureSliderRangeObserver = UserDefaults.standard.observe(\.sliderDayRange, options: [.new]) { _, change in futureSliderRangeObserver = UserDefaults.standard.observe(\.sliderDayRange, options: [.new]) { _, change in
if change.newValue != nil { if change.newValue != nil {
self.adjustFutureSliderBasedOnPreferences() self.adjustFutureSliderBasedOnPreferences()
self.modernSlider.reloadData()
} }
} }
} }

Loading…
Cancel
Save