Browse Source

More linting.

pull/92/head
Abhishek Banthia 6 years ago
parent
commit
0fd72ab06f
  1. 2
      Clocker/AppDelegate.swift
  2. 4
      Clocker/Clocker.xcodeproj/project.pbxproj
  3. 18
      Clocker/Overall App/UserDefaults + KVOExtensions.swift
  4. 122
      Clocker/Panel/ParentPanelController.swift
  5. 38
      Clocker/Preferences/General/PreferencesViewController.swift

2
Clocker/AppDelegate.swift

@ -126,7 +126,7 @@ open class AppDelegate : NSObject, NSApplicationDelegate {
assignShortcut() assignShortcut()
panelObserver = panelController.observe(\.hasActivePanel, options: [.new]) { (obj, change) in panelObserver = panelController.observe(\.hasActivePanel, options: [.new]) { (obj, _) in
self.statusBarHandler.setHasActiveIcon(obj.hasActivePanelGetter()) self.statusBarHandler.setHasActiveIcon(obj.hasActivePanelGetter())
} }

4
Clocker/Clocker.xcodeproj/project.pbxproj

@ -7,6 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
3595FAD0227F88BC0044A12A /* UserDefaults + KVOExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3595FACF227F88BC0044A12A /* UserDefaults + KVOExtensions.swift */; };
35C36EE422595EFD002FA5C6 /* StatusContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36EE022595EFD002FA5C6 /* StatusContainerView.swift */; }; 35C36EE422595EFD002FA5C6 /* StatusContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36EE022595EFD002FA5C6 /* StatusContainerView.swift */; };
35C36EE522595EFD002FA5C6 /* MenubarHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36EE122595EFD002FA5C6 /* MenubarHandler.swift */; }; 35C36EE522595EFD002FA5C6 /* MenubarHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36EE122595EFD002FA5C6 /* MenubarHandler.swift */; };
35C36EE622595EFD002FA5C6 /* StatusItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36EE222595EFD002FA5C6 /* StatusItemView.swift */; }; 35C36EE622595EFD002FA5C6 /* StatusItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36EE222595EFD002FA5C6 /* StatusItemView.swift */; };
@ -214,6 +215,7 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
3545C52A22612BCC00121E25 /* RateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RateTests.swift; sourceTree = "<group>"; }; 3545C52A22612BCC00121E25 /* RateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RateTests.swift; sourceTree = "<group>"; };
3595FACF227F88BC0044A12A /* UserDefaults + KVOExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefaults + KVOExtensions.swift"; sourceTree = "<group>"; };
35C36EE022595EFD002FA5C6 /* StatusContainerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusContainerView.swift; sourceTree = "<group>"; }; 35C36EE022595EFD002FA5C6 /* StatusContainerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusContainerView.swift; sourceTree = "<group>"; };
35C36EE122595EFD002FA5C6 /* MenubarHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenubarHandler.swift; sourceTree = "<group>"; }; 35C36EE122595EFD002FA5C6 /* MenubarHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenubarHandler.swift; sourceTree = "<group>"; };
35C36EE222595EFD002FA5C6 /* StatusItemView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusItemView.swift; sourceTree = "<group>"; }; 35C36EE222595EFD002FA5C6 /* StatusItemView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusItemView.swift; sourceTree = "<group>"; };
@ -504,6 +506,7 @@
35C36F3D2259D892002FA5C6 /* Strings.swift */, 35C36F3D2259D892002FA5C6 /* Strings.swift */,
35C36F392259D892002FA5C6 /* Themer.swift */, 35C36F392259D892002FA5C6 /* Themer.swift */,
35C36F3A2259D892002FA5C6 /* Timer.swift */, 35C36F3A2259D892002FA5C6 /* Timer.swift */,
3595FACF227F88BC0044A12A /* UserDefaults + KVOExtensions.swift */,
); );
path = "Overall App"; path = "Overall App";
sourceTree = "<group>"; sourceTree = "<group>";
@ -1178,6 +1181,7 @@
C2CCCD8220619C4C00F2DFC2 /* LocationController.swift in Sources */, C2CCCD8220619C4C00F2DFC2 /* LocationController.swift in Sources */,
35C36F4B2259D971002FA5C6 /* UnderlinedButton.swift in Sources */, 35C36F4B2259D971002FA5C6 /* UnderlinedButton.swift in Sources */,
9AB6F1562259CF3900A44663 /* CalendarViewController.swift in Sources */, 9AB6F1562259CF3900A44663 /* CalendarViewController.swift in Sources */,
3595FAD0227F88BC0044A12A /* UserDefaults + KVOExtensions.swift in Sources */,
9AB6F1612259D1B000A44663 /* PreferencesViewController.swift in Sources */, 9AB6F1612259D1B000A44663 /* PreferencesViewController.swift in Sources */,
35C36F2022596253002FA5C6 /* OneWindowController.swift in Sources */, 35C36F2022596253002FA5C6 /* OneWindowController.swift in Sources */,
35C36F442259D892002FA5C6 /* Logger.swift in Sources */, 35C36F442259D892002FA5C6 /* Logger.swift in Sources */,

18
Clocker/Overall App/UserDefaults + KVOExtensions.swift

@ -0,0 +1,18 @@
// Copyright © 2015 Abhishek Banthia
import Cocoa
extension UserDefaults {
@objc dynamic var displayFutureSlider: Int {
return integer(forKey: CLDisplayFutureSliderKey)
}
@objc dynamic var userFontSize: Int {
return integer(forKey: CLUserFontSizePreference)
}
@objc dynamic var sliderDayRange: Int {
return integer(forKey: CLFutureSliderRange)
}
}

122
Clocker/Panel/ParentPanelController.swift

@ -13,6 +13,10 @@ struct PanelConstants {
class ParentPanelController: NSWindowController { class ParentPanelController: NSWindowController {
private var futureSliderObserver: NSKeyValueObservation?
private var userFontSizeSelectionObserver: NSKeyValueObservation?
private var futureSliderRangeObserver: NSKeyValueObservation?
private var eventStoreChangedNotification: NSObjectProtocol? private var eventStoreChangedNotification: NSObjectProtocol?
var dateFormatter = DateFormatter() var dateFormatter = DateFormatter()
@ -87,6 +91,32 @@ class ParentPanelController: NSWindowController {
if let eventStoreNotif = eventStoreChangedNotification { if let eventStoreNotif = eventStoreChangedNotification {
NotificationCenter.default.removeObserver(eventStoreNotif) NotificationCenter.default.removeObserver(eventStoreNotif)
} }
[futureSliderObserver, userFontSizeSelectionObserver, futureSliderRangeObserver].forEach {
$0?.invalidate()
}
}
private func setupObservers() {
futureSliderObserver = UserDefaults.standard.observe(\.displayFutureSlider, options: [.new]) { (_, change) in
if let changedValue = change.newValue {
self.futureSliderView.isHidden = changedValue == 1
}
}
userFontSizeSelectionObserver = UserDefaults.standard.observe(\.userFontSize, options: [.new]) { (_, change) in
if let newFontSize = change.newValue {
Logger.log(object: ["FontSize": newFontSize], for: "User Font Size Preference")
self.mainTableView.reloadData()
self.setScrollViewConstraint()
}
}
futureSliderRangeObserver = UserDefaults.standard.observe(\.sliderDayRange, options: [.new]) { (_, change) in
if change.newValue != nil {
self.adjustFutureSliderBasedOnPreferences()
}
}
} }
override func awakeFromNib() { override func awakeFromNib() {
@ -107,13 +137,7 @@ class ParentPanelController: NSWindowController {
mainTableView.selectionHighlightStyle = .none mainTableView.selectionHighlightStyle = .none
mainTableView.enclosingScrollView?.hasVerticalScroller = false mainTableView.enclosingScrollView?.hasVerticalScroller = false
[CLDisplayFutureSliderKey, CLUserFontSizePreference, CLThemeKey, CLFutureSliderRange].forEach { key in setupObservers()
UserDefaults.standard.addObserver(self,
forKeyPath: key,
options: .new,
context: nil)
}
updateReviewViewFontColor() updateReviewViewFontColor()
@ -281,6 +305,8 @@ class ParentPanelController: NSWindowController {
sharingButton.image = sharedThemer.sharingImage() sharingButton.image = sharedThemer.sharingImage()
sliderDatePicker.textColor = sharedThemer.mainTextColor() sliderDatePicker.textColor = sharedThemer.mainTextColor()
updateReviewViewFontColor()
} }
override func windowDidLoad() { override func windowDidLoad() {
@ -302,25 +328,6 @@ class ParentPanelController: NSWindowController {
} }
} }
override func observeValue(forKeyPath keyPath: String?, of _: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == CLDisplayFutureSliderKey, let changes = change, let new = changes[NSKeyValueChangeKey.newKey] as? NSNumber {
futureSliderView.isHidden = new.isEqual(to: NSNumber(value: 1))
} else if keyPath == CLUserFontSizePreference, let userFontSize = DataStore.shared().retrieve(key: CLUserFontSizePreference) as? NSNumber {
Logger.log(object: ["FontSize": userFontSize], for: "User Font Size Preference")
mainTableView.reloadData()
setScrollViewConstraint()
} else if keyPath == CLThemeKey {
updateReviewViewFontColor()
} else if keyPath == CLFutureSliderRange {
adjustFutureSliderBasedOnPreferences()
} else {
super.observeValue(forKeyPath: keyPath,
of: keyPath,
change: change,
context: context)
}
}
func screenHeight() -> CGFloat { func screenHeight() -> CGFloat {
guard let main = NSScreen.main else { return 100 } guard let main = NSScreen.main else { return 100 }
@ -343,38 +350,42 @@ class ParentPanelController: NSWindowController {
parentTimer = nil parentTimer = nil
} }
func setScrollViewConstraint() { private func getAdjustedRowHeight(for object: TimezoneData?, _ currentHeight: CGFloat) -> CGFloat {
var totalHeight: CGFloat = 0.0 var newHeight = currentHeight
let preferences = defaultPreferences
for cellIndex in 0 ..< preferences.count { if newHeight <= 68.0 {
let currentObject = TimezoneData.customObject(from: preferences[cellIndex]) newHeight = 69.0
let rowRect = mainTableView.rect(ofRow: cellIndex)
var height: CGFloat = rowRect.size.height
if height <= 68.0 {
height = 69.0
} }
if height >= 68.0 { if newHeight >= 68.0 {
height = 75.0 newHeight = 75.0
if let note = currentObject?.note, note.isEmpty == false { if let note = object?.note, note.isEmpty == false {
height += 30 newHeight += 30
} }
} }
if height >= 88.0 { if newHeight >= 88.0 {
// Set it to 95 expicity in case the row height is calculated be higher. // Set it to 95 expicity in case the row height is calculated be higher.
height = 95.0 newHeight = 95.0
if let note = currentObject?.note, note.isEmpty { if let note = object?.note, note.isEmpty {
height -= 30.0 newHeight -= 30.0
} }
} }
height += mainTableView.intercellSpacing.height newHeight += mainTableView.intercellSpacing.height
return newHeight
}
func setScrollViewConstraint() {
var totalHeight: CGFloat = 0.0
let preferences = defaultPreferences
totalHeight += height for cellIndex in 0 ..< preferences.count {
let currentObject = TimezoneData.customObject(from: preferences[cellIndex])
let rowRect = mainTableView.rect(ofRow: cellIndex)
totalHeight += getAdjustedRowHeight(for: currentObject, rowRect.size.height)
} }
// This is for the Add Cell View case // This is for the Add Cell View case
@ -828,17 +839,23 @@ class ParentPanelController: NSWindowController {
return return
} }
NSAnimationContext.runAnimationGroup({ context in NSAnimationContext.runAnimationGroup({ (context) in
context.duration = 1 context.duration = 1
context.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut) context.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
leftButton.animator().alphaValue = 0.0 leftButton.animator().alphaValue = 0.0
rightButton.animator().alphaValue = 0.0 rightButton.animator().alphaValue = 0.0
}) { }, completionHandler: {
field.stringValue = title field.stringValue = title
NSAnimationContext.runAnimationGroup({ context in NSAnimationContext.runAnimationGroup({ (context) in
context.duration = 1 context.duration = 1
context.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn) context.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn)
self.runAnimationCompletionBlock(leftTitle, rightTitle)
}, completionHandler: {})
})
}
private func runAnimationCompletionBlock(_ leftButtonTitle: String, _ rightButtonTitle: String) {
self.leftButton.animator().alphaValue = 1.0 self.leftButton.animator().alphaValue = 1.0
self.rightButton.animator().alphaValue = 1.0 self.rightButton.animator().alphaValue = 1.0
@ -858,11 +875,8 @@ class ParentPanelController: NSWindowController {
self.rightButton.animator().attributedTitle = NSAttributedString(string: "Yes, sure", attributes: styleAttributes) self.rightButton.animator().attributedTitle = NSAttributedString(string: "Yes, sure", attributes: styleAttributes)
} }
self.leftButton.animator().attributedTitle = NSAttributedString(string: leftTitle, attributes: styleAttributes) self.leftButton.animator().attributedTitle = NSAttributedString(string: leftButtonTitle, attributes: styleAttributes)
self.rightButton.animator().attributedTitle = NSAttributedString(string: rightTitle, attributes: styleAttributes) self.rightButton.animator().attributedTitle = NSAttributedString(string: rightButtonTitle, attributes: styleAttributes)
}) {}
}
} }
// MARK: Date Picker + Slider // MARK: Date Picker + Slider

38
Clocker/Preferences/General/PreferencesViewController.swift

@ -340,6 +340,29 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
} }
if tableColumn?.identifier.rawValue == PreferencesConstants.timezoneNameIdentifier { if tableColumn?.identifier.rawValue == PreferencesConstants.timezoneNameIdentifier {
return handleTimezoneNameIdentifier(for: row, selectedDataSource)
}
if tableColumn?.identifier.rawValue == PreferencesConstants.availableTimezoneIdentifier {
return handleAvailableTimezoneColumn(for: row, dataSource)
}
if tableColumn?.identifier.rawValue == PreferencesConstants.customLabelIdentifier {
return selectedDataSource?.customLabel ?? "Error"
}
if tableColumn?.identifier.rawValue == "favouriteTimezone" {
return selectedDataSource?.isFavourite ?? 0
}
if tableColumn?.identifier.rawValue == "abbreviation" {
return handleAbbreviationColumn(for: row)
}
return nil
}
private func handleTimezoneNameIdentifier(for row: Int, _ selectedDataSource: TimezoneData?) -> Any? {
guard let model = selectedDataSource else { guard let model = selectedDataSource else {
return nil return nil
} }
@ -351,7 +374,7 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
return model.timezoneID return model.timezoneID
} }
if tableColumn?.identifier.rawValue == PreferencesConstants.availableTimezoneIdentifier { private func handleAvailableTimezoneColumn(for row: Int, _ dataSource: TimezoneData?) -> Any? {
let criteria = searchCriteria.selectedSegment let criteria = searchCriteria.selectedSegment
if criteria == 0 { if criteria == 0 {
@ -364,17 +387,10 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
} }
return timezoneArray[row] return timezoneArray[row]
} }
return nil
} }
if tableColumn?.identifier.rawValue == PreferencesConstants.customLabelIdentifier { private func handleAbbreviationColumn(for row: Int) -> Any? {
return selectedDataSource?.customLabel ?? "Error"
}
if tableColumn?.identifier.rawValue == "favouriteTimezone" {
return selectedDataSource?.isFavourite ?? 0
}
if tableColumn?.identifier.rawValue == "abbreviation" {
if searchField.stringValue.isEmpty == false && (row < timezoneFilteredArray.count) { if searchField.stringValue.isEmpty == false && (row < timezoneFilteredArray.count) {
let currentSelection = timezoneFilteredArray[row] let currentSelection = timezoneFilteredArray[row]
if currentSelection == "UTC" { if currentSelection == "UTC" {
@ -398,8 +414,6 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
return NSTimeZone(name: timezoneArray[row])?.abbreviation ?? "Error" return NSTimeZone(name: timezoneArray[row])?.abbreviation ?? "Error"
} }
}
return nil return nil
} }

Loading…
Cancel
Save