Skip to content

Commit

Permalink
Revert "Merge pull request #2652 from mapbox/maxim/566-add-offline-su…
Browse files Browse the repository at this point in the history
…pport"

This reverts commit 080ac48, reversing
changes made to 2a4489c.
  • Loading branch information
MaximAlien committed Oct 26, 2020
1 parent 89f6cf5 commit aea714c
Show file tree
Hide file tree
Showing 30 changed files with 335 additions and 1,096 deletions.
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

* MapboxNavigationNative dependency was updated to v22.0.5 and MapboxCommon to v7.1.2. ([#2648](https://github.com/mapbox/mapbox-navigation-ios/pull/2648))

### Offline

* Added Offline Service support for Maps and Navigation. To allow Mapbox Maps SDK to pick up downloaded regions, `OfflineService` has to be instantiated prior to `MGLMapView`. In case of offline navigation `MapboxNavigationService` and `PassiveLocationDataSource` has to contain `tilesVersion` parameter of downloaded Navigation region. Undeprecated `NavigationDirections`, `OfflineRouteCompletionHandler` and `NavigationDirections.calculate(_:offline:completionHandler:)` and introduced `NavigationDirections.configureRouter(tilesVersion:)` to be able to request route in offline. ([#2653](https://github.com/mapbox/mapbox-navigation-ios/pull/2653))

### Other changes

* `RouteProgress`, `RouteLegProgress`, and `RouteStepProgress` now conform to the `Codable` protocol. ([#2615](https://github.com/mapbox/mapbox-navigation-ios/pull/2615))
Expand Down
13 changes: 0 additions & 13 deletions Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
window!.rootViewController = UIViewController()
}

listMapboxFrameworks()

return true
}

private func isRunningTests() -> Bool {
return NSClassFromString("XCTestCase") != nil
}

private func listMapboxFrameworks() {
NSLog("Versions of linked Mapbox frameworks:")

for framework in Bundle.allFrameworks {
if let bundleIdentifier = framework.bundleIdentifier, bundleIdentifier.contains("mapbox") {
let version = "CFBundleShortVersionString"
NSLog("\(bundleIdentifier): \(framework.infoDictionary?[version] ?? "Unknown version")")
}
}
}
}
9 changes: 2 additions & 7 deletions Example/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
/* CPAlertTemplate OK button title */
"CARPLAY_OK" = "OK";

/* Generic cancel title */
"CANCEL_TITLE" = "Cancel";
/* Title of action for dismissing waypoint removal confirmation sheet */
"REMOVE_WAYPOINT_CONFIRM_CANCEL" = "Cancel";

/* Message of alert confirming waypoint removal */
"REMOVE_WAYPOINT_CONFIRM_MSG" = "Do you want to remove this waypoint?";
Expand All @@ -16,8 +16,3 @@
/* Title of alert confirming waypoint removal */
"REMOVE_WAYPOINT_CONFIRM_TITLE" = "Remove Waypoint?";

/* Offline Service Title */
"OFFLINE_SERVICE_TITLE" = "Offline Service";

/* Close Title */
"CLOSE_TITLE" = "Close";
7 changes: 1 addition & 6 deletions Example/CustomViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ class CustomViewController: UIViewController, MGLMapViewDelegate {
super.viewDidLoad()

let locationManager = simulateLocation ? SimulatedLocationManager(route: userIndexedRoute!.0) : NavigationLocationManager()
navigationService = MapboxNavigationService(route: userIndexedRoute!.0,
routeIndex: userIndexedRoute!.1,
routeOptions: userRouteOptions!,
locationSource: locationManager,
simulating: simulateLocation ? .always : .onPoorGPS,
tilesVersion: OfflineServiceConstants.tilesVersion)
navigationService = MapboxNavigationService(route: userIndexedRoute!.0, routeIndex: userIndexedRoute!.1, routeOptions: userRouteOptions!, locationSource: locationManager, simulating: simulateLocation ? .always : .onPoorGPS)

mapView.delegate = self
mapView.compassView.isHidden = true
Expand Down
129 changes: 129 additions & 0 deletions Example/ResizableView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import UIKit

class ResizableView: UIControl {
let lineLayer = CAShapeLayer()
// Associated background layer will be masked by the frame of the resizable view
weak var backgroundLayer: CAShapeLayer?
let maskLayer = CAShapeLayer()
var imageView: UIImageView!
var panRecognizer: UIPanGestureRecognizer!
var resizePanRecognizer: UIPanGestureRecognizer!

convenience init(frame: CGRect, backgroundLayer: CAShapeLayer) {
self.init(frame: frame)
self.backgroundLayer = backgroundLayer
}

override init(frame: CGRect) {
super.init(frame: frame)

clipsToBounds = false
layer.masksToBounds = false
isUserInteractionEnabled = true
backgroundColor = .clear
isOpaque = false
layer.backgroundColor = UIColor.clear.cgColor

panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(pan(_:)))
resizePanRecognizer = UIPanGestureRecognizer(target: self, action: #selector(resizePan(_:)))

let image = UIImage(named: "ic_resize")!.withPadding(x: 12, y: 12)!
imageView = UIImageView(image: image.withRenderingMode(.alwaysTemplate))
imageView.layer.cornerRadius = image.size.width.mid
imageView.backgroundColor = .white
imageView.tintColor = #colorLiteral(red: 0, green: 0.5490196078, blue: 1, alpha: 1)
imageView.isUserInteractionEnabled = true
imageView.layer.shadowColor = #colorLiteral(red: 0.1029271765, green: 0.08949588804, blue: 0.1094761982, alpha: 0.8005611796)
imageView.layer.shadowOffset = CGSize(width: 0, height: 1)
imageView.layer.shadowOpacity = 1
imageView.layer.shadowRadius = 1.0

panRecognizer.require(toFail: resizePanRecognizer)

addGestureRecognizer(panRecognizer)
imageView.addGestureRecognizer(resizePanRecognizer)
addSubview(imageView)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

@objc func pan(_ sender: UIPanGestureRecognizer) {
if sender.state == .began || sender.state == .changed {
center = sender.location(in: superview)

layoutSubviews()
}
}

@objc func resizePan(_ sender: UIPanGestureRecognizer) {
let location = sender.location(in: superview)

if sender.state == .began || sender.state == .changed {
let origin = CGPoint(x: frame.minX, y: frame.minY)
frame = CGRect(origin: origin,
size: CGSize(width: location.x - origin.x,
height: location.y - origin.y))
layoutSubviews()
}
}

override func layoutSubviews() {
super.layoutSubviews()

if lineLayer.superlayer == nil {
lineLayer.strokeColor = #colorLiteral(red: 0, green: 0.5490196078, blue: 1, alpha: 1).cgColor
lineLayer.fillColor = UIColor.clear.cgColor
lineLayer.lineWidth = 1
lineLayer.lineDashPattern = [5, 5]
layer.addSublayer(lineLayer)
}

lineLayer.path = UIBezierPath(rect: bounds).cgPath

let clippedPath = UIBezierPath(rect: superview!.bounds)
clippedPath.append(UIBezierPath(rect: lineLayer.frame))

let superFrame = self.convert(superview!.bounds, to: self)

if let backgroundLayer = backgroundLayer {
backgroundLayer.path = UIBezierPath(rect: superFrame).cgPath
backgroundLayer.frame = superFrame

let path = UIBezierPath(rect: frame)
path.append(UIBezierPath(rect: backgroundLayer.bounds))

maskLayer.fillRule = .evenOdd
maskLayer.path = path.cgPath
backgroundLayer.mask = maskLayer
}

imageView.center = CGPoint(x: bounds.maxX-5, y: bounds.maxY-5)

bringSubviewToFront(imageView)
}
}

fileprivate extension CGFloat {
var mid: CGFloat {
return self / 2
}
}

extension UIImage {
func withPadding(x: CGFloat, y: CGFloat) -> UIImage? {
let width: CGFloat = size.width + x
let height: CGFloat = size.height + y
UIGraphicsBeginImageContextWithOptions(CGSize(width: width, height: height), false, 0)

defer {
UIGraphicsEndImageContext()
}

let origin: CGPoint = CGPoint(x: (width - size.width) / 2, y: (height - size.height) / 2)
draw(at: origin)

return UIGraphicsGetImageFromCurrentImageContext()
}
}
59 changes: 59 additions & 0 deletions Example/SettingsItems.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import UIKit
import MapboxDirections
import MapboxCoreNavigation

typealias Payload = () -> ()

protocol ItemProtocol {
var title: String { get }
var subtitle: String? { get }
// View controller to present on SettingsViewController.tableView(_:didSelectRowAt:)
var viewControllerType: UIViewController.Type? { get }
// Closure to call on SettingsViewController.tableView(_:didSelectRowAt:)
var payload: Payload? { get }
// SettingsViewController.tableView(_:canEditRowAt:)
var canEditRow: Bool { get }
}

struct Item: ItemProtocol {
let title: String
let subtitle: String?
let viewControllerType: UIViewController.Type?
let payload: Payload?
var canEditRow: Bool

init(title: String, subtitle: String? = nil, viewControllerType: UIViewController.Type? = nil, payload: Payload? = nil, canEditRow: Bool = false) {
self.title = title
self.subtitle = subtitle
self.viewControllerType = viewControllerType
self.payload = payload
self.canEditRow = canEditRow
}
}

struct Section {
let title: String
let items: [ItemProtocol]
}

extension SettingsViewController {
// The property is used to decide whether to show the settings button or not
static let numberOfSections = 0

func sections() -> [Section] {
return []
}
}

extension URL {
var directorySize: Int? {
guard (try? resourceValues(forKeys: [.isDirectoryKey]).isDirectory) as Bool?? != nil else { return nil }
var directorySize = 0

(FileManager.default.enumerator(at: self, includingPropertiesForKeys: nil)?.allObjects as? [URL])?.lazy.forEach {
directorySize += (try? $0.resourceValues(forKeys: [.totalFileAllocatedSizeKey]))?.totalFileAllocatedSize ?? 0
}

return directorySize
}
}
83 changes: 83 additions & 0 deletions Example/SettingsViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import UIKit
import MapboxDirections
import MapboxCoreNavigation

class SettingsViewController: UITableViewController {
let cellIdentifier = "cellId"
var dataSource: [Section]!

override func viewDidLoad() {
super.viewDidLoad()
dataSource = sections()
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Close", style: .done, target: self, action: #selector(close))
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

dataSource = sections()
tableView.reloadData()
}

@IBAction func close() {
dismiss(animated: true, completion: nil)
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell: UITableViewCell! = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)
if cell == nil {
cell = UITableViewCell(style: .subtitle, reuseIdentifier: cellIdentifier)
}

let item = dataSource[indexPath.section].items[indexPath.row]

cell.textLabel?.text = item.title
cell.detailTextLabel?.text = item.subtitle

return cell
}

override func numberOfSections(in tableView: UITableView) -> Int {
return dataSource.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource[section].items.count
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return dataSource[section].title
}

override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return dataSource[indexPath.section].items[indexPath.row].canEditRow
}

override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
return .delete
}

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
let item = dataSource[indexPath.section].items[indexPath.row]

guard let url = Bundle.mapboxCoreNavigation.suggestedTileURL(version: item.title) else { return }
try? FileManager.default.removeItem(atPath: url.path)

dataSource = sections()
tableView.reloadData()
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)

let item = dataSource[indexPath.section].items[indexPath.row]

if let viewController = item.viewControllerType?.init() {
navigationController?.pushViewController(viewController, animated: true)
}

if let payload = item.payload {
payload()
}
}
}
18 changes: 6 additions & 12 deletions Example/UIViewController.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import UIKit

extension UIViewController {

func presentAlert(_ title: String? = nil, message: String? = nil, handler: ((UIAlertAction) -> Void)? = nil) {
DispatchQueue.main.async {
let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)

let defaultHandler: ((UIAlertAction) -> Void) = { (action) in
controller.dismiss(animated: true, completion: nil)
}

controller.addAction(UIAlertAction(title: NSLocalizedString("ALERT_OK", value: "OK", comment: "Alert action"), style: .default, handler: handler ?? defaultHandler))
self.present(controller, animated: true, completion: nil)
}
func presentAlert(_ title: String? = nil, message: String? = nil) {
let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)
controller.addAction(UIAlertAction(title: NSLocalizedString("ALERT_OK", value: "OK", comment: "Alert action"), style: .default, handler: { (action) in
controller.dismiss(animated: true, completion: nil)
}))
present(controller, animated: true, completion: nil)
}
}
Loading

0 comments on commit aea714c

Please sign in to comment.