[ios] Catalog bugfix and refactoring

This commit is contained in:
Alexey Belousov 2018-06-25 19:12:10 +03:00 committed by Vlad Mihaylenko
parent ed0fbb7095
commit 07888673da
10 changed files with 256 additions and 138 deletions

View file

@ -0,0 +1,34 @@
@objc(MWMBookmarksTabViewController)
class BookmarksTabViewController: TabViewController {
private static let selectedIndexKey = "BookmarksTabViewController_selectedIndexKey"
private var selectedIndex: Int {
get {
return UserDefaults.standard.integer(forKey: BookmarksTabViewController.selectedIndexKey)
}
set {
UserDefaults.standard.set(newValue, forKey: BookmarksTabViewController.selectedIndexKey)
}
}
override func viewDidLoad() {
super.viewDidLoad()
let bookmarks = BMCViewController()
let catalog = DownloadedBookmarksViewController()
bookmarks.title = L("bookmarks_page_my")
catalog.title = L("bookmarks_page_downloaded")
viewControllers = [bookmarks, catalog]
title = L("bookmarks");
tabView.barTintColor = .primary()
tabView.tintColor = .white()
tabView.headerTextAttributes = [.foregroundColor: UIColor.whitePrimaryText(),
.font: UIFont.medium14()]
tabView.selectedIndex = selectedIndex
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
selectedIndex = tabView.selectedIndex
}
}

View file

@ -86,6 +86,16 @@ class CatalogWebViewController: WebViewController {
}
})
if MWMBookmarksManager.isCategoryDownloading(id) {
//TODO: add alert
return
}
if MWMBookmarksManager.hasCategoryDownloaded(id) {
//TODO: add alert
return
}
MWMBookmarksManager.downloadItem(withId: id, name: name, progress: { (progress) in
self.updateProgress()
}) { (error) in
@ -112,8 +122,8 @@ class CatalogWebViewController: WebViewController {
} else {
Toast.toast(withText: L("bookmarks_webview_success_toast")).show()
}
self.updateProgress()
}
self.updateProgress()
}
private func showDiskError() {
@ -134,7 +144,8 @@ class CatalogWebViewController: WebViewController {
}
private func showImportError() {
// TODO: add import error alert
MWMAlertViewController.activeAlert().presentInfoAlert(L("title_error_downloading_bookmarks"),
text: L("subtitle_error_downloading_bookmarks"))
}
private func updateProgress() {

View file

@ -1,16 +1,14 @@
class DownloadedBookmarksViewController: MWMTableViewController {
class DownloadedBookmarksViewController: MWMViewController {
@IBOutlet var topView: UIView!
@IBOutlet var bottomView: UIView!
@IBOutlet weak var noDataView: UIView!
@IBOutlet weak var tableView: UITableView!
let dataSource = DownloadedBookmarksDataSource()
override func viewDidLoad() {
super.viewDidLoad()
if dataSource.categoriesCount == 0 {
tableView.tableHeaderView = topView
}
tableView.tableFooterView = bottomView
tableView.registerNib(cell: CatalogCategoryCell.self)
tableView.registerNibForHeaderFooterView(BMCCategoriesHeader.self)
@ -20,43 +18,10 @@ class DownloadedBookmarksViewController: MWMTableViewController {
super.viewWillAppear(animated)
dataSource.reload()
noDataView.isHidden = dataSource.categoriesCount > 0
tableView.reloadData()
}
override func numberOfSections(in tableView: UITableView) -> Int {
return dataSource.categoriesCount > 0 ? 1 : 0
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource.categoriesCount
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(cell: CatalogCategoryCell.self, indexPath: indexPath)
cell.update(with: dataSource.category(at: indexPath.row), delegate: self)
return cell
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 48
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = tableView.dequeueReusableHeaderFooterView(BMCCategoriesHeader.self)
headerView.isShowAll = !dataSource.allCategoriesVisible
headerView.delegate = self
return headerView
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let category = dataSource.category(at: indexPath.row)
if let bmViewController = BookmarksVC(category: category.categoryId) {
MapViewController.topViewController().navigationController?.pushViewController(bmViewController,
animated: true)
}
}
@IBAction func onDownloadBookmarks(_ sender: Any) {
if MWMPlatform.networkConnectionType() == .none {
MWMAlertViewController.activeAlert().presentNoConnectionAlert();
@ -85,12 +50,51 @@ class DownloadedBookmarksViewController: MWMTableViewController {
}
private func deleteCategory(at index: Int) {
self.dataSource.deleteCategory(at: index)
if self.dataSource.categoriesCount > 0 {
self.tableView.deleteRows(at: [IndexPath(row: index, section: 0)], with: .automatic)
dataSource.deleteCategory(at: index)
if dataSource.categoriesCount > 0 {
tableView.deleteRows(at: [IndexPath(row: index, section: 0)], with: .automatic)
} else {
self.tableView.tableHeaderView = self.topView
self.tableView.reloadData()
noDataView.isHidden = false
tableView.reloadData()
}
}
}
extension DownloadedBookmarksViewController: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return dataSource.categoriesCount > 0 ? 1 : 0
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource.categoriesCount
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(cell: CatalogCategoryCell.self, indexPath: indexPath)
cell.update(with: dataSource.category(at: indexPath.row), delegate: self)
return cell
}
}
extension DownloadedBookmarksViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 48
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = tableView.dequeueReusableHeaderFooterView(BMCCategoriesHeader.self)
headerView.isShowAll = !dataSource.allCategoriesVisible
headerView.delegate = self
return headerView
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let category = dataSource.category(at: indexPath.row)
if let bmViewController = BookmarksVC(category: category.categoryId) {
MapViewController.topViewController().navigationController?.pushViewController(bmViewController,
animated: true)
}
}
}

View file

@ -13,27 +13,18 @@
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="DownloadedBookmarksViewController" customModule="maps_me" customModuleProvider="target">
<connections>
<outlet property="bottomView" destination="A19-bw-qEr" id="kih-zB-eh4"/>
<outlet property="topView" destination="EF0-Bq-c6F" id="P2B-zS-paE"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
<outlet property="noDataView" destination="EF0-Bq-c6F" id="Zna-hA-2r3"/>
<outlet property="tableView" destination="i5M-Pr-FkT" id="hZS-jj-xH4"/>
<outlet property="view" destination="Q8q-x4-Mvv" id="Ch1-sh-by5"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableView opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" bouncesZoom="NO" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<viewLayoutGuide key="safeArea" id="vLr-E1-eTs"/>
<connections>
<outlet property="dataSource" destination="-1" id="Tng-2m-Rnh"/>
<outlet property="delegate" destination="-1" id="9aC-8N-iBw"/>
</connections>
</tableView>
<view contentMode="scaleToFill" id="A19-bw-qEr">
<rect key="frame" x="0.0" y="0.0" width="375" height="76"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="161"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Yjf-3F-Ewf" userLabel="NotNow">
<rect key="frame" x="16" y="16" width="343" height="44"/>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" verticalHuggingPriority="251" verticalCompressionResistancePriority="751" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Yjf-3F-Ewf" userLabel="NotNow">
<rect key="frame" x="16" y="107.5" width="343" height="37.5"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" priority="750" constant="44" id="I5l-6h-e83"/>
@ -57,60 +48,132 @@
<action selector="onDownloadBookmarks:" destination="-1" eventType="touchUpInside" id="sde-zI-dEe"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="mHu-Y0-fCQ" firstAttribute="bottom" secondItem="Yjf-3F-Ewf" secondAttribute="bottom" constant="16" id="9ps-Bp-5C5"/>
<constraint firstItem="Yjf-3F-Ewf" firstAttribute="leading" secondItem="mHu-Y0-fCQ" secondAttribute="leading" constant="16" id="LCM-df-yqM"/>
<constraint firstItem="mHu-Y0-fCQ" firstAttribute="trailing" secondItem="Yjf-3F-Ewf" secondAttribute="trailing" constant="16" id="P85-sm-grd"/>
<constraint firstItem="Yjf-3F-Ewf" firstAttribute="top" secondItem="mHu-Y0-fCQ" secondAttribute="top" constant="16" id="n9w-00-rYO"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<viewLayoutGuide key="safeArea" id="mHu-Y0-fCQ"/>
<point key="canvasLocation" x="483" y="492"/>
</view>
<view contentMode="scaleToFill" id="EF0-Bq-c6F">
<rect key="frame" x="0.0" y="0.0" width="375" height="349"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="img_empty_bookmarks" translatesAutoresizingMaskIntoConstraints="NO" id="ahy-M3-meH">
<rect key="frame" x="87.5" y="40" width="200" height="200"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Download new places" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="13b-uj-bGK">
<rect key="frame" x="16" y="256" width="343" height="24"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<color key="textColor" white="0.0" alpha="0.87371575342465757" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="751" text="DOWNLOAD NEW PLACES" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TnJ-F3-v3h">
<rect key="frame" x="16" y="12" width="343" height="17"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="14"/>
<color key="textColor" white="0.0" alpha="0.5586472602739726" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="cached_bookmarks_placeholder_title"/>
</userDefinedRuntimeAttributes>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="TopLeft" horizontalHuggingPriority="251" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1gY-vv-QfN">
<rect key="frame" x="16" y="288" width="343" height="53"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lZi-fE-uf3">
<rect key="frame" x="16" y="41" width="343" height="50.5"/>
<string key="text">Press the button to download thousands of intresting places and routes created by MAPS.ME users. You will need the internet connection.</string>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" white="0.0" alpha="0.53735017123287676" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="textColor" white="0.0" alpha="0.54010595034246578" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="cached_bookmarks_placeholder_subtitle"/>
</userDefinedRuntimeAttributes>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="1gY-vv-QfN" firstAttribute="trailing" secondItem="13b-uj-bGK" secondAttribute="trailing" id="24k-XV-fh7"/>
<constraint firstItem="13b-uj-bGK" firstAttribute="leading" secondItem="jiO-QA-gWD" secondAttribute="leading" constant="16" id="JLq-wb-chA"/>
<constraint firstItem="1gY-vv-QfN" firstAttribute="top" secondItem="13b-uj-bGK" secondAttribute="bottom" constant="8" id="TND-0r-7FO"/>
<constraint firstItem="ahy-M3-meH" firstAttribute="centerX" secondItem="jiO-QA-gWD" secondAttribute="centerX" id="VjC-b4-t1W"/>
<constraint firstItem="jiO-QA-gWD" firstAttribute="bottom" secondItem="1gY-vv-QfN" secondAttribute="bottom" constant="8" id="Xa8-RL-OhU"/>
<constraint firstItem="1gY-vv-QfN" firstAttribute="leading" secondItem="13b-uj-bGK" secondAttribute="leading" id="Yju-ZI-ayo"/>
<constraint firstItem="jiO-QA-gWD" firstAttribute="trailing" secondItem="13b-uj-bGK" secondAttribute="trailing" constant="16" id="a1y-O4-QFn"/>
<constraint firstItem="13b-uj-bGK" firstAttribute="top" secondItem="ahy-M3-meH" secondAttribute="bottom" constant="16" id="fjL-BN-m8O"/>
<constraint firstItem="ahy-M3-meH" firstAttribute="top" secondItem="jiO-QA-gWD" secondAttribute="top" constant="40" id="tdz-sP-cyI"/>
<constraint firstAttribute="trailing" secondItem="TnJ-F3-v3h" secondAttribute="trailing" constant="16" id="60Y-LP-DTq"/>
<constraint firstAttribute="bottom" secondItem="Yjf-3F-Ewf" secondAttribute="bottom" constant="16" id="9ps-Bp-5C5"/>
<constraint firstItem="lZi-fE-uf3" firstAttribute="leading" secondItem="TnJ-F3-v3h" secondAttribute="leading" id="KcF-yb-1YG"/>
<constraint firstItem="Yjf-3F-Ewf" firstAttribute="leading" secondItem="A19-bw-qEr" secondAttribute="leading" constant="16" id="LCM-df-yqM"/>
<constraint firstAttribute="trailing" secondItem="Yjf-3F-Ewf" secondAttribute="trailing" constant="16" id="P85-sm-grd"/>
<constraint firstItem="TnJ-F3-v3h" firstAttribute="top" secondItem="A19-bw-qEr" secondAttribute="top" constant="12" id="WRg-Kb-Ahh"/>
<constraint firstItem="TnJ-F3-v3h" firstAttribute="leading" secondItem="A19-bw-qEr" secondAttribute="leading" constant="16" id="bhK-YJ-ofg"/>
<constraint firstItem="lZi-fE-uf3" firstAttribute="trailing" secondItem="TnJ-F3-v3h" secondAttribute="trailing" id="f2s-Q9-s4h"/>
<constraint firstItem="Yjf-3F-Ewf" firstAttribute="top" secondItem="lZi-fE-uf3" secondAttribute="bottom" constant="16" id="l9P-Ku-GZY"/>
<constraint firstItem="lZi-fE-uf3" firstAttribute="top" secondItem="TnJ-F3-v3h" secondAttribute="bottom" constant="12" id="vO0-Ba-ex8"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<viewLayoutGuide key="safeArea" id="jiO-QA-gWD"/>
<point key="canvasLocation" x="450.5" y="158.5"/>
<viewLayoutGuide key="safeArea" id="nPB-bx-EIH"/>
<point key="canvasLocation" x="458.5" y="471.5"/>
</view>
<view contentMode="scaleToFill" id="Q8q-x4-Mvv">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<tableView opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" bouncesZoom="NO" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" translatesAutoresizingMaskIntoConstraints="NO" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<connections>
<outlet property="dataSource" destination="-1" id="Tng-2m-Rnh"/>
<outlet property="delegate" destination="-1" id="9aC-8N-iBw"/>
</connections>
</tableView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="EF0-Bq-c6F">
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="img_empty_bookmarks" translatesAutoresizingMaskIntoConstraints="NO" id="ahy-M3-meH">
<rect key="frame" x="88" y="40" width="200" height="200"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Download new places" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="13b-uj-bGK">
<rect key="frame" x="16" y="256" width="343" height="24"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<color key="textColor" white="0.0" alpha="0.87371575342465757" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="cached_bookmarks_placeholder_title"/>
</userDefinedRuntimeAttributes>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="TopLeft" horizontalHuggingPriority="251" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1gY-vv-QfN">
<rect key="frame" x="16" y="288" width="343" height="50.5"/>
<string key="text">Press the button to download thousands of intresting places and routes created by MAPS.ME users. You will need the internet connection.</string>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" white="0.0" alpha="0.53735017123287676" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="cached_bookmarks_placeholder_subtitle"/>
</userDefinedRuntimeAttributes>
</label>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kER-re-108" userLabel="NotNow">
<rect key="frame" x="16" y="364.5" width="343" height="44"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" priority="750" constant="44" id="GMD-2V-uPA"/>
</constraints>
<fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="17"/>
<state key="normal" title="DOWNLOAD BOOKMARKS">
<color key="titleColor" red="0.01176470588" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="textColorHighlightedName" value="white"/>
<userDefinedRuntimeAttribute type="string" keyPath="fontName" value="medium14"/>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="8"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="string" keyPath="textColorName" value="white"/>
<userDefinedRuntimeAttribute type="string" keyPath="backgroundColorName" value="linkBlue"/>
<userDefinedRuntimeAttribute type="string" keyPath="backgroundHighlightedColorName" value="linkBlueHighlighted"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="onDownloadBookmarks:" destination="-1" eventType="touchUpInside" id="u6w-gS-8w1"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="1gY-vv-QfN" firstAttribute="trailing" secondItem="13b-uj-bGK" secondAttribute="trailing" id="24k-XV-fh7"/>
<constraint firstItem="kER-re-108" firstAttribute="top" secondItem="1gY-vv-QfN" secondAttribute="bottom" constant="26" id="Hz8-vx-8Au"/>
<constraint firstItem="13b-uj-bGK" firstAttribute="leading" secondItem="EF0-Bq-c6F" secondAttribute="leading" constant="16" id="JLq-wb-chA"/>
<constraint firstItem="1gY-vv-QfN" firstAttribute="top" secondItem="13b-uj-bGK" secondAttribute="bottom" constant="8" id="TND-0r-7FO"/>
<constraint firstItem="ahy-M3-meH" firstAttribute="centerX" secondItem="EF0-Bq-c6F" secondAttribute="centerX" id="VjC-b4-t1W"/>
<constraint firstItem="1gY-vv-QfN" firstAttribute="leading" secondItem="13b-uj-bGK" secondAttribute="leading" id="Yju-ZI-ayo"/>
<constraint firstAttribute="trailing" secondItem="13b-uj-bGK" secondAttribute="trailing" constant="16" id="a1y-O4-QFn"/>
<constraint firstItem="13b-uj-bGK" firstAttribute="top" secondItem="ahy-M3-meH" secondAttribute="bottom" constant="16" id="fjL-BN-m8O"/>
<constraint firstItem="kER-re-108" firstAttribute="leading" secondItem="1gY-vv-QfN" secondAttribute="leading" id="hOa-iZ-SPL"/>
<constraint firstItem="kER-re-108" firstAttribute="trailing" secondItem="1gY-vv-QfN" secondAttribute="trailing" id="lNV-h2-oYP"/>
<constraint firstItem="ahy-M3-meH" firstAttribute="top" secondItem="EF0-Bq-c6F" secondAttribute="top" constant="40" id="tdz-sP-cyI"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="backgroundColorName" value="white"/>
</userDefinedRuntimeAttributes>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="Ceu-pi-1ck" firstAttribute="bottom" secondItem="EF0-Bq-c6F" secondAttribute="bottom" id="5y4-yL-yj0"/>
<constraint firstItem="EF0-Bq-c6F" firstAttribute="trailing" secondItem="Ceu-pi-1ck" secondAttribute="trailing" id="6kC-Cy-pKw"/>
<constraint firstItem="EF0-Bq-c6F" firstAttribute="leading" secondItem="Ceu-pi-1ck" secondAttribute="leading" id="960-JS-u7u"/>
<constraint firstItem="Ceu-pi-1ck" firstAttribute="bottom" secondItem="i5M-Pr-FkT" secondAttribute="bottom" id="FuD-uD-FSR"/>
<constraint firstItem="Ceu-pi-1ck" firstAttribute="top" secondItem="EF0-Bq-c6F" secondAttribute="top" id="O8B-1S-ys6"/>
<constraint firstItem="Ceu-pi-1ck" firstAttribute="trailing" secondItem="i5M-Pr-FkT" secondAttribute="trailing" id="XBC-8g-rDM"/>
<constraint firstItem="i5M-Pr-FkT" firstAttribute="leading" secondItem="Ceu-pi-1ck" secondAttribute="leading" id="gVE-Vs-wgj"/>
<constraint firstItem="Ceu-pi-1ck" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" id="pYZ-O3-uHP"/>
</constraints>
<viewLayoutGuide key="safeArea" id="Ceu-pi-1ck"/>
<point key="canvasLocation" x="-437" y="21"/>
</view>
</objects>
<resources>

View file

@ -75,7 +75,8 @@ class TabView: UIView {
private let slidingView = UIView()
private var slidingViewLeft: NSLayoutConstraint!
private var slidingViewWidth: NSLayoutConstraint!
private var pageCount = 0
private lazy var pageCount = { return self.dataSource?.numberOfPages(in: self) ?? 0; }()
var selectedIndex = -1
weak var dataSource: TabViewDataSource?
@ -191,17 +192,16 @@ class TabView: UIView {
slidingView.addConstraint(slidingViewWidth)
}
override func willMove(toSuperview newSuperview: UIView?) {
super.willMove(toSuperview: newSuperview)
pageCount = dataSource?.numberOfPages(in: self) ?? 0
}
override func layoutSubviews() {
super.layoutSubviews()
slidingViewWidth.constant = bounds.width / CGFloat(pageCount)
slidingViewWidth.constant = pageCount > 0 ? bounds.width / CGFloat(pageCount) : 0
tabsLayout.invalidateLayout()
tabsContentLayout.invalidateLayout()
tabsContentCollectionView.layoutIfNeeded()
if selectedIndex >= 0 {
tabsContentCollectionView.scrollToItem(at: IndexPath(item: selectedIndex, section: 0), at: .left, animated: false)
}
}
}
@ -237,8 +237,13 @@ extension TabView : UICollectionViewDelegateFlowLayout {
slidingViewLeft.constant = scrollOffset * bounds.width
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
selectedIndex = Int(round(scrollView.contentOffset.x / scrollView.bounds.width))
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if (collectionView == tabsCollectionView) {
selectedIndex = indexPath.item
tabsContentCollectionView.scrollToItem(at: indexPath, at: .left, animated: true)
}
}

View file

@ -1,8 +1,13 @@
@objcMembers
@objc(MWMTabViewController)
class TabViewController: MWMViewController {
var viewControllers: [UIViewController] = []
var selectedIndex = 0
var viewControllers: [UIViewController] = [] {
didSet {
viewControllers.forEach {
self.addChildViewController($0)
$0.didMove(toParentViewController: self)
}
}
}
var tabView: TabView {
get {
return view as! TabView
@ -14,15 +19,6 @@ class TabViewController: MWMViewController {
v.dataSource = self
view = v
}
override func viewDidLoad() {
super.viewDidLoad()
viewControllers.forEach { (vc) in
self.addChildViewController(vc)
vc.didMove(toParentViewController: self)
}
}
}
extension TabViewController: TabViewDataSource {

View file

@ -358,19 +358,8 @@ BOOL gIsFirstMyPositionMode = YES;
- (void)openMigration { [self performSegueWithIdentifier:kMigrationSegue sender:self]; }
- (void)openBookmarks
{
BMCViewController * bookmarks = [[BMCViewController alloc] init];
DownloadedBookmarksViewController * catalog = [[DownloadedBookmarksViewController alloc] init];
bookmarks.title = L(@"bookmarks_page_my");
catalog.title = L(@"bookmarks_page_downloaded");
MWMTabViewController * tvc = [[MWMTabViewController alloc] init];
tvc.title = L(@"bookmarks");
tvc.tabView.barTintColor = [UIColor primary];
tvc.tabView.tintColor = [UIColor white];
tvc.tabView.headerTextAttributes = @{NSForegroundColorAttributeName: [UIColor whitePrimaryText],
NSFontAttributeName: [UIFont medium14]};
tvc.viewControllers = @[bookmarks, catalog];
[self.navigationController pushViewController:tvc animated:YES];
[self.navigationController pushViewController:[[MWMBookmarksTabViewController alloc] init]
animated:YES];
}
- (void)openMapsDownloader:(MWMMapDownloaderMode)mode

View file

@ -55,6 +55,8 @@
+ (BOOL)isCategoryFromCatalog:(MWMMarkGroupID)groupId;
+ (NSArray<MWMCatalogCategory *> * _Nonnull)categoriesFromCatalog;
+ (NSInteger)getCatalogDownloadsCount;
+ (BOOL)isCategoryDownloading:(NSString * _Nonnull)itemId;
+ (BOOL)hasCategoryDownloaded:(NSString * _Nonnull)itemId;
- (instancetype)init __attribute__((unavailable("call +manager instead")));
- (instancetype)copy __attribute__((unavailable("call +manager instead")));

View file

@ -540,4 +540,14 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
return GetFramework().GetBookmarkManager().GetCatalog().GetDownloadingCount();
}
+ (BOOL)isCategoryDownloading:(NSString *)itemId
{
return GetFramework().GetBookmarkManager().GetCatalog().IsDownloading(itemId.UTF8String);
}
+ (BOOL)hasCategoryDownloaded:(NSString *)itemId
{
return GetFramework().GetBookmarkManager().GetCatalog().HasDownloaded(itemId.UTF8String);
}
@end

View file

@ -470,6 +470,7 @@
B33D21AD20DA515800BAD749 /* MWMCategoryInfoCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B33D21AB20DA515800BAD749 /* MWMCategoryInfoCell.xib */; };
B33D21AF20DAF9F000BAD749 /* Toast.swift in Sources */ = {isa = PBXBuildFile; fileRef = B33D21AE20DAF9F000BAD749 /* Toast.swift */; };
B33D21B220DBCC5E00BAD749 /* MWMCatalogObserver.mm in Sources */ = {isa = PBXBuildFile; fileRef = B33D21B120DBCC5D00BAD749 /* MWMCatalogObserver.mm */; };
B33D21B820E130D000BAD749 /* BookmarksTabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B33D21B720E130D000BAD749 /* BookmarksTabViewController.swift */; };
B366130420D5D9BC00E7DC3E /* MWMCatalogCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = B366130320D5D9BC00E7DC3E /* MWMCatalogCategory.m */; };
B366130720D5DD2300E7DC3E /* MWMCatalogCategory+Convenience.mm in Sources */ = {isa = PBXBuildFile; fileRef = B366130620D5DD2300E7DC3E /* MWMCatalogCategory+Convenience.mm */; };
B366130A20D5E2E000E7DC3E /* CatalogCategoryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B366130820D5E2E000E7DC3E /* CatalogCategoryCell.swift */; };
@ -1399,6 +1400,7 @@
B33D21B020DBCC5D00BAD749 /* MWMCatalogObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMCatalogObserver.h; sourceTree = "<group>"; };
B33D21B120DBCC5D00BAD749 /* MWMCatalogObserver.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMCatalogObserver.mm; sourceTree = "<group>"; };
B33D21B320DBF3EB00BAD749 /* MWMCatalogCommon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMCatalogCommon.h; sourceTree = "<group>"; };
B33D21B720E130D000BAD749 /* BookmarksTabViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksTabViewController.swift; sourceTree = "<group>"; };
B366130220D5D9BC00E7DC3E /* MWMCatalogCategory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMCatalogCategory.h; sourceTree = "<group>"; };
B366130320D5D9BC00E7DC3E /* MWMCatalogCategory.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MWMCatalogCategory.m; sourceTree = "<group>"; };
B366130520D5DD2300E7DC3E /* MWMCatalogCategory+Convenience.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MWMCatalogCategory+Convenience.h"; sourceTree = "<group>"; };
@ -4114,6 +4116,7 @@
3404F4A02028A6C00090E401 /* Categories */,
FA054610155C465E001F4E37 /* SelectSetVC.h */,
FA054611155C465E001F4E37 /* SelectSetVC.mm */,
B33D21B720E130D000BAD749 /* BookmarksTabViewController.swift */,
);
path = Bookmarks;
sourceTree = "<group>";
@ -4721,6 +4724,7 @@
34BBD65C1F826FD30070CA50 /* AuthorizationiPhonePresentationController.swift in Sources */,
56C74C391C74A3BC00B71B9F /* MWMInputEmailValidator.mm in Sources */,
6741A9F51BF340DE002C974C /* BookmarksVC.mm in Sources */,
B33D21B820E130D000BAD749 /* BookmarksTabViewController.swift in Sources */,
3404754A1E081A4600C92850 /* AppInfo.mm in Sources */,
34AB662F1FC5AA330078E451 /* RouteManageriPhonePresentationController.swift in Sources */,
34AB66201FC5AA330078E451 /* RouteStartButton.swift in Sources */,