From 7c0f3edab910837dbe970894fe6e21e3fda84df8 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 10 Mar 2020 10:59:20 +0300 Subject: [PATCH] [iOS] Added 'Add map' button in Downloader https://jira.mail.ru/browse/MAPSME-12359 --- iphone/Maps/Bridging-Header.h | 1 + .../MWMMapDownloaderButtonTableViewCell.h | 2 +- .../MWMMapDownloaderButtonTableViewCell.m | 2 +- .../DownloadMapsViewController.swift | 32 ++++++++++++++----- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/iphone/Maps/Bridging-Header.h b/iphone/Maps/Bridging-Header.h index 86644a75cc..907e462a40 100644 --- a/iphone/Maps/Bridging-Header.h +++ b/iphone/Maps/Bridging-Header.h @@ -40,6 +40,7 @@ #import "MWMLocationManager.h" #import "MWMMapWidgetsHelper.h" #import "MWMMapDownloaderTableViewCell.h" +#import "MWMMapDownloaderButtonTableViewCell.h" #import "MWMMapDownloaderPlaceTableViewCell.h" #import "MWMMapDownloaderLargeCountryTableViewCell.h" #import "MWMMapDownloaderSubplaceTableViewCell.h" diff --git a/iphone/Maps/UI/Downloader/Cells/MWMMapDownloaderButtonTableViewCell.h b/iphone/Maps/UI/Downloader/Cells/MWMMapDownloaderButtonTableViewCell.h index 930b239558..c60349a336 100644 --- a/iphone/Maps/UI/Downloader/Cells/MWMMapDownloaderButtonTableViewCell.h +++ b/iphone/Maps/UI/Downloader/Cells/MWMMapDownloaderButtonTableViewCell.h @@ -2,7 +2,7 @@ @protocol MWMMapDownloaderButtonTableViewCellProtocol -- (void)openAvailableMaps; +- (void)onAddMaps; @end diff --git a/iphone/Maps/UI/Downloader/Cells/MWMMapDownloaderButtonTableViewCell.m b/iphone/Maps/UI/Downloader/Cells/MWMMapDownloaderButtonTableViewCell.m index dc8f4ea124..77b3023843 100644 --- a/iphone/Maps/UI/Downloader/Cells/MWMMapDownloaderButtonTableViewCell.m +++ b/iphone/Maps/UI/Downloader/Cells/MWMMapDownloaderButtonTableViewCell.m @@ -24,7 +24,7 @@ - (IBAction)buttonPressed { - [self.delegate openAvailableMaps]; + [self.delegate onAddMaps]; } @end diff --git a/iphone/Maps/UI/Downloader/DownloadMapsViewController.swift b/iphone/Maps/UI/Downloader/DownloadMapsViewController.swift index 1e5bdcf2de..66d13dc6c9 100644 --- a/iphone/Maps/UI/Downloader/DownloadMapsViewController.swift +++ b/iphone/Maps/UI/Downloader/DownloadMapsViewController.swift @@ -33,6 +33,7 @@ class DownloadMapsViewController: MWMViewController { var dataSource: IDownloaderDataSource! @objc var mode: MWMMapDownloaderMode = .downloaded private var skipCountryEvent = false + private var hasAddMapSection: Bool { dataSource.isRoot && mode == .downloaded } lazy var noSerchResultViewController: SearchNoResultsViewController = { let vc = storyboard!.instantiateViewController(ofType: SearchNoResultsViewController.self) @@ -62,6 +63,7 @@ class DownloadMapsViewController: MWMViewController { tableView.registerNib(cell: MWMMapDownloaderPlaceTableViewCell.self) tableView.registerNib(cell: MWMMapDownloaderLargeCountryTableViewCell.self) tableView.registerNib(cell: MWMMapDownloaderSubplaceTableViewCell.self) + tableView.registerNib(cell: MWMMapDownloaderButtonTableViewCell.self) title = dataSource.title if mode == .downloaded { let addMapsButton = button(with: UIImage(named: "ic_nav_bar_add"), action: #selector(onAddMaps)) @@ -192,12 +194,6 @@ class DownloadMapsViewController: MWMViewController { } } - @objc func onAddMaps() { - let vc = storyboard!.instantiateViewController(ofType: DownloadMapsViewController.self) - vc.mode = .available - navigationController?.pushViewController(vc, animated: true) - } - @IBAction func onAllMaps(_ sender: UIButton) { skipCountryEvent = true if mode == .downloaded { @@ -222,14 +218,24 @@ class DownloadMapsViewController: MWMViewController { extension DownloadMapsViewController: UITableViewDataSource { func numberOfSections(in tableView: UITableView) -> Int { - dataSource.numberOfSections() + dataSource.numberOfSections() + (hasAddMapSection ? 1 : 0) } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - dataSource.numberOfItems(in: section) + if hasAddMapSection && section == dataSource.numberOfSections() { + return 1 + } + return dataSource.numberOfItems(in: section) } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + if hasAddMapSection && indexPath.section == dataSource.numberOfSections() { + let cellType = MWMMapDownloaderButtonTableViewCell.self + let buttonCell = tableView.dequeueReusableCell(cell: cellType, indexPath: indexPath) + buttonCell.delegate = self + return buttonCell + } + let nodeAttrs = dataSource.item(at: indexPath) let cell: MWMMapDownloaderTableViewCell if dataSource.item(at: indexPath).hasChildren { @@ -437,3 +443,13 @@ extension DownloadMapsViewController: UIBarPositioningDelegate { .topAttached } } + +// MARK: - MWMMapDownloaderButtonTableViewCellProtocol + +extension DownloadMapsViewController: MWMMapDownloaderButtonTableViewCellProtocol { + @objc func onAddMaps() { + let vc = storyboard!.instantiateViewController(ofType: DownloadMapsViewController.self) + vc.mode = .available + navigationController?.pushViewController(vc, animated: true) + } +}