Skip to content

Commit

Permalink
Fix bugs regarding initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCodedSelf committed Aug 20, 2017
1 parent 1e35d01 commit e952c40
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
9 changes: 5 additions & 4 deletions HushTime/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -655,7 +656,7 @@
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
</connections>
</application>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="HushTime" customModuleProvider="target"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="Hush_Time" customModuleProvider="target"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="0.0"/>
Expand All @@ -681,7 +682,7 @@
<!--View Controller-->
<scene sceneID="hIz-AP-VOD">
<objects>
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModule="HushTime" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModule="Hush_Time" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" wantsLayer="YES" id="m2S-Jp-Qdl">
<rect key="frame" x="0.0" y="0.0" width="300" height="400"/>
<autoresizingMask key="autoresizingMask"/>
Expand All @@ -706,7 +707,7 @@
<customView translatesAutoresizingMaskIntoConstraints="NO" id="BVk-fe-YLz" userLabel="Time and Power">
<rect key="frame" x="67" y="0.0" width="166" height="32"/>
<subviews>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="iOe-K9-Uh9" customClass="TimeSelector" customModule="HushTime" customModuleProvider="target">
<customView translatesAutoresizingMaskIntoConstraints="NO" id="iOe-K9-Uh9" customClass="TimeSelector" customModule="Hush_Time" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="130" height="32"/>
<constraints>
<constraint firstAttribute="width" constant="130" id="pWb-Gl-edk"/>
Expand Down Expand Up @@ -763,7 +764,7 @@
<rect key="frame" x="0.0" y="0.0" width="300" height="276"/>
<clipView key="contentView" drawsBackground="NO" id="H3n-Bx-ga8" userLabel="Selected Apps Clip View">
<rect key="frame" x="1" y="1" width="298" height="274"/>
<autoresizingMask key="autoresizingMask"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="sourceList" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" indentationPerLevel="14" outlineTableColumn="Cc5-Kg-t2l" id="Ymb-Qu-nXC">
<rect key="frame" x="0.0" y="0.0" width="298" height="274"/>
Expand Down
2 changes: 1 addition & 1 deletion HushTime/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>2</string>
<string>3</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.productivity</string>
<key>LSMinimumSystemVersion</key>
Expand Down
13 changes: 8 additions & 5 deletions HushTime/TimeSelector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ typealias Time = Measurement<UnitDuration>

class TimeSelector: NSView {

var valueChanged: (() -> ())? = nil

@IBOutlet private weak var mainView: NSView!
@IBOutlet fileprivate weak var minuteTextField: NSTextField!
@IBOutlet fileprivate weak var hourTextField: NSTextField!
Expand Down Expand Up @@ -47,25 +49,26 @@ class TimeSelector: NSView {

minuteTextField.integerValue = Int(time.converted(to: .minutes).value) % 60
hourTextField.integerValue = Int(time.converted(to: .hours).value)
resetIfInvalid()
updateForChangedValues()
}

fileprivate func resetIfInvalid() {
fileprivate func updateForChangedValues() {

resetHourTextIfNotValidHour()
resetMinuteTextIfNotValidMinute()
valueChanged?()
}

@IBAction private func minutesChanged(_ sender: Any) {

minuteTextField.integerValue = minuteStepper.integerValue
resetIfInvalid()
updateForChangedValues()
}

@IBAction private func hoursChanged(_ sender: Any) {

hourTextField.integerValue = hourStepper.integerValue
resetIfInvalid()
updateForChangedValues()
}

private func loadView() {
Expand Down Expand Up @@ -113,7 +116,7 @@ class TimeSelector: NSView {
extension TimeSelector: NSTextFieldDelegate {

override func controlTextDidEndEditing(_ obj: Notification) {
resetIfInvalid()
updateForChangedValues()
}

override func controlTextDidChange(_ obj: Notification) {
Expand Down
19 changes: 15 additions & 4 deletions HushTime/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@ class ViewController: NSViewController {
@IBOutlet private weak var onOffButton: NSButton!
@IBOutlet private weak var pomidoroButton: NSButton!
@IBOutlet private weak var configurationView: NSView!
@IBOutlet weak var selectedAppsView: NSScrollView!
@IBOutlet private weak var selectedAppsView: NSScrollView!

private var shouldPresentNotificationOnFinish = true
private var hushTimeBlock: HushTimeBlock?

fileprivate var selectedApps = SelectedApps() {
didSet {
selectedAppsSourceList.reloadData()
onOffButton.isEnabled = !selectedApps.apps.isEmpty
pomidoroButton.isEnabled = !selectedApps.apps.isEmpty
setButtonStateAccordingToAbilityToStart()
if selectedApps.apps.isEmpty { showEmptyState() }
else { hideEmptyState() }
}
Expand Down Expand Up @@ -98,6 +97,10 @@ class ViewController: NSViewController {

private func firstTimeSetup() {

timeSelector.valueChanged = { [weak self] in
self?.setButtonStateAccordingToAbilityToStart()
}

selectedAppsSourceList.dataSource = self
selectedAppsSourceList.delegate = self
selectedAppsSourceList.reloadData()
Expand All @@ -111,7 +114,14 @@ class ViewController: NSViewController {

}

@IBAction func startPomodoro(_ sender: Any) {
private func setButtonStateAccordingToAbilityToStart() {
let isTimeValid = timeSelector.value.value > 0
let selectedAppsNonEmpty = !selectedApps.apps.isEmpty
pomidoroButton.isEnabled = isTimeValid && selectedAppsNonEmpty
onOffButton.isEnabled = isTimeValid && selectedAppsNonEmpty
}

@IBAction private func startPomodoro(_ sender: Any) {

timeSelector.populate(with: timeOfPomodoro)
start()
Expand Down Expand Up @@ -185,6 +195,7 @@ class ViewController: NSViewController {

remainingTimeLabel.isHidden = !isRunning
timeSelector.isHidden = isRunning
pomidoroButton.isEnabled = !isRunning
onOffButton.image = isRunning ? NSImage(named: "Power On") : NSImage(named: "Power Off")
selectedAppsSourceList.allowsMultipleSelection = true
}
Expand Down

0 comments on commit e952c40

Please sign in to comment.