forked from organicmaps/organicmaps
[iOS] add stats for catalog
This commit is contained in:
parent
278087d0ac
commit
b2a37ece23
4 changed files with 51 additions and 5 deletions
|
@ -29,10 +29,18 @@ final class BookmarksTabViewController: TabViewController {
|
|||
tabView.headerTextAttributes = [.foregroundColor: UIColor.whitePrimaryText(),
|
||||
.font: UIFont.medium14()]
|
||||
tabView.selectedIndex = activeTab.rawValue
|
||||
tabView.delegate = self
|
||||
}
|
||||
|
||||
override func viewDidDisappear(_ animated: Bool) {
|
||||
super.viewDidDisappear(animated)
|
||||
activeTab = ActiveTab.init(rawValue: tabView.selectedIndex) ?? .user
|
||||
activeTab = ActiveTab.init(rawValue: tabView.selectedIndex ?? 0) ?? .user
|
||||
}
|
||||
}
|
||||
|
||||
extension BookmarksTabViewController: TabViewDelegate {
|
||||
func tabView(_ tabView: TabView, didSelectTabAt index: Int) {
|
||||
let selectedTab = index == 0 ? "my" : "downloaded"
|
||||
Statistics.logEvent("Bookmarks_Tab_click", withParameters: [kStatValue : selectedTab])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ final class CatalogWebViewController: WebViewController {
|
|||
let progressImageView = UIImageView(image: #imageLiteral(resourceName: "ic_24px_spinner"))
|
||||
let numberOfTasksLabel = UILabel()
|
||||
var deeplink: URL?
|
||||
var statSent = false
|
||||
|
||||
@objc init() {
|
||||
super.init(url: MWMBookmarksManager.catalogFrontendUrl()!, title: L("routes_and_bookmarks"))!
|
||||
|
@ -94,6 +95,25 @@ final class CatalogWebViewController: WebViewController {
|
|||
decisionHandler(.cancel);
|
||||
}
|
||||
|
||||
override func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
||||
if !statSent {
|
||||
Statistics.logEvent("Bookmarks_Downloaded_Catalogue_open")
|
||||
statSent = true
|
||||
}
|
||||
}
|
||||
|
||||
override func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
|
||||
Statistics.logEvent("Bookmarks_Downloaded_Catalogue_error",
|
||||
withParameters: [kStatError : kStatUnknown])
|
||||
}
|
||||
|
||||
override func webView(_ webView: WKWebView,
|
||||
didFailProvisionalNavigation navigation: WKNavigation!,
|
||||
withError error: Error) {
|
||||
Statistics.logEvent("Bookmarks_Downloaded_Catalogue_error",
|
||||
withParameters: [kStatError : kStatUnknown])
|
||||
}
|
||||
|
||||
func processDeeplink(_ url: URL) {
|
||||
let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
|
||||
var id = ""
|
||||
|
|
|
@ -52,6 +52,8 @@ class DownloadedBookmarksViewController: MWMViewController {
|
|||
@IBAction func onDownloadBookmarks(_ sender: Any) {
|
||||
if MWMPlatform.networkConnectionType() == .none {
|
||||
MWMAlertViewController.activeAlert().presentNoConnectionAlert();
|
||||
Statistics.logEvent("Bookmarks_Downloaded_Catalogue_error",
|
||||
withParameters: [kStatError : "no_internet"])
|
||||
return
|
||||
}
|
||||
let webViewController = CatalogWebViewController()
|
||||
|
|
|
@ -55,6 +55,10 @@ protocol TabViewDataSource: AnyObject {
|
|||
func tabView(_ tabView: TabView, titleAt index: Int) -> String?
|
||||
}
|
||||
|
||||
protocol TabViewDelegate: AnyObject {
|
||||
func tabView(_ tabView: TabView, didSelectTabAt index: Int)
|
||||
}
|
||||
|
||||
@objcMembers
|
||||
@objc(MWMTabView)
|
||||
class TabView: UIView {
|
||||
|
@ -72,9 +76,11 @@ class TabView: UIView {
|
|||
private var slidingViewLeft: NSLayoutConstraint!
|
||||
private var slidingViewWidth: NSLayoutConstraint!
|
||||
private lazy var pageCount = { return self.dataSource?.numberOfPages(in: self) ?? 0; }()
|
||||
var selectedIndex = -1
|
||||
var selectedIndex: Int?
|
||||
private var lastSelectedIndex: Int?
|
||||
|
||||
weak var dataSource: TabViewDataSource?
|
||||
weak var delegate: TabViewDelegate?
|
||||
|
||||
var barTintColor = UIColor.white {
|
||||
didSet {
|
||||
|
@ -194,7 +200,7 @@ class TabView: UIView {
|
|||
super.layoutSubviews()
|
||||
slidingViewWidth.constant = pageCount > 0 ? bounds.width / CGFloat(pageCount) : 0
|
||||
tabsContentCollectionView.layoutIfNeeded()
|
||||
if selectedIndex >= 0 {
|
||||
if let selectedIndex = selectedIndex {
|
||||
tabsContentCollectionView.scrollToItem(at: IndexPath(item: selectedIndex, section: 0),
|
||||
at: .left,
|
||||
animated: false)
|
||||
|
@ -236,14 +242,24 @@ extension TabView : UICollectionViewDelegateFlowLayout {
|
|||
}
|
||||
}
|
||||
|
||||
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
|
||||
lastSelectedIndex = selectedIndex
|
||||
}
|
||||
|
||||
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
|
||||
selectedIndex = Int(round(scrollView.contentOffset.x / scrollView.bounds.width))
|
||||
if let selectedIndex = selectedIndex, selectedIndex != lastSelectedIndex {
|
||||
delegate?.tabView(self, didSelectTabAt: selectedIndex)
|
||||
}
|
||||
}
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
if (collectionView == tabsCollectionView) {
|
||||
selectedIndex = indexPath.item
|
||||
tabsContentCollectionView.scrollToItem(at: indexPath, at: .left, animated: true)
|
||||
if selectedIndex != indexPath.item {
|
||||
selectedIndex = indexPath.item
|
||||
tabsContentCollectionView.scrollToItem(at: indexPath, at: .left, animated: true)
|
||||
delegate?.tabView(self, didSelectTabAt: selectedIndex!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue