From 01ec4ac411be6d9fd63b23a5558a7aa79cf16006 Mon Sep 17 00:00:00 2001 From: Max Hunt Date: Mon, 3 Jun 2019 10:52:50 +0100 Subject: [PATCH] minor SBS changes --- Guibe/AppDelegate.swift | 1 + Guibe/MainViewController.swift | 2 ++ Guibe/WrittenInstructionsViewController.swift | 36 +++++++++++++++---- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Guibe/AppDelegate.swift b/Guibe/AppDelegate.swift index de50e3b..ff56329 100644 --- a/Guibe/AppDelegate.swift +++ b/Guibe/AppDelegate.swift @@ -16,6 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var textSteps: [MKRoute.Step]? var currentStep: Int = 0 + var naviStarted: Bool = false func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { diff --git a/Guibe/MainViewController.swift b/Guibe/MainViewController.swift index d010088..9f28114 100644 --- a/Guibe/MainViewController.swift +++ b/Guibe/MainViewController.swift @@ -87,6 +87,7 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate, myProtocol { } // -------------------------- @IBAction func startNaviPressed(_ sender: Any) { + self.appDelegate.naviStarted = true self.startedNavigation = true self.stepCounter += 1 @@ -110,6 +111,7 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate, myProtocol { @IBAction func cancelBtnPressed(_ sender: Any) { self.stepCounter = 0 self.startedNavigation = false + self.appDelegate.naviStarted = false mapView.removeOverlays(mapView.overlays) UIView.animate(withDuration: 0.3, animations: { self.searchView.alpha = 1.0 diff --git a/Guibe/WrittenInstructionsViewController.swift b/Guibe/WrittenInstructionsViewController.swift index d9d5adc..141e60c 100644 --- a/Guibe/WrittenInstructionsViewController.swift +++ b/Guibe/WrittenInstructionsViewController.swift @@ -13,13 +13,19 @@ class WrittenInstructionsViewController: UIViewController, UITableViewDelegate, let appDelegate = UIApplication.shared.delegate as! AppDelegate + // var stepBySteps = appDelegate.currentStep // var currentStep: Int = 0 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - let stepBySteps = appDelegate.textSteps - return stepBySteps?.count ?? 0 + if self.appDelegate.naviStarted == true{ + let stepBySteps = appDelegate.textSteps + return stepBySteps?.count ?? 0} + else { + return 0 + } + } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { @@ -27,11 +33,12 @@ class WrittenInstructionsViewController: UIViewController, UITableViewDelegate, let currentStep = appDelegate.currentStep let stepBySteps = appDelegate.textSteps let focusInstruction = (stepBySteps?[indexPath.row].instructions)! - let focusDistance = (stepBySteps?[indexPath.row].distance)! + let focusDistance = Int((stepBySteps?[indexPath.row].distance)!) + cell.textLabel?.adjustsFontSizeToFitWidth = true if focusInstruction == "" { - cell.textLabel?.text = "Start" } + cell.textLabel?.text = "Start, walk for \(focusDistance) meters" } else { - cell.textLabel?.text = "In \(focusDistance)m, \(focusInstruction)" } + cell.textLabel?.text = "Then in \(focusDistance)m, \(focusInstruction)" } if indexPath.row == currentStep { cell.backgroundColor = .green } else { @@ -56,7 +63,24 @@ class WrittenInstructionsViewController: UIViewController, UITableViewDelegate, override func viewDidLoad() { super.viewDidLoad() - + if appDelegate.naviStarted == false { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { + let alert = UIAlertController(title: "Not Navigating", message: "Please start navigation to see step by step instructions.", preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in + switch action.style{ + case .default: + self.dismiss(animated: true, completion: nil) + + case .cancel: + return + + case .destructive: + return + }})) + self.present(alert, animated: true, completion: nil) + } + } + // Do any additional setup after loading the view. } }