101 lines
2.7 KiB
Swift
101 lines
2.7 KiB
Swift
protocol BottomMenuInteractorProtocol: AnyObject {
|
|
func close()
|
|
func addPlace()
|
|
func downloadMaps()
|
|
func donate()
|
|
func openHelp()
|
|
func openSettings()
|
|
func shareLocation(cell: BottomMenuItemCell)
|
|
func toggleTrackRecording()
|
|
}
|
|
|
|
@objc protocol BottomMenuDelegate {
|
|
func actionDownloadMaps(_ mode: MWMMapDownloaderMode)
|
|
func addPlace()
|
|
func didFinishAddingPlace()
|
|
}
|
|
|
|
class BottomMenuInteractor {
|
|
weak var presenter: BottomMenuPresenterProtocol?
|
|
private weak var viewController: UIViewController?
|
|
private weak var mapViewController: MapViewController?
|
|
private weak var delegate: BottomMenuDelegate?
|
|
private weak var controlsManager: MWMMapViewControlsManager?
|
|
|
|
private let trackRecorder: TrackRecordingManager = .shared
|
|
|
|
init(viewController: UIViewController,
|
|
mapViewController: MapViewController,
|
|
controlsManager: MWMMapViewControlsManager,
|
|
delegate: BottomMenuDelegate) {
|
|
self.viewController = viewController
|
|
self.mapViewController = mapViewController
|
|
self.delegate = delegate
|
|
self.controlsManager = controlsManager
|
|
}
|
|
}
|
|
|
|
extension BottomMenuInteractor: BottomMenuInteractorProtocol {
|
|
func close() {
|
|
guard let controlsManager = controlsManager else {
|
|
fatalError()
|
|
}
|
|
controlsManager.menuState = controlsManager.menuRestoreState
|
|
}
|
|
|
|
func addPlace() {
|
|
delegate?.addPlace()
|
|
}
|
|
|
|
func donate() {
|
|
close()
|
|
guard var url = SettingsBridge.donateUrl() else { return }
|
|
if url == "https://www.comaps.app/donate/" {
|
|
url = L("translated_om_site_url") + "donate/"
|
|
}
|
|
viewController?.openUrl(url, externally: true)
|
|
}
|
|
|
|
func downloadMaps() {
|
|
close()
|
|
delegate?.actionDownloadMaps(.downloaded)
|
|
}
|
|
|
|
func openHelp() {
|
|
close()
|
|
mapViewController?.openAbout()
|
|
}
|
|
|
|
func openSettings() {
|
|
close()
|
|
mapViewController?.openSettings()
|
|
}
|
|
|
|
func shareLocation(cell: BottomMenuItemCell) {
|
|
guard let coordinates = LocationManager.lastLocation()?.coordinate else {
|
|
viewController?.present(UIAlertController.unknownCurrentPosition(), animated: true, completion: nil)
|
|
return
|
|
}
|
|
guard let viewController = viewController else { return }
|
|
let vc = ActivityViewController.share(forMyPosition: coordinates)
|
|
vc.present(inParentViewController: viewController, anchorView: cell.anchorView)
|
|
}
|
|
|
|
func toggleTrackRecording() {
|
|
close()
|
|
let mapViewController = MapViewController.shared()!
|
|
switch trackRecorder.recordingState {
|
|
case .active:
|
|
mapViewController.showTrackRecordingPlacePage()
|
|
case .inactive:
|
|
trackRecorder.start { result in
|
|
switch result {
|
|
case .success:
|
|
mapViewController.showTrackRecordingPlacePage()
|
|
case .failure:
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|