guide/Guibe/WrittenInstructionsViewController.swift
2019-06-15 16:51:18 +01:00

95 lines
3.1 KiB
Swift

//
// WrittenInstructionsViewController.swift
// Guibe
//
// Created by Max Hunt on 02/06/2019.
// Copyright © 2019 8. All rights reserved.
//
import UIKit
import MapKit
class WrittenInstructionsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
// var stepBySteps = appDelegate.currentStep
// var currentStep: Int = 0
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if self.appDelegate.naviStarted == true{
let stepBySteps = appDelegate.textSteps
return stepBySteps?.count ?? 0}
else {
return 0
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "iCell", for: indexPath)
let currentStep = appDelegate.currentStep
let stepBySteps = appDelegate.textSteps
let focusInstruction = (stepBySteps?[indexPath.row].instructions)!
let focusDistance = Int((stepBySteps?[indexPath.row].distance)!)
cell.textLabel?.adjustsFontSizeToFitWidth = true
if focusInstruction == "" {
cell.textLabel?.text = "Start, walk for \(focusDistance) meters" }
else {
cell.textLabel?.text = "Then in \(focusDistance)m, \(focusInstruction)" }
if indexPath.row == currentStep {
cell.backgroundColor = .green
let txt = (cell.textLabel?.text)!
cell.accessibilityLabel = "\(txt), current step"
}
else {
cell.accessibilityLabel = cell.textLabel?.text
cell.backgroundColor = .white
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// Maybe speak this?
self.dismiss(animated: true, completion: nil)
}
@IBAction func backBtnPressed(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}
@IBOutlet weak var instructionsTable: UITableView!
@IBOutlet weak var backBtn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
backBtn.accessibilityLabel = "Back"
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.
}
}