Skip to content

Commit

Permalink
Fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
aydenp committed Dec 4, 2017
1 parent 6d63813 commit def7800
Show file tree
Hide file tree
Showing 15 changed files with 1,381 additions and 46 deletions.
17 changes: 15 additions & 2 deletions Bank/AccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@

import UIKit

class AccountViewController: UITableViewController {
var account: Account!
class AccountViewController: UITableViewController, AccountHeaderViewDelegate {
weak var delegate: AccountViewControllerDelegate?
var account: Account!, index: (Int, Int)?

override func viewDidLoad() {
super.viewDidLoad()

// Setup header view
headerView.account = account
headerView.accountIndex = index
headerView.delegate = self
// Populate with initial transaction data
populateData()
// Listen for transaction data changes
Expand Down Expand Up @@ -62,4 +65,14 @@ class AccountViewController: UITableViewController {
static func get() -> AccountViewController {
return UIStoryboard(name: "Main", bundle: .main).instantiateViewController(withIdentifier: "Account") as! AccountViewController
}

// MARK: - Account Header View Delegate

func shouldMove(to index: Int) {
delegate?.shouldMove(to: index)
}
}

protocol AccountViewControllerDelegate: class {
func shouldMove(to index: Int)
}
67 changes: 43 additions & 24 deletions Bank/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -155,54 +155,71 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="drY-yl-DdM">
<rect key="frame" x="0.0" y="197.5" width="375" height="162.5"/>
<rect key="frame" x="0.0" y="192.5" width="375" height="167.5"/>
<subviews>
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="abw-PF-ErW">
<rect key="frame" x="177" y="71.5" width="20" height="20"/>
<rect key="frame" x="177" y="74" width="20" height="20"/>
</activityIndicatorView>
</subviews>
<constraints>
<constraint firstItem="abw-PF-ErW" firstAttribute="centerX" secondItem="drY-yl-DdM" secondAttribute="centerX" id="Vl5-L5-WtE"/>
<constraint firstItem="abw-PF-ErW" firstAttribute="centerY" secondItem="drY-yl-DdM" secondAttribute="centerY" id="njA-Hm-ujt"/>
</constraints>
</view>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" spacing="2" translatesAutoresizingMaskIntoConstraints="NO" id="UDC-Ph-GPI">
<rect key="frame" x="20" y="60" width="335" height="117.5"/>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="UDC-Ph-GPI">
<rect key="frame" x="20" y="55" width="335" height="117.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="$---.--" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="KUA-aH-omm" customClass="AmountLabel" customModule="Bank" customModuleProvider="target">
<rect key="frame" x="77" y="0.0" width="181" height="69.5"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="58"/>
<color key="textColor" red="0.32941176470588235" green="0.7803921568627451" blue="0.9882352941176471" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="90y-zk-0Sg">
<rect key="frame" x="99" y="71.5" width="137.5" height="46"/>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" spacing="2" translatesAutoresizingMaskIntoConstraints="NO" id="Vah-3D-xlp">
<rect key="frame" x="77" y="0.0" width="181" height="117.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Account Name" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.75" translatesAutoresizingMaskIntoConstraints="NO" id="Plo-Ia-DOK">
<rect key="frame" x="0.0" y="0.0" width="137.5" height="24"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="20"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="$---.--" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="KUA-aH-omm" customClass="AmountLabel" customModule="Bank" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="181" height="69.5"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="58"/>
<color key="textColor" red="0.32941176470588235" green="0.7803921568627451" blue="0.9882352941176471" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="INSTITUTION NAME" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.75" translatesAutoresizingMaskIntoConstraints="NO" id="5Gl-gL-Tu5">
<rect key="frame" x="0.0" y="29" width="137.5" height="17"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="14"/>
<color key="textColor" red="0.7803921568627451" green="0.7803921568627451" blue="0.80392156862745101" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="90y-zk-0Sg">
<rect key="frame" x="22" y="71.5" width="137.5" height="46"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Account Name" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.75" translatesAutoresizingMaskIntoConstraints="NO" id="Plo-Ia-DOK">
<rect key="frame" x="0.0" y="0.0" width="137.5" height="24"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="20"/>
<color key="textColor" red="0.32941176470588235" green="0.7803921568627451" blue="0.9882352941176471" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="INSTITUTION NAME" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.75" translatesAutoresizingMaskIntoConstraints="NO" id="5Gl-gL-Tu5">
<rect key="frame" x="0.0" y="29" width="137.5" height="17"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="14"/>
<color key="textColor" red="0.7803921568627451" green="0.7803921568627451" blue="0.80392156862745101" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="300" id="c7F-Ha-7Pa"/>
</constraints>
</stackView>
</subviews>
</stackView>
<pageControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" hidesForSinglePage="YES" defersCurrentPageDisplay="YES" numberOfPages="1" translatesAutoresizingMaskIntoConstraints="NO" id="7N1-VT-en8">
<rect key="frame" x="-4499999832.5" y="-55" width="9000000000" height="16"/>
<constraints>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="300" id="c7F-Ha-7Pa"/>
<constraint firstAttribute="height" constant="16" id="pkX-69-Bca"/>
</constraints>
</stackView>
<color key="pageIndicatorTintColor" white="0.80000000000000004" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="currentPageIndicatorTintColor" red="0.3294117647" green="0.78039215689999997" blue="0.98823529409999999" alpha="1" colorSpace="calibratedRGB"/>
<connections>
<action selector="pageControlChanged:" destination="gzl-Ul-oCI" eventType="valueChanged" id="7Zy-cs-Qpm"/>
<action selector="pageControlChanged:" destination="BCK-rc-BfJ" eventType="valueChanged" id="oX9-YP-AS2"/>
</connections>
</pageControl>
</subviews>
</stackView>
</subviews>
<constraints>
<constraint firstItem="drY-yl-DdM" firstAttribute="top" secondItem="UDC-Ph-GPI" secondAttribute="bottom" constant="20" id="3XU-jw-2Oq"/>
<constraint firstAttribute="trailing" secondItem="drY-yl-DdM" secondAttribute="trailing" id="52X-Md-t7h"/>
<constraint firstItem="drY-yl-DdM" firstAttribute="leading" secondItem="BCK-rc-BfJ" secondAttribute="leading" id="CJG-a7-pxy"/>
<constraint firstItem="UDC-Ph-GPI" firstAttribute="top" secondItem="BCK-rc-BfJ" secondAttribute="top" constant="60" id="EBD-qt-7tD"/>
<constraint firstItem="UDC-Ph-GPI" firstAttribute="top" secondItem="BCK-rc-BfJ" secondAttribute="top" constant="55" id="EBD-qt-7tD"/>
<constraint firstItem="UDC-Ph-GPI" firstAttribute="leading" secondItem="BCK-rc-BfJ" secondAttribute="leading" constant="20" id="YKF-mA-Wc8"/>
<constraint firstAttribute="trailing" secondItem="UDC-Ph-GPI" secondAttribute="trailing" constant="20" id="lgY-c9-u5T"/>
<constraint firstAttribute="bottom" secondItem="drY-yl-DdM" secondAttribute="bottom" id="qJI-Na-eJS"/>
Expand All @@ -213,6 +230,7 @@
<outlet property="chartLoadingView" destination="abw-PF-ErW" id="mFm-e9-giY"/>
<outlet property="institutionLabel" destination="5Gl-gL-Tu5" id="TKl-d7-QwK"/>
<outlet property="nameLabel" destination="Plo-Ia-DOK" id="W3J-qN-XBK"/>
<outlet property="pageControl" destination="7N1-VT-en8" id="5RI-lX-7y0"/>
</connections>
</view>
<view key="tableFooterView" contentMode="scaleToFill" id="5ty-Ac-eji">
Expand Down Expand Up @@ -272,6 +290,7 @@
</tableView>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Kfr-ED-fmU" userLabel="First Responder" sceneMemberID="firstResponder"/>
<exit id="gzl-Ul-oCI" userLabel="Exit" sceneMemberID="exit"/>
</objects>
<point key="canvasLocation" x="1037.5999999999999" y="175.86206896551727"/>
</scene>
Expand Down
36 changes: 16 additions & 20 deletions Bank/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

class ViewController: UIPageViewController, UIPageViewControllerDataSource, NoAccountsViewControllerDelegate {
class ViewController: UIPageViewController, UIPageViewControllerDataSource, AccountViewControllerDelegate, NoAccountsViewControllerDelegate {
var statusViewController: StatusViewController?
var isExchanging = false

Expand Down Expand Up @@ -61,9 +61,17 @@ class ViewController: UIPageViewController, UIPageViewControllerDataSource, NoAc
determineStatus()
}

var currentIndex: Int? {
guard let account = (viewControllers?.first as? AccountViewController)?.account else { return nil }
return SessionDataStorage.shared.accounts?.index(of: account)
}

func getViewController(for index: Int) -> AccountViewController {
let vc = AccountViewController.get()
vc.account = SessionDataStorage.shared.accounts?[index]
let pageCount = SessionDataStorage.shared.accounts?.count ?? 0
vc.index = pageCount > 1 ? (index, pageCount) : nil
vc.delegate = self
return vc
}

Expand All @@ -80,27 +88,8 @@ class ViewController: UIPageViewController, UIPageViewControllerDataSource, NoAc
}
}

/// Whether or not swiping to go to the previous/next page is enabled.
var isSwipingEnabled = true {
didSet {
view.subviews.forEach { view in
if let scrollView = view as? UIScrollView { scrollView.isScrollEnabled = isSwipingEnabled }
}
}
}

// MARK: - Page View Controller Data Source

func presentationCount(for pageViewController: UIPageViewController) -> Int {
let count = SessionDataStorage.shared.accounts?.count ?? 0
return count > 1 ? count : 0
}

func presentationIndex(for pageViewController: UIPageViewController) -> Int {
guard let account = ((pageViewController.viewControllers?.first) as? AccountViewController)?.account else { return 0 }
return SessionDataStorage.shared.accounts?.index(of: account) ?? 0
}

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let account = (viewController as? AccountViewController)?.account, let index = SessionDataStorage.shared.accounts?.index(of: account) else { return nil }
let newIndex = index + 1
Expand Down Expand Up @@ -131,4 +120,11 @@ class ViewController: UIPageViewController, UIPageViewControllerDataSource, NoAc
statusViewController = vc
}
}

// MARK: - Account View Controller Delegate

func shouldMove(to index: Int) {
guard let currentIndex = self.currentIndex, currentIndex != index else { return }
setViewControllers([getViewController(for: index)], direction: index > currentIndex ? .forward : .reverse, animated: true, completion: nil)
}
}
22 changes: 22 additions & 0 deletions Bank/Views/AccountHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import UIKit
import SwiftChart

class AccountHeaderView: UIView {
weak var delegate: AccountHeaderViewDelegate?
@IBOutlet weak var amountLabel: AmountLabel!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var institutionLabel: UILabel!
@IBOutlet weak var chartContainerView: UIView!
@IBOutlet weak var chartLoadingView: UIActivityIndicatorView!
@IBOutlet weak var pageControl: UIPageControl!
var hasAwaken = false
var chart: Chart!

Expand Down Expand Up @@ -45,10 +47,18 @@ class AccountHeaderView: UIView {
}
}

var accountIndex: (Int, Int)? {
didSet {
if hasAwaken { setupData() }
}
}

@objc func setupData() {
amountLabel.amount = account?.displayBalance ?? 0
nameLabel.text = account?.name ?? "Account Name"
institutionLabel.text = account?.institutionDescription ?? "Institution Name"
pageControl.numberOfPages = accountIndex?.1 ?? 1
pageControl.currentPage = accountIndex?.0 ?? 0
setupChart()
}

Expand All @@ -66,4 +76,16 @@ class AccountHeaderView: UIView {
}
}
}

// MARK: - Event Handlers

@IBAction func pageControlChanged(_ sender: Any) {
delegate?.shouldMove(to: pageControl.currentPage)
pageControl.currentPage = accountIndex?.0 ?? 0
}

}

protocol AccountHeaderViewDelegate: class {
func shouldMove(to index: Int)
}
21 changes: 21 additions & 0 deletions Pods/SwiftChart/LICENSE.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit def7800

Please sign in to comment.