Browse Source

Modern Slider Bug Fix!!

pull/101/head
Abhishek 4 years ago
parent
commit
f9f2bbd383
  1. 3
      Clocker/Panel/PanelController.swift
  2. 23
      Clocker/Panel/ParentPanelController+ModernSlider.swift

3
Clocker/Panel/PanelController.swift

@ -97,7 +97,8 @@ class PanelController: ParentPanelController {
// Reset future slider value to zero
futureSlider.integerValue = 0
sliderDatePicker.dateValue = Date()
closestQuarterTimeRepresentation = setModernSliderLabel()
closestQuarterTimeRepresentation = findClosestQuarterTimeApproximation()
modernSliderLabel.stringValue = "Time Scroller"
if modernSlider != nil {
let indexPaths: Set<IndexPath> = Set([IndexPath(item: modernSlider.numberOfItems(inSection: 0) / 2, section: 0)])

23
Clocker/Panel/ParentPanelController+ModernSlider.swift

@ -32,7 +32,14 @@ extension ParentPanelController {
selector: #selector(collectionViewDidScroll(_:)),
name: NSView.boundsDidChangeNotification,
object: modernSlider.superview)
closestQuarterTimeRepresentation = setModernSliderLabel()
// Set the modern slider label!
closestQuarterTimeRepresentation = findClosestQuarterTimeApproximation()
if let unwrappedClosetQuarterTime = closestQuarterTimeRepresentation {
modernSliderLabel.stringValue = timezoneFormattedStringRepresentation(unwrappedClosetQuarterTime)
}
// Make sure modern slider is centered horizontally!
let indexPaths: Set<IndexPath> = Set([IndexPath(item: modernSlider.numberOfItems(inSection: 0) / 2, section: 0)])
modernSlider.scrollToItems(at: indexPaths, scrollPosition: .centeredHorizontally)
}
@ -74,21 +81,13 @@ extension ParentPanelController {
}
}
@discardableResult
public func setModernSliderLabel(_ shouldUpdate: Bool = false) -> Date {
public func findClosestQuarterTimeApproximation() -> Date {
let defaultParameters = minuteFromCalendar()
let hourQuarterDate = Calendar.current.nextDate(after: defaultParameters.0,
matching: DateComponents(minute: defaultParameters.1),
matchingPolicy: .strict,
repeatedTimePolicy: .first,
direction: .forward)!
if shouldUpdate {
modernSliderLabel.stringValue = timezoneFormattedStringRepresentation(hourQuarterDate)
} else {
modernSliderLabel.stringValue = "Time Scroller"
}
return hourQuarterDate
}
@ -100,13 +99,13 @@ extension ParentPanelController {
let nextDate = Calendar.current.date(byAdding: .minute, value: remainder * 15, to: closestQuarterTimeRepresentation ?? Date())!
modernSliderLabel.stringValue = timezoneFormattedStringRepresentation(nextDate)
return nextDate.minutes(from: Date()) + 1
} else if index <= centerPoint {
} else if index < centerPoint {
let remainder = centerPoint - index + 1
let previousDate = Calendar.current.date(byAdding: .minute, value: -1 * remainder * 15, to: closestQuarterTimeRepresentation ?? Date())!
modernSliderLabel.stringValue = timezoneFormattedStringRepresentation(previousDate)
return previousDate.minutes(from: Date())
} else {
setModernSliderLabel(true)
modernSliderLabel.stringValue = "Time Scroller"
return 0
}
}

Loading…
Cancel
Save