Add a few more things

This commit is contained in:
IamTheFij 2019-04-08 09:52:11 -07:00
parent e6c3489e66
commit b54dcad16e
2 changed files with 28 additions and 3 deletions

View File

@ -22,7 +22,13 @@
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<items>
<navigationItem title="FitKit" id="2jc-hB-lMj"/>
<navigationItem title="FitKit" id="2jc-hB-lMj">
<barButtonItem key="rightBarButtonItem" title="Log Out" id="A20-nJ-4HO">
<connections>
<action selector="logOut:" destination="BYZ-38-t0r" id="ohP-Rh-eHV"/>
</connections>
</barButtonItem>
</navigationItem>
</items>
</navigationBar>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Logged In" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="CoH-cd-flw">
@ -39,6 +45,14 @@
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="qBL-XQ-4jZ">
<rect key="frame" x="170" y="617" width="34" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<state key="normal" title="Sync"/>
<connections>
<action selector="syncNow:" destination="BYZ-38-t0r" eventType="touchUpInside" id="50A-vo-aNS"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<accessibility key="accessibilityConfiguration">
@ -47,6 +61,7 @@
<viewLayoutGuide key="safeArea" id="OGN-ry-fYp"/>
</view>
<connections>
<outlet property="logInButton" destination="A20-nJ-4HO" id="wg9-Si-CdO"/>
<outlet property="loggedIn" destination="CoH-cd-flw" id="SUh-wA-KNF"/>
<outlet property="outputText" destination="IdY-jU-MBP" id="yl5-f9-Gws"/>
</connections>

View File

@ -14,6 +14,7 @@ class ViewController: UIViewController {
@IBOutlet var loggedIn: UILabel!
@IBOutlet var outputText: UITextView!
@IBOutlet var logInButton: UIBarButtonItem!
let client = FitbitClient()
override func viewDidLoad() {
@ -35,14 +36,23 @@ class ViewController: UIViewController {
DispatchQueue.main.async {
if self.client.isAuthorized() {
self.loggedIn.text = "Logged In"
//self.loginButton.currentTitle = "Log Out"
self.logInButton.title = "Log Out"
} else {
self.loggedIn.text = "Not Logged In"
//self.loginButton.currentTitle = "Log In"
self.logInButton.title = "Log In"
}
}
}
@IBAction func logOut(_ sender: Any) {
NSLog("Log out!!!")
self.client.clearCredential()
self.updateAuthorizedLabel()
}
@IBAction func syncNow(_ sender: Any) {
NSLog("Sync button tapped")
self.syncWeights()
}
/// Ensure that the client is authorized and then continue
fileprivate func ensureAuthorized(callback: @escaping (Bool) -> Void) {
// If already authroized, we can short circuit