| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- //
- // TransmitterSetupViewController.swift
- // CGMBLEKitUI
- //
- // Copyright © 2018 LoopKit Authors. All rights reserved.
- //
- import UIKit
- import LoopKit
- import LoopKitUI
- import CGMBLEKit
- import ShareClient
- class TransmitterSetupViewController: UINavigationController, CGMManagerOnboarding, UINavigationControllerDelegate, CompletionNotifying {
- class func instantiateFromStoryboard() -> TransmitterSetupViewController {
- return UIStoryboard(name: "TransmitterManagerSetup", bundle: Bundle(for: TransmitterSetupViewController.self)).instantiateInitialViewController() as! TransmitterSetupViewController
- }
- weak var cgmManagerOnboardingDelegate: CGMManagerOnboardingDelegate?
- weak var completionDelegate: CompletionDelegate?
- var cgmManagerType: TransmitterManager.Type!
- override func viewDidLoad() {
- super.viewDidLoad()
- delegate = self
- view.backgroundColor = .systemGroupedBackground
- navigationBar.shadowImage = UIImage()
- }
- func completeSetup(state: TransmitterManagerState) {
- if let manager = cgmManagerType.init(state: state) as? CGMManagerUI {
- cgmManagerOnboardingDelegate?.cgmManagerOnboarding(didCreateCGMManager: manager)
- cgmManagerOnboardingDelegate?.cgmManagerOnboarding(didOnboardCGMManager: manager)
- completionDelegate?.completionNotifyingDidComplete(self)
- }
- }
- // MARK: - UINavigationControllerDelegate
- func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
- // Read state values
- let viewControllers = navigationController.viewControllers
- let count = navigationController.viewControllers.count
- if count >= 2 {
- switch viewControllers[count - 2] {
- case _ as TransmitterIDSetupViewController:
- break
- default:
- break
- }
- }
- if let setupViewController = viewController as? SetupTableViewController {
- setupViewController.delegate = self
- }
- // Set state values
- switch viewController {
- case _ as TransmitterIDSetupViewController:
- break
- default:
- break
- }
- // Adjust the appearance for the main setup view controllers only
- if viewController is SetupTableViewController {
- navigationBar.isTranslucent = false
- navigationBar.shadowImage = UIImage()
- } else {
- navigationBar.isTranslucent = true
- navigationBar.shadowImage = nil
- viewController.navigationItem.largeTitleDisplayMode = .never
- }
- }
- func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
- // Adjust the appearance for the main setup view controllers only
- if viewController is SetupTableViewController {
- navigationBar.isTranslucent = false
- navigationBar.shadowImage = UIImage()
- } else {
- navigationBar.isTranslucent = true
- navigationBar.shadowImage = nil
- }
- }
- }
- extension TransmitterSetupViewController: SetupTableViewControllerDelegate {
- public func setupTableViewControllerCancelButtonPressed(_ viewController: SetupTableViewController) {
- completionDelegate?.completionNotifyingDidComplete(self)
- }
- }
|