Skip to content

Commit

Permalink
added segmented control to adjust distance units
Browse files Browse the repository at this point in the history
  • Loading branch information
clrung committed Dec 12, 2016
1 parent d931db6 commit 1d96f8d
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 18 deletions.
2 changes: 1 addition & 1 deletion DC Metro.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0810;
ORGANIZATIONNAME = "Christopher Rung";
TargetAttributes = {
588D7C461CD1A1CB008A2A22 = {
Expand Down
4 changes: 2 additions & 2 deletions DCMetro/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>2.0.0</string>
<string>2.1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>9</string>
<string>11</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down
33 changes: 27 additions & 6 deletions DCMetroWidget/Base.lproj/TodayViewController.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11542"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="TodayViewController">
Expand Down Expand Up @@ -296,9 +297,9 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ACV-B8-Vee">
<rect key="frame" x="23" y="165" width="164" height="23"/>
<rect key="frame" x="23" y="168" width="164" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="23" id="84s-Io-Vjn"/>
<constraint firstAttribute="height" constant="20" id="84s-Io-Vjn"/>
<constraint firstAttribute="width" constant="160" id="z8M-wI-ekl"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Select a station near you" id="mES-6g-8Ve">
Expand Down Expand Up @@ -386,6 +387,23 @@
<action selector="touchStationPopUpButton:" target="0Rw-a2-Wa9" id="sby-bn-22V"/>
</connections>
</popUpButton>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="wJg-zX-n1u">
<rect key="frame" x="204" y="168" width="113" height="24"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="Qzv-vQ-FfF"/>
<constraint firstAttribute="width" constant="109" id="XHZ-Pb-aPw"/>
</constraints>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="8uy-YH-SQQ">
<font key="font" metaFont="system"/>
<segments>
<segment label="Imperial" width="53" selected="YES"/>
<segment label="Metric" width="53" tag="1"/>
</segments>
</segmentedCell>
<connections>
<action selector="touchUnitsSegmentedControl:" target="0Rw-a2-Wa9" id="5iK-0Q-aPW"/>
</connections>
</segmentedControl>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="2aZ-BT-h88" secondAttribute="bottom" constant="10" id="1mk-e8-Urh"/>
Expand All @@ -395,10 +413,12 @@
<constraint firstItem="nBu-WG-98t" firstAttribute="width" secondItem="dwA-BQ-Qh3" secondAttribute="width" id="Ey4-wV-N9B"/>
<constraint firstItem="nBu-WG-98t" firstAttribute="centerX" secondItem="dwA-BQ-Qh3" secondAttribute="centerX" id="FZc-CB-zRj"/>
<constraint firstItem="3Xg-rL-G4C" firstAttribute="top" secondItem="afb-Tg-MZI" secondAttribute="bottom" id="GYr-U3-IYW"/>
<constraint firstAttribute="trailing" secondItem="wJg-zX-n1u" secondAttribute="trailing" constant="5" id="HVn-tA-ASc"/>
<constraint firstItem="ACV-B8-Vee" firstAttribute="leading" secondItem="dwA-BQ-Qh3" secondAttribute="leading" id="Ioq-sO-pBQ"/>
<constraint firstItem="2aZ-BT-h88" firstAttribute="width" secondItem="dwA-BQ-Qh3" secondAttribute="width" id="N1u-Yy-CNb"/>
<constraint firstItem="3Xg-rL-G4C" firstAttribute="leading" secondItem="dwA-BQ-Qh3" secondAttribute="leading" id="Nfd-CK-LWU"/>
<constraint firstItem="dwA-BQ-Qh3" firstAttribute="height" secondItem="ACV-B8-Vee" secondAttribute="height" id="URi-2Z-0i7"/>
<constraint firstItem="wJg-zX-n1u" firstAttribute="centerY" secondItem="ACV-B8-Vee" secondAttribute="centerY" constant="-2" id="QKk-GP-6zd"/>
<constraint firstItem="dwA-BQ-Qh3" firstAttribute="height" secondItem="ACV-B8-Vee" secondAttribute="height" constant="3" id="URi-2Z-0i7"/>
<constraint firstItem="WNO-CP-OSh" firstAttribute="bottom" secondItem="nBu-WG-98t" secondAttribute="top" id="Utp-eb-zMU"/>
<constraint firstItem="WNO-CP-OSh" firstAttribute="height" secondItem="dwA-BQ-Qh3" secondAttribute="height" id="aGv-Zo-WfS"/>
<constraint firstItem="ACV-B8-Vee" firstAttribute="top" secondItem="HsN-Qm-UAY" secondAttribute="top" id="aPs-B6-d0j"/>
Expand All @@ -414,7 +434,7 @@
<constraint firstItem="WNO-CP-OSh" firstAttribute="top" secondItem="7g1-b0-6tO" secondAttribute="bottom" id="s3B-qp-ICD"/>
<constraint firstItem="dwA-BQ-Qh3" firstAttribute="leading" secondItem="HsN-Qm-UAY" secondAttribute="leading" constant="25" id="tk4-ID-dXR"/>
<constraint firstItem="7g1-b0-6tO" firstAttribute="width" secondItem="dwA-BQ-Qh3" secondAttribute="width" id="u1R-Dv-K9l"/>
<constraint firstItem="dwA-BQ-Qh3" firstAttribute="top" secondItem="ACV-B8-Vee" secondAttribute="bottom" constant="-3" id="y9M-7R-4ec"/>
<constraint firstItem="dwA-BQ-Qh3" firstAttribute="top" secondItem="ACV-B8-Vee" secondAttribute="bottom" id="y9M-7R-4ec"/>
</constraints>
<point key="canvasLocation" x="460" y="774"/>
</customView>
Expand All @@ -429,6 +449,7 @@
<outlet property="stationRadioButton3" destination="WNO-CP-OSh" id="8fb-EE-s4d"/>
<outlet property="stationRadioButton4" destination="nBu-WG-98t" id="I35-QX-aRh"/>
<outlet property="stationRadioButton5" destination="afb-Tg-MZI" id="9BN-9f-jz3"/>
<outlet property="unitsSegmentedControl" destination="wJg-zX-n1u" id="WcC-RA-vbE"/>
<outlet property="view" destination="HsN-Qm-UAY" id="LIU-Gg-VaC"/>
</connections>
</viewController>
Expand Down
4 changes: 2 additions & 2 deletions DCMetroWidget/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>2.0.0</string>
<string>2.1.0</string>
<key>CFBundleSignature</key>
<string>XPC!</string>
<key>CFBundleVersion</key>
<string>9</string>
<string>11</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down
23 changes: 18 additions & 5 deletions DCMetroWidget/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ class SettingsViewController: NCWidgetListViewController {
@IBOutlet weak var chooseFromListTextField: NSTextField!
@IBOutlet weak var stationPopUpButton: NSPopUpButton!

@IBOutlet weak var unitsSegmentedControl: NSSegmentedControl!

override var nibName: String? {
return "SettingsViewController"
}

override func viewDidLoad() {
super.viewDidLoad()
setupPopUpButton()
UserDefaults.standard.bool(forKey: "isMetric") ? unitsSegmentedControl.setSelected(true, forSegment: 1) : unitsSegmentedControl.setSelected(true, forSegment: 0)
}

override func viewWillAppear() {
Expand All @@ -47,11 +50,7 @@ class SettingsViewController: NCWidgetListViewController {
if currentLocation != nil {
selectStationAndRadioButtonsHeightConstraint.constant = 23
chooseFromListTextField.stringValue = "or choose from the list"
for (index, radioButton) in stationRadioButtons.enumerated() {
radioButton.isHidden = false
let station = fiveClosestStations[index]
stationRadioButtons[index].title = station.description + String(format: " (%@)", WMATAfetcher.getDistanceFromStation(location: currentLocation!, station: station, isMetric: false))
}
populateStationRadioButtonTitles()
} else {
selectStationAndRadioButtonsHeightConstraint.constant = 2
chooseFromListTextField.stringValue = "Choose a station from the list"
Expand Down Expand Up @@ -91,6 +90,11 @@ class SettingsViewController: NCWidgetListViewController {
setSelectedStation(sender.selectedItem?.representedObject as! String)
}

@IBAction func touchUnitsSegmentedControl(_ sender: NSSegmentedControl) {
unitsSegmentedControl.isSelected(forSegment: 1) ? UserDefaults.standard.set(true, forKey: "isMetric") : UserDefaults.standard.set(false, forKey: "isMetric")
populateStationRadioButtonTitles()
}

func setSelectedStation(_ selectedStationCode: String) {
for radioButton in stationRadioButtons {
radioButton.state = NSOffState
Expand All @@ -102,4 +106,13 @@ class SettingsViewController: NCWidgetListViewController {
didSelectStation = true
}

func populateStationRadioButtonTitles() {
for (index, radioButton) in stationRadioButtons.enumerated() {
radioButton.isHidden = false
let station = fiveClosestStations[index]
let distance = WMATAfetcher.getDistanceFromStation(location: currentLocation!, station: station, isMetric: unitsSegmentedControl.isSelected(forSegment: 1))
stationRadioButtons[index].title = station.description + String(format: " (%@)", distance)
}
}

}
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PODS:
- Fabric (~> 1.6.3)
- Fabric (1.6.11)
- SwiftyJSON (3.1.3)
- WMATAFetcher (2.2.1):
- WMATAFetcher (2.2.2):
- SwiftyJSON (~> 3.0)

DEPENDENCIES:
Expand All @@ -15,7 +15,7 @@ SPEC CHECKSUMS:
Crashlytics: 2b6dbe138a42395577cfa73dfa1aa7248cadf39e
Fabric: 5911403591946b8228ab1c51d98f1d7137e863c6
SwiftyJSON: 38a8ea2006779c0fc4c310cb2ee8195327740faf
WMATAFetcher: 8353ca1c1244ce7819ffa1a51fdab671d750a7a6
WMATAFetcher: f5ac6d87976045b7625244c6018dd5afd4d7cbfe

PODFILE CHECKSUM: cf472ee5754ad4f01b24dd56f92f19db35f25794

Expand Down
Binary file modified Screenshots/App Store/Main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/App Store/Settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/GitHub/Settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1d96f8d

Please sign in to comment.