Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
SynchronyFinancialWatchApp/SynchronyFinancial/SynchronyFinancial WatchKit Extension/UtilizationTrendInterfaceController.swift
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
59 lines (51 sloc)
1.95 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UtilizationTrendInterfaceController.swift | |
// SynchronyFinancial WatchKit Extension | |
// | |
// Created by Alan Maynard on 4/17/19. | |
// Copyright © 2019 Alan Maynard. All rights reserved. | |
// | |
import WatchKit | |
import Foundation | |
class UtilizationTrendInterfaceController: WKInterfaceController { | |
@IBOutlet var trendImage: WKInterfaceImage! | |
@IBOutlet var trendLabel: WKInterfaceLabel! | |
var previousUtilization: Int? | |
var currentUtilization: Int? | |
override func awake(withContext context: Any?) { | |
super.awake(withContext: context) | |
guard let data = context as? [Int], data.count == 2 else { | |
NSLog("Error getting utilization data from wellness.") | |
return | |
} | |
previousUtilization = data[1] | |
currentUtilization = data[0] | |
configure() | |
} | |
override func didAppear() { | |
// This method is called when watch view controller is about to be visible to user | |
super.didAppear() | |
animate(withDuration: 1.5) { | |
self.trendImage.setAlpha(1.0) | |
self.trendLabel.setAlpha(1.0) | |
} | |
} | |
override func didDeactivate() { | |
// This method is called when watch view controller is no longer visible | |
super.didDeactivate() | |
} | |
private func configure() { | |
if let prev = previousUtilization, let curr = currentUtilization { | |
if prev > curr { | |
trendImage.setImageNamed("arrow_down") | |
trendLabel.setText("Down from \(prev)% last statement.") | |
} else { | |
trendImage.setImageNamed("arrow_up") | |
trendLabel.setText("Up from \(prev)% last statement.") | |
} | |
} | |
} | |
@IBAction func showDetails() { | |
presentAlert(withTitle: "Trends", message: "Lowering your utilization over time can help reduce the amount of interest accrued on your accounts.", preferredStyle: .alert, actions: [WKAlertAction(title: "Done", style: .default, handler: {})]) | |
} | |
} |