diff --git a/Guibe.xcodeproj/project.pbxproj b/Guibe.xcodeproj/project.pbxproj index b4b1b4e..6e7282a 100644 --- a/Guibe.xcodeproj/project.pbxproj +++ b/Guibe.xcodeproj/project.pbxproj @@ -20,6 +20,8 @@ 50A7ADFF229D768900D58743 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A7ADFE229D768900D58743 /* MainViewController.swift */; }; 50A7AE02229D7B1100D58743 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50A7AE01229D7B1100D58743 /* MapKit.framework */; }; 50A9B4E1229E115B00070F61 /* Video.mov in Resources */ = {isa = PBXBuildFile; fileRef = 50A9B4E0229E115B00070F61 /* Video.mov */; }; + 50C69B1122A16A7100EA99C1 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C69B1022A16A7100EA99C1 /* TableViewController.swift */; }; + 50C69B1322A19D8800EA99C1 /* NewTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C69B1222A19D8800EA99C1 /* NewTableViewCell.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -39,6 +41,8 @@ 50A7AE01229D7B1100D58743 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; }; 50A7AE05229D7B1E00D58743 /* Guibe.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Guibe.entitlements; sourceTree = ""; }; 50A9B4E0229E115B00070F61 /* Video.mov */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; path = Video.mov; sourceTree = ""; }; + 50C69B1022A16A7100EA99C1 /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; + 50C69B1222A19D8800EA99C1 /* NewTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTableViewCell.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -80,6 +84,8 @@ 50A7ADE6229D6C7100D58743 /* Assets.xcassets */, 50A7ADD8229D6A4200D58743 /* Main.storyboard */, 50A7ADFE229D768900D58743 /* MainViewController.swift */, + 50C69B1022A16A7100EA99C1 /* TableViewController.swift */, + 50C69B1222A19D8800EA99C1 /* NewTableViewCell.swift */, 505AFEF7229FE1BD004FF0F1 /* settingsViewController.swift */, 50A7ADFC229D766800D58743 /* 7_ReadyViewController.swift */, 50A7ADF4229D75A900D58743 /* 3_StartViewController.swift */, @@ -188,8 +194,10 @@ 50A7ADFD229D766800D58743 /* 7_ReadyViewController.swift in Sources */, 50A7ADF9229D75C100D58743 /* 5_HandChoiceViewController.swift in Sources */, 50A7ADD7229D6A4200D58743 /* ViewController.swift in Sources */, + 50C69B1122A16A7100EA99C1 /* TableViewController.swift in Sources */, 50A7ADF5229D75A900D58743 /* 3_StartViewController.swift in Sources */, 50A7ADD5229D6A4200D58743 /* AppDelegate.swift in Sources */, + 50C69B1322A19D8800EA99C1 /* NewTableViewCell.swift in Sources */, 50A7ADFF229D768900D58743 /* MainViewController.swift in Sources */, 50A7ADFB229D75E900D58743 /* 6_SideChoiceViewController.swift in Sources */, 505AFEF8229FE1BD004FF0F1 /* settingsViewController.swift in Sources */, diff --git a/Guibe.xcodeproj/xcuserdata/max.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Guibe.xcodeproj/xcuserdata/max.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..fe2b454 --- /dev/null +++ b/Guibe.xcodeproj/xcuserdata/max.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,5 @@ + + + diff --git a/Guibe/AppDelegate.swift b/Guibe/AppDelegate.swift index 2e8172a..dfc8b36 100644 --- a/Guibe/AppDelegate.swift +++ b/Guibe/AppDelegate.swift @@ -7,11 +7,14 @@ // import UIKit +import MapKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? + + var navigationResults: MKDirections.Response? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { diff --git a/Guibe/Base.lproj/Main.storyboard b/Guibe/Base.lproj/Main.storyboard index 5d69ba8..ffc6a37 100644 --- a/Guibe/Base.lproj/Main.storyboard +++ b/Guibe/Base.lproj/Main.storyboard @@ -300,30 +300,6 @@ - - - - - - - - - - - - - - - - - - @@ -344,6 +320,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Guibe/MainViewController.swift b/Guibe/MainViewController.swift index 146c801..582198b 100644 --- a/Guibe/MainViewController.swift +++ b/Guibe/MainViewController.swift @@ -12,12 +12,20 @@ import MapKit import CoreLocation import AVFoundation -class MainViewController: UIViewController, AVAudioPlayerDelegate { + + + + +class MainViewController: UIViewController, AVAudioPlayerDelegate, myProtocol { + // DELETE let defaults = UserDefaults.standard // DELETE + let appDelegate = UIApplication.shared.delegate as! AppDelegate + + let locationManager = CLLocationManager() var currentCoordinate: CLLocationCoordinate2D! @@ -32,6 +40,7 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate { var startedNavigation: Bool = false + var toLocationId: Int = -1 // OUTLETS--------------OUTLETS @IBOutlet weak var menuWindowView: UIView! @@ -45,7 +54,6 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate { @IBOutlet weak var micBtn: UIButton! // --------------------- @IBOutlet weak var mapView: MKMapView! - // OUTLETS--------------OUTLETS // ACTIONS--------------ACTIONS @@ -101,6 +109,16 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate { let directions = MKDirections(request: directionsRequest) directions.calculate { (response, _) in guard let response = response else { return } + +// self.appDelegate.navigationResults = response + + + +// let resultsViewController = self.storyboard?.instantiateViewController(withIdentifier: "resultsScreen") as! TableViewController +// resultsViewController.searchResults = response +// resultsViewController.modalTransitionStyle = .coverVertical +// self.present(resultsViewController, animated: true, completion: nil) + guard let primaryRoute = response.routes.first else { return } self.mapView.addOverlay(primaryRoute.polyline) @@ -124,6 +142,10 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate { self.stepCounter += 1 } } + + func startNavigation(toPlace: MKMapItem){ + getDirections(to: toPlace) + } } //END OF CLASS @@ -238,7 +260,6 @@ extension MainViewController: CLLocationManagerDelegate { extension MainViewController: UISearchBarDelegate { func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { - print("Here2") searchBar.endEditing(true) //HIDES LE KEYBOARD let localSearchRequest = MKLocalSearch.Request() @@ -248,14 +269,23 @@ extension MainViewController: UISearchBarDelegate { let localSearch = MKLocalSearch(request: localSearchRequest) localSearch.start { (response, _) in guard let response = response else { return } - guard let firstMapItem = response.mapItems.first else { return } - self.getDirections(to: firstMapItem) + + + + let resultsViewController = self.storyboard?.instantiateViewController(withIdentifier: "resultsScreen") as! TableViewController + resultsViewController.searchResults = response.mapItems + resultsViewController.modalTransitionStyle = .coverVertical + resultsViewController.myProtocol = self + self.present(resultsViewController, animated: true, completion: nil) + + + +// guard let firstMapItem = response.mapItems.first else { return } +// self.getDirections(to: firstMapItem) } } } - - extension MainViewController: MKMapViewDelegate { func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer { if overlay is MKPolyline { diff --git a/Guibe/NewTableViewCell.swift b/Guibe/NewTableViewCell.swift new file mode 100644 index 0000000..9c4959d --- /dev/null +++ b/Guibe/NewTableViewCell.swift @@ -0,0 +1,41 @@ +// +// NewTableViewCell.swift +// Guibe +// +// Created by Max Hunt on 31/05/2019. +// Copyright © 2019 8. All rights reserved. +// + +import UIKit + + +protocol tableViewProtocol { + func onClickCell(index: Int) +} + + +class NewTableViewCell: UITableViewCell { + + @IBOutlet weak var primaryLbl: UILabel! + @IBOutlet weak var secondaryLbl: UILabel! + + + @IBAction func goPressed(_ sender: Any) { + cellDelegate?.onClickCell(index: (index?.row)!) + } + + var cellDelegate: tableViewProtocol? + var index: IndexPath? + + override func awakeFromNib() { + super.awakeFromNib() + // Initialization code + } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + +} diff --git a/Guibe/TableViewController.swift b/Guibe/TableViewController.swift new file mode 100644 index 0000000..4af6eca --- /dev/null +++ b/Guibe/TableViewController.swift @@ -0,0 +1,76 @@ +// +// TableViewController.swift +// Guibe +// +// Created by Max Hunt on 31/05/2019. +// Copyright © 2019 8. All rights reserved. +// + +import UIKit +import MapKit + +protocol myProtocol { + func startNavigation(toPlace: MKMapItem) +} + + + +class TableViewController: UIViewController { + + var searchResults: [MKMapItem]? + var myProtocol: myProtocol? + + @IBOutlet weak var tableView: UITableView! + + + override func viewDidLoad() { + super.viewDidLoad() + + +// let testData = appDelegate.navigationResults + } + +// func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { +// return searchResults?.count ?? 0 +// } +// +// func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { +// let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) +// let row = indexPath.row +// +// if let item = searchResults?[row] { +// print(item) +// cell.textLabel?.text = item.name +// } +// +// return cell +// } +} // END OF CLASS + +extension TableViewController: UITableViewDataSource, UITableViewDelegate { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return searchResults?.count ?? 0 + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! NewTableViewCell + + let row = indexPath.row + if let result = searchResults?[row] { + cell.primaryLbl.text = result.name + cell.secondaryLbl.text = result.phoneNumber + cell.cellDelegate = self + cell.index = indexPath + } + + return cell + } +} + +extension TableViewController: tableViewProtocol { + func onClickCell(index: Int) { + debugPrint("Going to navigate to option \(index)") + self.myProtocol?.startNavigation(toPlace: (searchResults?[index])!) + self.dismiss(animated: true, completion: nil) + } +}