Skip to content

Commit

Permalink
update to include notify window that is adjustable
Browse files Browse the repository at this point in the history
  • Loading branch information
fireph committed Oct 11, 2017
1 parent 8393062 commit 23122ce
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 17 deletions.
4 changes: 2 additions & 2 deletions TrafficSweetSpot/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.4</string>
<string>1.5</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>9</string>
<string>10</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
Expand Down
74 changes: 63 additions & 11 deletions TrafficSweetSpot/PreferencesWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class PreferencesWindow: NSWindowController {
@IBOutlet weak var notificationsTimeLabel: NSTextField!
@IBOutlet weak var travelTimeMenuBarCheckBox: NSButton!
@IBOutlet weak var checkForUpdatesCheckBox: NSButton!
@IBOutlet weak var startTimeDropdown: NSPopUpButton!
@IBOutlet weak var endTimeDropdown: NSPopUpButton!

var delegate: PreferencesWindowDelegate?

Expand Down Expand Up @@ -60,19 +62,41 @@ class PreferencesWindow: NSWindowController {
if let checkForUpdatesVal = defaults.string(forKey: "checkForUpdates") {
checkForUpdatesCheckBox.stringValue = checkForUpdatesVal
}
}
@IBAction func onSliderUpdate(_ sender: Any) {
notificationsTimeSlider.integerValue = Int(notificationsTimeSlider.floatValue.rounded())
let value = notificationsTimeSlider.integerValue
var hours = String(value / 60)
if (hours.count < 2) {
hours = "0" + hours
startTimeDropdown.removeAllItems()
endTimeDropdown.removeAllItems()
for index in 0...23 {
var hour = String(index)
if (index < 10) {
hour = "0" + hour
}
startTimeDropdown.addItem(withTitle: hour + ":00")
endTimeDropdown.addItem(withTitle: hour + ":00")
}
var minutes = String(value % 60)
if (minutes.count < 2) {
minutes = "0" + minutes
if let startTimeNotifVal = defaults.string(forKey: "startTimeNotif") {
startTimeDropdown.selectItem(at: Int(startTimeNotifVal) ?? 17)
} else {
startTimeDropdown.selectItem(at: 17)
}
notificationsTimeLabel.stringValue = hours + ":" + minutes
if let endTimeNotifVal = defaults.string(forKey: "endTimeNotif") {
endTimeDropdown.selectItem(at: Int(endTimeNotifVal) ?? 20)
} else {
endTimeDropdown.selectItem(at: 20)
}
updateStartTimeDropdownItems()
updateEndTimeDropdownItems()
updateSliderLabel()
}

@IBAction func onSliderUpdate(_ sender: Any) {
updateSliderLabel()
}

@IBAction func onStartTimeDropdownUpdate(_ sender: Any) {
updateEndTimeDropdownItems()
}

@IBAction func onEndTimeDropdownUpdate(_ sender: Any) {
updateStartTimeDropdownItems()
}

@IBAction func saveClicked(_ sender: AnyObject) {
Expand All @@ -85,8 +109,36 @@ class PreferencesWindow: NSWindowController {
defaults.setValue(notificationsTimeSlider.stringValue, forKey: "notificationsTime")
defaults.setValue(travelTimeMenuBarCheckBox.stringValue, forKey: "travelTimeMenuBar")
defaults.setValue(checkForUpdatesCheckBox.stringValue, forKey: "checkForUpdates")
defaults.setValue(String(startTimeDropdown.indexOfSelectedItem), forKey: "startTimeNotif")
defaults.setValue(String(endTimeDropdown.indexOfSelectedItem), forKey: "endTimeNotif")
defaults.synchronize()
delegate?.preferencesDidUpdate()
self.window?.close()
}

func updateSliderLabel() {
notificationsTimeSlider.integerValue = Int(notificationsTimeSlider.floatValue.rounded())
let value = notificationsTimeSlider.integerValue
var hours = String(value / 60)
if (hours.count < 2) {
hours = "0" + hours
}
var minutes = String(value % 60)
if (minutes.count < 2) {
minutes = "0" + minutes
}
notificationsTimeLabel.stringValue = hours + ":" + minutes
}

func updateStartTimeDropdownItems() {
for item in startTimeDropdown.itemArray {
item.isHidden = startTimeDropdown.index(of: item) >= endTimeDropdown.indexOfSelectedItem
}
}

func updateEndTimeDropdownItems() {
for item in endTimeDropdown.itemArray {
item.isHidden = endTimeDropdown.index(of: item) <= startTimeDropdown.indexOfSelectedItem
}
}
}
Loading

0 comments on commit 23122ce

Please sign in to comment.