Browse Source

Playing!

pull/92/head
Abhishek 4 years ago
parent
commit
8563c790fd
  1. 31
      Clocker/Panel/UI/HourMarkerViewItem.swift
  2. 4
      Clocker/Panel/UI/HourMarkerViewItem.xib

31
Clocker/Panel/UI/HourMarkerViewItem.swift

@ -3,13 +3,34 @@
import Cocoa import Cocoa
class HourMarkerViewItem: NSCollectionViewItem { class HourMarkerViewItem: NSCollectionViewItem {
static let reuseIdentifier = NSUserInterfaceItemIdentifier("HourMarkerViewItem")
@IBOutlet var hourLabel: NSTextField! @IBOutlet var hourLabel: NSTextField!
func setup(with indexPath: IndexPath) { func setup(with hour: Int) {
hourLabel.stringValue = "\(indexPath.item):00" var dateComponents = DateComponents()
if indexPath.item == 2 { dateComponents.hour = hour
highlightState = .forSelection
isSelected = true 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)
hourLabel.stringValue = dateFormatter.string(from: newDate)
}
}
override var acceptsFirstResponder: Bool {
return false
} }
}
extension Date {
public var nextHour: Date {
let calendar = Calendar.current
let minutes = calendar.component(.minute, from: self)
let components = DateComponents(hour: 1, minute: -minutes)
return calendar.date(byAdding: components, to: self) ?? self
} }
} }

4
Clocker/Panel/UI/HourMarkerViewItem.xib

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17156" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies> <dependencies>
<deployment identifier="macosx"/> <deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17154"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17156"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<objects> <objects>

Loading…
Cancel
Save