Browse Source

Setup Modern Slider.

pull/101/head
Abhishek 4 years ago
parent
commit
7c14ffc18c
  1. 64
      Clocker/Clocker/en.lproj/Panel.xib
  2. 2
      Clocker/Panel/PanelController.swift
  3. 51
      Clocker/Panel/ParentPanelController+ModernSlider.swift
  4. 23
      Clocker/Panel/ParentPanelController.swift
  5. 31
      Clocker/Panel/UI/HourMarkerViewItem.swift
  6. 25
      Clocker/Panel/UI/HourMarkerViewItem.xib

64
Clocker/Clocker/en.lproj/Panel.xib

@ -3,6 +3,7 @@
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="18122"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@ -17,6 +18,7 @@
<outlet property="leftField" destination="8Qj-Y9-Okf" id="q3N-ht-jCd"/>
<outlet property="mainTableView" destination="dFw-ts-8OZ" id="2kY-dd-rDV"/>
<outlet property="modernSlider" destination="lxA-64-3QU" id="kS5-ub-7gV"/>
<outlet property="modernSliderLabel" destination="pi8-wk-eXa" id="yLU-nz-IBx"/>
<outlet property="nextEventLabel" destination="rld-Ag-KL1" id="GTY-j3-A1g"/>
<outlet property="pinButton" destination="YXE-4J-5cn" id="k6V-HK-7XG"/>
<outlet property="preferencesButton" destination="Ctq-BV-GPN" id="cdL-5h-qmx"/>
@ -42,14 +44,14 @@
<rect key="contentRect" x="1000" y="379" width="350" height="460"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1415"/>
<view key="contentView" focusRingType="none" id="6" customClass="BackgroundPanelView" customModule="Clocker" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="350" height="460"/>
<rect key="frame" x="0.0" y="0.0" width="350" height="275"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView focusRingType="none" distribution="fill" orientation="vertical" alignment="leading" spacing="0.0" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="OZA-6o-SbE">
<rect key="frame" x="0.0" y="0.0" width="350" height="460"/>
<rect key="frame" x="0.0" y="0.0" width="350" height="275"/>
<subviews>
<scrollView focusRingType="none" borderType="none" autohidesScrollers="YES" horizontalLineScroll="96" horizontalPageScroll="1" verticalLineScroll="96" verticalPageScroll="1" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" scrollerKnobStyle="light" translatesAutoresizingMaskIntoConstraints="NO" id="4Gd-Nv-fXr">
<rect key="frame" x="-20" y="195" width="370" height="265"/>
<rect key="frame" x="-20" y="10" width="370" height="265"/>
<clipView key="contentView" focusRingType="none" drawsBackground="NO" copiesOnScroll="NO" id="4MZ-Di-yNR">
<rect key="frame" x="0.0" y="0.0" width="370" height="265"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@ -259,7 +261,7 @@
</scroller>
</scrollView>
<customView identifier="Review Cell" focusRingType="none" translatesAutoresizingMaskIntoConstraints="NO" id="TDn-Kk-KkV">
<rect key="frame" x="0.0" y="145" width="350" height="50"/>
<rect key="frame" x="0.0" y="-40" width="350" height="50"/>
<subviews>
<stackView focusRingType="none" distribution="fill" orientation="horizontal" alignment="centerY" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uys-ww-duA">
<rect key="frame" x="25" y="25" width="300" height="20"/>
@ -332,8 +334,8 @@
</constraints>
<accessibility description="ReviewCell" identifier="ReviewCell"/>
</customView>
<customView wantsLayer="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Akn-cR-W4G" customClass="ReviewView" customModule="Clocker" customModuleProvider="target">
<rect key="frame" x="0.0" y="70" width="350" height="75"/>
<customView wantsLayer="YES" focusRingType="none" translatesAutoresizingMaskIntoConstraints="NO" id="Akn-cR-W4G" customClass="ReviewView" customModule="Clocker" customModuleProvider="target">
<rect key="frame" x="0.0" y="140" width="350" height="75"/>
<subviews>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="Etf-aa-udM" customClass="ClockerTextBackgroundView" customModule="Clocker" customModuleProvider="target">
<rect key="frame" x="10" y="10" width="330" height="55"/>
@ -410,7 +412,7 @@
<accessibility identifier="UpcomingEventView"/>
</customView>
<customView wantsLayer="YES" focusRingType="none" translatesAutoresizingMaskIntoConstraints="NO" id="C7R-Dq-MFr" userLabel="Slider View">
<rect key="frame" x="0.0" y="40" width="350" height="30"/>
<rect key="frame" x="0.0" y="110" width="350" height="30"/>
<subviews>
<slider verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Vf2-uI-yf3">
<rect key="frame" x="7" y="2" width="201" height="23"/>
@ -459,7 +461,7 @@
</constraints>
</customView>
<customView wantsLayer="YES" focusRingType="none" translatesAutoresizingMaskIntoConstraints="NO" id="B8X-sx-cjT">
<rect key="frame" x="0.0" y="0.0" width="350" height="40"/>
<rect key="frame" x="0.0" y="70" width="350" height="40"/>
<subviews>
<button toolTip="Close Clocker" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="1cR-pI-osG">
<rect key="frame" x="309" y="7" width="30" height="26"/>
@ -536,18 +538,18 @@
<constraint firstItem="Ctq-BV-GPN" firstAttribute="leading" secondItem="B8X-sx-cjT" secondAttribute="leading" constant="8" id="ydm-oF-sVc"/>
</constraints>
</customView>
<customView hidden="YES" wantsLayer="YES" focusRingType="none" id="8W7-rS-Uob" userLabel="Slider View">
<rect key="frame" x="0.0" y="205" width="365" height="50"/>
<customView wantsLayer="YES" focusRingType="none" id="8W7-rS-Uob" userLabel="Modern Slider">
<rect key="frame" x="0.0" y="0.0" width="350" height="70"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<scrollView wantsLayer="YES" borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="htc-pO-AqH">
<rect key="frame" x="0.0" y="0.0" width="365" height="50"/>
<scrollView wantsLayer="YES" borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasVerticalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="htc-pO-AqH">
<rect key="frame" x="5" y="30" width="340" height="40"/>
<clipView key="contentView" id="N1e-zE-F86">
<rect key="frame" x="0.0" y="0.0" width="365" height="50"/>
<rect key="frame" x="0.0" y="0.0" width="340" height="40"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<collectionView id="lxA-64-3QU">
<rect key="frame" x="0.0" y="0.0" width="365" height="158"/>
<rect key="frame" x="0.0" y="0.0" width="340" height="40"/>
<autoresizingMask key="autoresizingMask" heightSizable="YES"/>
<collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" id="mgM-vQ-fB7">
<size key="itemSize" width="50" height="50"/>
@ -561,22 +563,37 @@
</subviews>
</clipView>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="8II-oP-xbd">
<rect key="frame" x="1" y="33" width="363" height="16"/>
<rect key="frame" x="0.0" y="34" width="340" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="f9b-8n-Bt1">
<rect key="frame" x="349" y="0.0" width="16" height="50"/>
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="f9b-8n-Bt1">
<rect key="frame" x="-100" y="-100" width="16" height="50"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="pi8-wk-eXa">
<rect key="frame" x="123" y="3" width="104" height="22"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="100" id="eLd-zO-yiI"/>
</constraints>
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="Label Goes Here" id="ii9-w0-WDX">
<font key="font" size="10" name="Avenir-LightOblique"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="Accent Color"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="htc-pO-AqH" firstAttribute="leading" secondItem="8W7-rS-Uob" secondAttribute="leading" id="0QY-hT-XLg"/>
<constraint firstAttribute="height" constant="50" id="5HT-Ps-YH3"/>
<constraint firstAttribute="height" constant="70" id="5HT-Ps-YH3"/>
<constraint firstAttribute="bottom" secondItem="pi8-wk-eXa" secondAttribute="bottom" constant="3" id="6E6-8S-PZv"/>
<constraint firstItem="htc-pO-AqH" firstAttribute="top" secondItem="8W7-rS-Uob" secondAttribute="top" id="Ag8-2G-tVA"/>
<constraint firstAttribute="bottom" secondItem="htc-pO-AqH" secondAttribute="bottom" id="YCJ-zB-dvc"/>
<constraint firstAttribute="trailing" secondItem="htc-pO-AqH" secondAttribute="trailing" id="d7f-wV-lqc"/>
<constraint firstItem="htc-pO-AqH" firstAttribute="leading" secondItem="8W7-rS-Uob" secondAttribute="leading" constant="5" id="QmJ-Dd-WLb"/>
<constraint firstItem="pi8-wk-eXa" firstAttribute="top" secondItem="htc-pO-AqH" secondAttribute="bottom" constant="5" id="UIT-XA-SEL"/>
<constraint firstAttribute="bottom" secondItem="htc-pO-AqH" secondAttribute="bottom" constant="30" id="YCJ-zB-dvc"/>
<constraint firstAttribute="trailing" secondItem="htc-pO-AqH" secondAttribute="trailing" constant="5" id="esR-My-uoD"/>
<constraint firstItem="pi8-wk-eXa" firstAttribute="centerX" secondItem="8W7-rS-Uob" secondAttribute="centerX" id="f3f-ax-wFo"/>
</constraints>
<accessibility identifier="Modern Slider"/>
</customView>
</subviews>
<constraints>
@ -617,7 +634,7 @@
<connections>
<outlet property="delegate" destination="-2" id="8"/>
</connections>
<point key="canvasLocation" x="172" y="466"/>
<point key="canvasLocation" x="172" y="465.5"/>
</window>
<userDefaultsController representsSharedInstance="YES" id="O3B-kK-4vm"/>
</objects>
@ -630,5 +647,8 @@
<image name="PowerIcon" width="350" height="350"/>
<image name="Remove" width="700" height="700"/>
<image name="SharingDarkIcon" width="19" height="22"/>
<namedColor name="Accent Color">
<color red="0.092000000178813934" green="0.0" blue="0.99900001287460327" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
</resources>
</document>

2
Clocker/Panel/PanelController.swift

@ -367,7 +367,7 @@ class PanelController: ParentPanelController {
// We only want to move the slider if the slider is visible.
// If the parent view is hidden, then that doesn't automatically mean that all the childViews are also hidden
// Hence, check if the parent view is totally hidden or not..
if futureSliderView.isHidden == false {
if futureSliderView.isHidden == false, modernSlider.isHidden {
futureSlider.doubleValue += Double(event.scrollingDeltaX)
sliderMoved(futureSlider!)
}

51
Clocker/Panel/ParentPanelController+ModernSlider.swift

@ -0,0 +1,51 @@
// Copyright © 2015 Abhishek Banthia
import CoreLoggerKit
import Foundation
extension ParentPanelController: NSCollectionViewDataSource, NSCollectionViewDelegate {
func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int {
return 96
}
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
let item = collectionView.makeItem(withIdentifier: HourMarkerViewItem.reuseIdentifier, for: indexPath) as! HourMarkerViewItem
item.setup(with: indexPath.item)
return item
}
}
extension ParentPanelController {
@objc func collectionViewDidScroll(_ notification: NSNotification) {
let contentView = notification.object as! NSClipView
let changedOrigin = contentView.documentVisibleRect.origin
let newPoint = NSPoint(x: changedOrigin.x + contentView.frame.width / 2, y: changedOrigin.y)
let indexPath = modernSlider.indexPathForItem(at: newPoint)
if let correctIndexPath = indexPath?.item, let item = modernSlider.item(at: correctIndexPath) as? HourMarkerViewItem {
setModernSliderLabel(item.indexTag)
setTimezoneDatasourceSlider(sliderValue: item.indexTag * 15)
item.setupLineColor()
mainTableView.reloadData()
if let previousItem = modernSlider.item(at: correctIndexPath - 1) as? HourMarkerViewItem {
previousItem.resetLineColor()
}
if let nextItem = modernSlider.item(at: correctIndexPath + 1) as? HourMarkerViewItem {
nextItem.resetLineColor()
}
}
}
func setModernSliderLabel(_ index: Int) {
var dateComponents = DateComponents()
dateComponents.minute = index * 15
if let newDate = Calendar.autoupdatingCurrent.date(byAdding: dateComponents, to: Date().nextHour) {
let dateFormatter = DateFormatterManager.dateFormatterWithFormat(with: .none,
format: "MMM d HH:mm",
timezoneIdentifier: TimeZone.current.identifier,
locale: Locale.autoupdatingCurrent)
modernSliderLabel.stringValue = dateFormatter.string(from: newDate)
}
}
}

23
Clocker/Panel/ParentPanelController.swift

@ -87,6 +87,7 @@ class ParentPanelController: NSWindowController {
// Modern Slider
@IBOutlet var modernSlider: NSCollectionView!
@IBOutlet var modernSliderLabel: NSTextField!
var defaultPreferences: [Data] {
return DataStore.shared().timezones()
@ -177,6 +178,12 @@ class ParentPanelController: NSWindowController {
if modernSlider != nil {
modernSlider.enclosingScrollView?.scrollerInsets = NSEdgeInsets(top: 0, left: 0, bottom: 100, right: 0)
modernSlider.delegate = self
modernSlider.postsBoundsChangedNotifications = true
NotificationCenter.default.addObserver(self,
selector: #selector(collectionViewDidScroll(_:)),
name: NSView.boundsDidChangeNotification,
object: modernSlider.superview)
setModernSliderLabel(0)
}
if roundedDateView != nil {
@ -1031,19 +1038,3 @@ extension ParentPanelController: NSSharingServicePickerDelegate {
return self as? NSSharingServiceDelegate
}
}
extension ParentPanelController: NSCollectionViewDataSource, NSCollectionViewDelegate {
func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int {
return 24
}
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
let item = collectionView.makeItem(withIdentifier: HourMarkerViewItem.reuseIdentifier, for: indexPath) as! HourMarkerViewItem
item.setup(with: indexPath.item)
return item
}
func collectionView(_: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
Logger.info("Did Select Item at \(indexPaths.description)")
}
}

31
Clocker/Panel/UI/HourMarkerViewItem.swift

@ -5,19 +5,34 @@ import Cocoa
class HourMarkerViewItem: NSCollectionViewItem {
static let reuseIdentifier = NSUserInterfaceItemIdentifier("HourMarkerViewItem")
@IBOutlet var hourLabel: NSTextField!
@IBOutlet var constraintFromTop: NSLayoutConstraint!
@IBOutlet var verticalLine: NSBox!
public var indexTag: Int = -1
func setup(with hour: Int) {
var dateComponents = DateComponents()
dateComponents.hour = hour
dateComponents.minute = hour * 15
indexTag = hour
for constraint in view.constraints where constraint.identifier == "constrainFromTop" {
if hour % 4 == 0 {
constraint.constant = 0
} else {
constraint.constant = 20
}
}
}
if let newDate = Calendar.autoupdatingCurrent.date(byAdding: dateComponents, to: Date().nextHour) {
let dateFormatter = DateFormatterManager.dateFormatterWithFormat(with: .none,
format: "HH:mm",
timezoneIdentifier: TimeZone.current.identifier,
locale: Locale.autoupdatingCurrent)
func setupLineColor() {
for subview in view.subviews where subview is NSBox {
subview.layer?.backgroundColor = NSColor.black.cgColor
}
}
hourLabel.stringValue = dateFormatter.string(from: newDate)
func resetLineColor() {
for subview in view.subviews where subview is NSBox {
subview.layer?.backgroundColor = nil
}
}

25
Clocker/Panel/UI/HourMarkerViewItem.xib

@ -1,13 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17156" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="18122" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17156"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="18122"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="HourMarkerViewItem" customModule="Clocker" customModuleProvider="target">
<connections>
<outlet property="constraintFromTop" destination="s8k-hS-sHN" id="aWd-YA-FDM"/>
<outlet property="verticalLine" destination="1AP-TS-SAk" id="kxC-uc-q7X"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
@ -18,32 +20,21 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<box horizontalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="1AP-TS-SAk">
<rect key="frame" x="86" y="23" width="9" height="80"/>
<rect key="frame" x="88" y="0.0" width="5" height="103"/>
<constraints>
<constraint firstAttribute="width" constant="5" id="DvW-Pd-tOA"/>
<constraint firstAttribute="width" constant="1" id="DvW-Pd-tOA"/>
</constraints>
</box>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="loc-Ga-aDA">
<rect key="frame" x="76" y="0.0" width="30" height="18"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="8:00" id="x1W-QM-ton">
<font key="font" size="13" name="Avenir-Book"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="1AP-TS-SAk" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="Ki4-9N-cRe"/>
<constraint firstAttribute="bottom" secondItem="loc-Ga-aDA" secondAttribute="bottom" id="cf2-W7-MIg"/>
<constraint firstItem="loc-Ga-aDA" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="jdj-qX-jCt"/>
<constraint firstItem="1AP-TS-SAk" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="s8k-hS-sHN"/>
<constraint firstItem="loc-Ga-aDA" firstAttribute="top" secondItem="1AP-TS-SAk" secondAttribute="bottom" constant="5" id="sDM-Xa-ZS4"/>
<constraint firstAttribute="bottom" secondItem="1AP-TS-SAk" secondAttribute="bottom" id="VbR-OQ-DUr"/>
<constraint firstItem="1AP-TS-SAk" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" identifier="constrainFromTop" id="s8k-hS-sHN"/>
</constraints>
<point key="canvasLocation" x="-17.5" y="283"/>
</customView>
<customObject id="p0M-E4-898" customClass="HourMarkerViewItem" customModule="Clocker" customModuleProvider="target">
<connections>
<outlet property="hourLabel" destination="loc-Ga-aDA" id="ZFf-u1-jVN"/>
<outlet property="view" destination="Hz6-mo-xeY" id="9S0-wg-csq"/>
</connections>
</customObject>

Loading…
Cancel
Save