From edc86c72d3bc964d9dc87c426809058bee3a30de Mon Sep 17 00:00:00 2001 From: Kiryl Kaveryn Date: Fri, 18 Oct 2024 23:43:51 +0400 Subject: [PATCH] fix 3 Signed-off-by: Kiryl Kaveryn --- iphone/CoreApi/CoreApi/Bookmarks/MWMTrack.h | 7 ++- iphone/CoreApi/CoreApi/Bookmarks/MWMTrack.mm | 2 + .../CoreApi/PlacePageData/PlacePageData.h | 3 +- .../CoreApi/PlacePageData/PlacePageData.mm | 5 +- .../TrackRecorder/TrackStatistics+Core.h | 1 - .../CoreApi/TrackRecorder/TrackStatistics.h | 3 +- .../CoreApi/TrackRecorder/TrackStatistics.mm | 15 +---- iphone/Maps/Maps.xcodeproj/project.pbxproj | 26 ++++++--- .../ElevationProfileBuilder.swift | 5 +- .../ElevationProfilePresenter.swift | 7 --- .../ElevationProfileViewController.swift | 27 ++------- .../TrackDetailsViewController.swift | 45 --------------- .../TrackStatisticsBuilder.swift | 7 +++ .../TrackStatisticsTableViewCell.swift | 29 ++++++++++ .../TrackStatisticsViewController.swift | 47 ++++++++++++++++ .../TrackStatisticsViewModel.swift | 42 ++++++++++++++ iphone/Maps/UI/PlacePage/PlacePage.storyboard | 56 +++++-------------- .../Maps/UI/PlacePage/PlacePageBuilder.swift | 8 +-- .../Layouts/PlacePageElevationLayout.swift | 33 +++++++---- .../PlacePageManager/MWMPlacePageManager.mm | 6 +- .../MWMPlacePageManagerHelper.mm | 2 +- map/elevation_info.cpp | 17 +++--- map/framework.cpp | 1 + 23 files changed, 221 insertions(+), 173 deletions(-) delete mode 100644 iphone/Maps/UI/PlacePage/Components/TrackDetails/TrackDetailsViewController.swift create mode 100644 iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsBuilder.swift create mode 100644 iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsTableViewCell.swift create mode 100644 iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsViewController.swift create mode 100644 iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsViewModel.swift diff --git a/iphone/CoreApi/CoreApi/Bookmarks/MWMTrack.h b/iphone/CoreApi/CoreApi/Bookmarks/MWMTrack.h index 2ff56af8ed..25c76389d5 100644 --- a/iphone/CoreApi/CoreApi/Bookmarks/MWMTrack.h +++ b/iphone/CoreApi/CoreApi/Bookmarks/MWMTrack.h @@ -4,13 +4,16 @@ NS_ASSUME_NONNULL_BEGIN +@class TrackStatistics; + NS_SWIFT_NAME(Track) @interface MWMTrack : NSObject @property(nonatomic, readonly) MWMTrackID trackId; -@property(nonatomic, readonly) NSString *trackName; +@property(nonatomic, readonly) NSString * trackName; @property(nonatomic, readonly) NSInteger trackLengthMeters; -@property(nonatomic, readonly) UIColor *trackColor; +@property(nonatomic, readonly) UIColor * trackColor; +@property(nonatomic, readonly) TrackStatistics * statistics; @end diff --git a/iphone/CoreApi/CoreApi/Bookmarks/MWMTrack.mm b/iphone/CoreApi/CoreApi/Bookmarks/MWMTrack.mm index 6650dfe606..b0929e9ff8 100644 --- a/iphone/CoreApi/CoreApi/Bookmarks/MWMTrack.mm +++ b/iphone/CoreApi/CoreApi/Bookmarks/MWMTrack.mm @@ -1,4 +1,5 @@ #import "MWMTrack+Core.h" +#import "TrackStatistics+Core.h" @implementation MWMTrack @@ -14,6 +15,7 @@ _trackLengthMeters = track->GetLengthMeters(); auto const color = track->GetColor(0); _trackColor = [UIColor colorWithRed:color.GetRedF() green:color.GetGreenF() blue:color.GetBlueF() alpha:1.f]; + _statistics = [[TrackStatistics alloc] initWithTrackData:track]; } return self; } diff --git a/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.h b/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.h index c016e3a18c..4c2ed9a526 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.h +++ b/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.h @@ -9,6 +9,7 @@ @class PlacePageBookmarkData; @class ElevationProfileData; @class MWMMapNodeAttributes; +@class TrackStatistics; typedef NS_ENUM(NSInteger, PlacePageRoadType) { PlacePageRoadTypeToll, @@ -31,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, readonly, nullable) PlacePageBookmarkData *bookmarkData; @property(nonatomic, readonly) PlacePageRoadType roadType; @property(nonatomic, readonly, nullable) NSString *wikiDescriptionHtml; -@property(nonatomic, readonly, nullable) ElevationProfileData *trackStatisticsData; +@property(nonatomic, readonly, nullable) TrackStatistics *trackStatistics; @property(nonatomic, readonly, nullable) ElevationProfileData *elevationProfileData; @property(nonatomic, readonly, nullable) MWMMapNodeAttributes *mapNodeAttributes; @property(nonatomic, readonly, nullable) NSString *bookingSearchUrl; diff --git a/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.mm b/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.mm index 05e5965906..0ff03b3303 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.mm +++ b/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.mm @@ -6,6 +6,7 @@ #import "PlacePageBookmarkData+Core.h" #import "ElevationProfileData+Core.h" #import "MWMMapNodeAttributes.h" +#import "TrackStatistics+Core.h" #include #include "platform/network_policy.hpp" @@ -66,7 +67,9 @@ static PlacePageRoadType convertRoadType(RoadWarningMarkType roadType) { if (_isTrack) { auto const & bm = GetFramework().GetBookmarkManager(); auto const & trackId = rawData().GetTrackId(); - if (bm.GetTrack(trackId)->HasAltitudes()) { + auto const & track = bm.GetTrack(trackId); + _trackStatistics = [[TrackStatistics alloc] initWithTrackData:track]; + if (track->HasAltitudes()) { auto const & elevationInfo = bm.MakeElevationInfo(trackId); _elevationProfileData = [[ElevationProfileData alloc] initWithElevationInfo:elevationInfo activePoint:bm.GetElevationActivePoint(trackId) diff --git a/iphone/CoreApi/CoreApi/TrackRecorder/TrackStatistics+Core.h b/iphone/CoreApi/CoreApi/TrackRecorder/TrackStatistics+Core.h index efd8732980..2ac0b40a3f 100644 --- a/iphone/CoreApi/CoreApi/TrackRecorder/TrackStatistics+Core.h +++ b/iphone/CoreApi/CoreApi/TrackRecorder/TrackStatistics+Core.h @@ -6,6 +6,5 @@ @interface TrackStatistics (Core) - (instancetype)initWithTrackData:(Track const *)track; -- (instancetype)initWithGpsTrackInfo:(GpsTrackCollection::GpsTrackInfo const &)info; @end diff --git a/iphone/CoreApi/CoreApi/TrackRecorder/TrackStatistics.h b/iphone/CoreApi/CoreApi/TrackRecorder/TrackStatistics.h index 18ad8c5fcf..ce28be08b4 100644 --- a/iphone/CoreApi/CoreApi/TrackRecorder/TrackStatistics.h +++ b/iphone/CoreApi/CoreApi/TrackRecorder/TrackStatistics.h @@ -6,7 +6,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) double length; @property (nonatomic, readonly) double duration; -@property (nonatomic, readonly) double elevationGain; +@property (nonatomic, readonly) double ascend; +@property (nonatomic, readonly) double descend; @end diff --git a/iphone/CoreApi/CoreApi/TrackRecorder/TrackStatistics.mm b/iphone/CoreApi/CoreApi/TrackRecorder/TrackStatistics.mm index 3b04409a29..5c53fa1434 100644 --- a/iphone/CoreApi/CoreApi/TrackRecorder/TrackStatistics.mm +++ b/iphone/CoreApi/CoreApi/TrackRecorder/TrackStatistics.mm @@ -10,18 +10,9 @@ self = [super init]; if (self) { _length = track->GetLengthMeters(); - // TODO: add methods to call - _duration = 0; - _elevationGain = 0; - } - return self; -} - -- (instancetype)initWithGpsTrackInfo:(GpsTrackCollection::GpsTrackInfo const &)trackInfo { - if (self = [super init]) { - _length = trackInfo.length; - _duration = trackInfo.duration; - _elevationGain = trackInfo.elevationGain; + _duration = track->GetDurationInSeconds(); + _ascend = 0; + _descend = 0; } return self; } diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index 4f40291c93..81fe54c26c 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -493,7 +493,10 @@ ED8270F02C2071A3005966DA /* SettingsTableViewDetailedSwitchCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED8270EF2C2071A3005966DA /* SettingsTableViewDetailedSwitchCell.swift */; }; ED9857082C4ED02D00694F6C /* MailComposer.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED9857072C4ED02D00694F6C /* MailComposer.swift */; }; ED9966802B94FBC20083CE55 /* ColorPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED99667D2B94FBC20083CE55 /* ColorPicker.swift */; }; - EDA1EA972CC25A3B00DBDCAA /* TrackDetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA1EA942CC25A0D00DBDCAA /* TrackDetailsViewController.swift */; }; + EDA1EA972CC25A3B00DBDCAA /* TrackStatisticsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA1EA942CC25A0D00DBDCAA /* TrackStatisticsViewController.swift */; }; + EDA1EA9A2CC260B400DBDCAA /* TrackStatisticsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA1EA992CC260B400DBDCAA /* TrackStatisticsViewModel.swift */; }; + EDA1EA9C2CC260C200DBDCAA /* TrackStatisticsBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA1EA9B2CC260C200DBDCAA /* TrackStatisticsBuilder.swift */; }; + EDA1EA9E2CC2CED100DBDCAA /* TrackStatisticsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA1EA9D2CC2CED100DBDCAA /* TrackStatisticsTableViewCell.swift */; }; EDBD68072B625724005DD151 /* LocationServicesDisabledAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = EDBD68062B625724005DD151 /* LocationServicesDisabledAlert.xib */; }; EDBD680B2B62572E005DD151 /* LocationServicesDisabledAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDBD680A2B62572E005DD151 /* LocationServicesDisabledAlert.swift */; }; EDC3573B2B7B5029001AE9CA /* CALayer+SetCorner.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC3573A2B7B5029001AE9CA /* CALayer+SetCorner.swift */; }; @@ -1423,7 +1426,10 @@ ED8270EF2C2071A3005966DA /* SettingsTableViewDetailedSwitchCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsTableViewDetailedSwitchCell.swift; sourceTree = ""; }; ED9857072C4ED02D00694F6C /* MailComposer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MailComposer.swift; sourceTree = ""; }; ED99667D2B94FBC20083CE55 /* ColorPicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorPicker.swift; sourceTree = ""; }; - EDA1EA942CC25A0D00DBDCAA /* TrackDetailsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrackDetailsViewController.swift; sourceTree = ""; }; + EDA1EA942CC25A0D00DBDCAA /* TrackStatisticsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrackStatisticsViewController.swift; sourceTree = ""; }; + EDA1EA992CC260B400DBDCAA /* TrackStatisticsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrackStatisticsViewModel.swift; sourceTree = ""; }; + EDA1EA9B2CC260C200DBDCAA /* TrackStatisticsBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrackStatisticsBuilder.swift; sourceTree = ""; }; + EDA1EA9D2CC2CED100DBDCAA /* TrackStatisticsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrackStatisticsTableViewCell.swift; sourceTree = ""; }; EDBD68062B625724005DD151 /* LocationServicesDisabledAlert.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LocationServicesDisabledAlert.xib; sourceTree = ""; }; EDBD680A2B62572E005DD151 /* LocationServicesDisabledAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationServicesDisabledAlert.swift; sourceTree = ""; }; EDC3573A2B7B5029001AE9CA /* CALayer+SetCorner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CALayer+SetCorner.swift"; sourceTree = ""; }; @@ -2936,7 +2942,6 @@ 99C6531F23F2F178004322F3 /* Components */ = { isa = PBXGroup; children = ( - EDA1EA982CC25A4200DBDCAA /* TrackDetails */, 99A906D423F6F7020005872B /* ActionBarViewController.swift */, 99A906D523F6F7020005872B /* OpeningHoursViewController.swift */, 99A906CD23F6F7010005872B /* PlacePageBookmarkViewController.swift */, @@ -2946,6 +2951,7 @@ 99A906D823F6F7030005872B /* WikiDescriptionViewController.swift */, 4726254821C27D4B00C7BAAD /* PlacePageDescriptionViewController.swift */, 99C964222428C0D500E41723 /* PlacePageHeader */, + EDA1EA982CC25A4200DBDCAA /* TrackStatistics */, 993DF0C223F6BD0600AC231A /* ElevationDetails */, 99DEF9D523E420D2006BFD21 /* ElevationProfile */, EDE8EAE32C2DB74A002777F5 /* OpenInAppActionSheet */, @@ -3158,12 +3164,15 @@ path = ColorPicker; sourceTree = ""; }; - EDA1EA982CC25A4200DBDCAA /* TrackDetails */ = { + EDA1EA982CC25A4200DBDCAA /* TrackStatistics */ = { isa = PBXGroup; children = ( - EDA1EA942CC25A0D00DBDCAA /* TrackDetailsViewController.swift */, + EDA1EA9B2CC260C200DBDCAA /* TrackStatisticsBuilder.swift */, + EDA1EA942CC25A0D00DBDCAA /* TrackStatisticsViewController.swift */, + EDA1EA992CC260B400DBDCAA /* TrackStatisticsViewModel.swift */, + EDA1EA9D2CC2CED100DBDCAA /* TrackStatisticsTableViewCell.swift */, ); - path = TrackDetails; + path = TrackStatistics; sourceTree = ""; }; EDC4E3422C5D1BD3009286A2 /* RecentlyDeletedTests */ = { @@ -4369,8 +4378,10 @@ 6741A9C01BF340DE002C974C /* MWMTextView.m in Sources */, F6E2FDB61E097BA00083EBEC /* MWMEditorAdditionalNamesHeader.m in Sources */, F6E2FDC81E097BA00083EBEC /* MWMEditorNotesFooter.m in Sources */, + EDA1EA9A2CC260B400DBDCAA /* TrackStatisticsViewModel.swift in Sources */, F6E2FD651E097BA00083EBEC /* MWMMapDownloaderPlaceTableViewCell.m in Sources */, F6E2FF2D1E097BA00083EBEC /* MWMSearchCell.mm in Sources */, + EDA1EA9E2CC2CED100DBDCAA /* TrackStatisticsTableViewCell.swift in Sources */, 3454D7C51E07F045004AF2AD /* UIButton+Orientation.m in Sources */, 34AB66831FC5AA330078E451 /* NavigationAddPointToastView.swift in Sources */, F6E2FE4C1E097BA00083EBEC /* MWMPlacePageManager.mm in Sources */, @@ -4562,6 +4573,7 @@ CDB4D4E4222E8FF600104869 /* CarPlayService.swift in Sources */, F6E2FF3C1E097BA00083EBEC /* MWMSearchTableView.m in Sources */, F6E2FF661E097BA00083EBEC /* MWMTTSSettingsViewController.mm in Sources */, + EDA1EA9C2CC260C200DBDCAA /* TrackStatisticsBuilder.swift in Sources */, 3454D7C21E07F045004AF2AD /* NSString+Categories.m in Sources */, 34E7761F1F14DB48003040B3 /* PlacePageArea.swift in Sources */, ED79A5D82BDF8D6100952D1F /* DefaultLocalDirectoryMonitor.swift in Sources */, @@ -4692,7 +4704,7 @@ 993DF0C923F6BD0600AC231A /* ElevationDetailsBuilder.swift in Sources */, 674A7E301C0DB10B003D48E1 /* MWMMapWidgets.mm in Sources */, 34AB66291FC5AA330078E451 /* RouteManagerViewController.swift in Sources */, - EDA1EA972CC25A3B00DBDCAA /* TrackDetailsViewController.swift in Sources */, + EDA1EA972CC25A3B00DBDCAA /* TrackStatisticsViewController.swift in Sources */, 3404754D1E081A4600C92850 /* MWMKeyboard.m in Sources */, EDE243E52B6D3F400057369B /* OSMView.swift in Sources */, 993DF10C23F6BDB100AC231A /* MWMTableViewCellRenderer.swift in Sources */, diff --git a/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfileBuilder.swift b/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfileBuilder.swift index aba969e77b..2d523dca89 100644 --- a/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfileBuilder.swift +++ b/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfileBuilder.swift @@ -1,8 +1,5 @@ class ElevationProfileBuilder { - static func build(data: PlacePageData, delegate: ElevationProfileViewControllerDelegate?) -> ElevationProfileViewController { - guard let elevationProfileData = data.elevationProfileData else { - fatalError() - } + static func build(elevationProfileData: ElevationProfileData, delegate: ElevationProfileViewControllerDelegate?) -> ElevationProfileViewController { let storyboard = UIStoryboard.instance(.placePage) let viewController = storyboard.instantiateViewController(ofType: ElevationProfileViewController.self); let presenter = ElevationProfilePresenter(view: viewController, diff --git a/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfilePresenter.swift b/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfilePresenter.swift index 682cdc1042..33f0d13b6f 100644 --- a/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfilePresenter.swift +++ b/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfilePresenter.swift @@ -61,13 +61,6 @@ extension ElevationProfilePresenter: ElevationProfilePresenterProtocol { view?.isDifficultyHidden = true } - if data.trackTime != 0, let eta = DateComponentsFormatter.etaString(from: TimeInterval(data.trackTime)) { - view?.isTimeHidden = false - view?.setTrackTime("\(eta)") - } else { - view?.isTimeHidden = true - } - view?.isBottomPanelHidden = data.trackTime == 0 && data.difficulty == .disabled view?.isExtendedDifficultyLabelHidden = true diff --git a/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfileViewController.swift b/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfileViewController.swift index 45e1496aef..824413d8b5 100644 --- a/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfileViewController.swift +++ b/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfileViewController.swift @@ -5,10 +5,8 @@ protocol ElevationProfileViewProtocol: AnyObject { var isExtendedDifficultyLabelHidden: Bool { get set } var isDifficultyHidden: Bool { get set } - var isTimeHidden: Bool { get set } var isBottomPanelHidden: Bool { get set } func setExtendedDifficultyGrade(_ value: String) - func setTrackTime(_ value: String?) func setDifficulty(_ value: ElevationDifficulty) func setChartData(_ data: ChartPresentationData) func setActivePoint(_ distance: Double) @@ -24,15 +22,12 @@ class ElevationProfileViewController: UIViewController { @IBOutlet private var difficultyView: DifficultyView! @IBOutlet private var difficultyTitle: UILabel! @IBOutlet private var extendedDifficultyGradeLabel: UILabel! - @IBOutlet private var trackTimeLabel: UILabel! - @IBOutlet private var trackTimeTitle: UILabel! @IBOutlet private var extendedGradeButton: UIButton! - @IBOutlet private var diffucultyConstraint: NSLayoutConstraint! + @IBOutlet private var difficultyConstraint: NSLayoutConstraint! - private let diffucultiVisibleConstraint: CGFloat = 60 - private let diffucultyHiddenConstraint: CGFloat = 10 + private let difficultyVisibleConstraint: CGFloat = 60 + private let difficultyHiddenConstraint: CGFloat = 10 private var difficultyHidden: Bool = false - private var timeHidden: Bool = false private var bottomPanelHidden: Bool = false override func viewDidLoad() { @@ -77,25 +72,15 @@ extension ElevationProfileViewController: ElevationProfileViewProtocol { } } - var isTimeHidden: Bool { - get { timeHidden } - set { - timeHidden = newValue - trackTimeLabel.isHidden = newValue - trackTimeTitle.isHidden = newValue - } - } - var isBottomPanelHidden: Bool { get { bottomPanelHidden } set { bottomPanelHidden = newValue if newValue == true { - isTimeHidden = true isExtendedDifficultyLabelHidden = true isDifficultyHidden = true } - diffucultyConstraint.constant = newValue ? diffucultyHiddenConstraint : diffucultiVisibleConstraint + difficultyConstraint.constant = newValue ? difficultyHiddenConstraint : difficultyVisibleConstraint } } @@ -103,10 +88,6 @@ extension ElevationProfileViewController: ElevationProfileViewProtocol { extendedDifficultyGradeLabel.text = value } - func setTrackTime(_ value: String?) { - trackTimeLabel.text = value - } - func setDifficulty(_ value: ElevationDifficulty) { difficultyView.difficulty = value } diff --git a/iphone/Maps/UI/PlacePage/Components/TrackDetails/TrackDetailsViewController.swift b/iphone/Maps/UI/PlacePage/Components/TrackDetails/TrackDetailsViewController.swift deleted file mode 100644 index 590912ab58..0000000000 --- a/iphone/Maps/UI/PlacePage/Components/TrackDetails/TrackDetailsViewController.swift +++ /dev/null @@ -1,45 +0,0 @@ - -class TrackDetailsBuilder { - static func build(data: PlacePageData) -> TrackDetailsViewController { - let viewModel = TrackDetailsViewModel(data: data) - let viewController = TrackDetailsViewController(viewModel: viewModel) - return viewController - - } -} - - -struct TrackDetailsViewModel { - let distance: String - let duration: String - - init(data: PlacePageData) { - let track = BookmarksManager.shared().track(withId: data.previewData.) - distance = data. - duration = data. - } -} - -class TrackDetailsViewController: MWMTableViewController { - - var viewModel: TrackDetailsViewModel - - init(viewModel: TrackDetailsViewModel) { - self.viewModel = viewModel - super.init() - } - - @available(*, unavailable) - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override func viewDidLoad() { - super.viewDidLoad() - setupView() - } - - private func setupView() { - tableView.register(cell: UITableViewCell.self) - } -} diff --git a/iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsBuilder.swift b/iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsBuilder.swift new file mode 100644 index 0000000000..7b0be80e39 --- /dev/null +++ b/iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsBuilder.swift @@ -0,0 +1,7 @@ +final class TrackStatisticsBuilder { + static func build(statistics: TrackStatistics) -> TrackStatisticsViewController { + let viewModel = TrackStatisticsViewModel(statistics: statistics) + let viewController = TrackStatisticsViewController(viewModel: viewModel) + return viewController + } +} diff --git a/iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsTableViewCell.swift b/iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsTableViewCell.swift new file mode 100644 index 0000000000..7368ee3650 --- /dev/null +++ b/iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsTableViewCell.swift @@ -0,0 +1,29 @@ +final class TrackStatisticsTableViewCell: UITableViewCell { + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: .value1, reuseIdentifier: reuseIdentifier) + } + + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func configure(text: String, detailText: String) { + let detailTextFont: UIFont = .bold16() + let detailTextColor: UIColor = .black + if #available(iOS 14.0, *) { + var configuration = UIListContentConfiguration.valueCell() + configuration.text = text + configuration.secondaryText = detailText + configuration.secondaryTextProperties.font = detailTextFont + configuration.secondaryTextProperties.color = detailTextColor + contentConfiguration = configuration + } else { + textLabel?.text = text + detailTextLabel?.text = detailText + detailTextLabel?.font = detailTextFont + detailTextLabel?.textColor = detailTextColor + } + } +} diff --git a/iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsViewController.swift b/iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsViewController.swift new file mode 100644 index 0000000000..103871dfa7 --- /dev/null +++ b/iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsViewController.swift @@ -0,0 +1,47 @@ +class TrackStatisticsViewController: MWMTableViewController { + + private var viewModel: TrackStatisticsViewModel + private var viewHeightConstraint: NSLayoutConstraint? + + init(viewModel: TrackStatisticsViewModel) { + self.viewModel = viewModel + super.init(nibName: nil, bundle: nil) + } + + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func viewDidLoad() { + super.viewDidLoad() + setupView() + } + + override func viewWillLayoutSubviews() { + super.viewWillLayoutSubviews() + viewHeightConstraint?.constant = tableView.contentSize.height + } + + private func setupView() { + viewHeightConstraint = view.heightAnchor.constraint(equalToConstant: .zero) + viewHeightConstraint?.isActive = true + tableView.register(cell: TrackStatisticsTableViewCell.self) + tableView.allowsSelection = false + } + + override func numberOfSections(in tableView: UITableView) -> Int { + viewModel.data.count + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + viewModel.data[section].cells.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(cell: TrackStatisticsTableViewCell.self, indexPath: indexPath) + let cellData = viewModel.data[indexPath.section].cells[indexPath.row] + cell.configure(text: cellData.text, detailText: cellData.detailText) + return cell + } +} diff --git a/iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsViewModel.swift b/iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsViewModel.swift new file mode 100644 index 0000000000..9fb70d6494 --- /dev/null +++ b/iphone/Maps/UI/PlacePage/Components/TrackStatistics/TrackStatisticsViewModel.swift @@ -0,0 +1,42 @@ +struct TrackStatisticsViewModel { + private var statistics: TrackStatistics + + enum Section: Int, CaseIterable { + case statistics + } + + struct SectionModel { + var cells: [CellModel] + } + + struct CellModel { + var text: String + var detailText: String + } + + private static let distanceFormatter: MKDistanceFormatter = { + let formatter = MKDistanceFormatter() + formatter.units = Settings.measurementUnits() == .imperial ? .imperial : .metric + formatter.unitStyle = .abbreviated + return formatter + }() + + private(set) var data: [SectionModel] = [] + + init(statistics: TrackStatistics) { + self.statistics = statistics + self.data = Self.buildData(from: statistics) + } + + private static func buildData(from statistics: TrackStatistics) -> [SectionModel] { + let length = distanceFormatter.string(fromDistance: statistics.length) + let duration = DateComponentsFormatter.etaString(from: statistics.duration) + var rows: [CellModel] = [] + rows.append(CellModel(text: L("length"), detailText: length)) + if let duration = duration { + // TODO: Localize string + rows.append(CellModel(text: L("duration"), detailText: duration)) + } + return [SectionModel(cells: rows)] + } +} diff --git a/iphone/Maps/UI/PlacePage/PlacePage.storyboard b/iphone/Maps/UI/PlacePage/PlacePage.storyboard index 10eae05f46..c87d49f867 100644 --- a/iphone/Maps/UI/PlacePage/PlacePage.storyboard +++ b/iphone/Maps/UI/PlacePage/PlacePage.storyboard @@ -1,9 +1,9 @@ - + - + @@ -636,7 +636,7 @@ diff --git a/iphone/Maps/UI/PlacePage/PlacePageBuilder.swift b/iphone/Maps/UI/PlacePage/PlacePageBuilder.swift index 337f7d4163..77c1cd60ef 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageBuilder.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageBuilder.swift @@ -9,8 +9,8 @@ let interactor = PlacePageInteractor(viewController: viewController, data: data, mapViewController: MapViewController.shared()!) - let layout:IPlacePageLayout - if data.elevationProfileData != nil { + let layout: IPlacePageLayout + if data.isTrack { layout = PlacePageElevationLayout(interactor: interactor, storyboard: storyboard, data: data) } else { layout = PlacePageCommonLayout(interactor: interactor, storyboard: storyboard, data: data) @@ -30,8 +30,8 @@ let interactor = PlacePageInteractor(viewController: viewController, data: data, mapViewController: MapViewController.shared()!) - let layout:IPlacePageLayout - if data.elevationProfileData != nil { + let layout: IPlacePageLayout + if data.isTrack { layout = PlacePageElevationLayout(interactor: interactor, storyboard: viewController.storyboard!, data: data) } else { layout = PlacePageCommonLayout(interactor: interactor, storyboard: viewController.storyboard!, data: data) diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageElevationLayout.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageElevationLayout.swift index 259f8970dc..b3b339a5ee 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageElevationLayout.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageElevationLayout.swift @@ -29,15 +29,16 @@ class PlacePageElevationLayout: IPlacePageLayout { return vc } () - lazy var infoViewController: PlacePageInfoViewController = { - let vc = storyboard.instantiateViewController(ofType: PlacePageInfoViewController.self) - vc.placePageInfoData = placePageData.infoData - vc.delegate = interactor + func trackStatisticsViewController(statistics: TrackStatistics) -> TrackStatisticsViewController { + let vc = TrackStatisticsBuilder.build(statistics: statistics) return vc - } () + } - lazy var elevationMapViewController: ElevationProfileViewController = { - return ElevationProfileBuilder.build(data: placePageData, delegate: interactor) + lazy var elevationMapViewController: ElevationProfileViewController? = { + guard let elevationProfileData = placePageData.elevationProfileData else { + return nil + } + return ElevationProfileBuilder.build(elevationProfileData: elevationProfileData, delegate: interactor) } () init(interactor: PlacePageInteractor, storyboard: UIStoryboard, data: PlacePageData) { @@ -55,11 +56,15 @@ class PlacePageElevationLayout: IPlacePageLayout { bookmarkViewController.view.isHidden = false } - if placePageData.infoData != nil { - viewControllers.append(infoViewController) + guard let trackStatistics = placePageData.trackStatistics else { + let message = "Track statistics should not be nil" + LOG(.critical, message) + fatalError(message) + } + viewControllers.append(trackStatisticsViewController(statistics: trackStatistics)) + if let elevationMapViewController { + viewControllers.append(elevationMapViewController) } - - viewControllers.append(elevationMapViewController) return viewControllers } @@ -67,8 +72,12 @@ class PlacePageElevationLayout: IPlacePageLayout { func calculateSteps(inScrollView scrollView: UIScrollView, compact: Bool) -> [PlacePageState] { var steps: [PlacePageState] = [] let scrollHeight = scrollView.height - let previewHeight = elevationMapViewController.getPreviewHeight() steps.append(.closed(-scrollHeight)) + guard let elevationMapViewController else { + steps.append(.full(0)) + return steps + } + let previewHeight = elevationMapViewController.getPreviewHeight() guard let previewView = elevationMapViewController.view else { return steps } diff --git a/iphone/Maps/UI/PlacePage/PlacePageManager/MWMPlacePageManager.mm b/iphone/Maps/UI/PlacePage/PlacePageManager/MWMPlacePageManager.mm index bde9befc2b..0dd5442dbb 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageManager/MWMPlacePageManager.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageManager/MWMPlacePageManager.mm @@ -205,9 +205,9 @@ using namespace storage; } - (void)editTrack:(PlacePageData *)data { - EditTrackViewController * editTrackController = [[EditTrackViewController alloc] init]; - [editBookmarkController configureWithPlacePageData:data]; - [[MapViewController sharedController].navigationController pushViewController:editBookmarkController animated:YES]; +// EditTrackViewController * editTrackController = [[EditTrackViewController alloc] init]; +// [editBookmarkController configureWithPlacePageData:data]; +// [[MapViewController sharedController].navigationController pushViewController:editBookmarkController animated:YES]; } - (void)showPlaceDescription:(NSString *)htmlString diff --git a/iphone/Maps/UI/PlacePage/PlacePageManager/MWMPlacePageManagerHelper.mm b/iphone/Maps/UI/PlacePage/PlacePageManager/MWMPlacePageManagerHelper.mm index 15826dfdfa..c9538d4164 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageManager/MWMPlacePageManagerHelper.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageManager/MWMPlacePageManagerHelper.mm @@ -157,7 +157,7 @@ } + (void)editTrack:(PlacePageData *)data { - [[MWMMapViewControlsManager manager].placePageManager editTrack:data]; +// [[MWMMapViewControlsManager manager].placePageManager editTrack:data]; } + (void)searchBookingHotels:(PlacePageData *)data { diff --git a/map/elevation_info.cpp b/map/elevation_info.cpp index 89e64fee9e..879c3453cf 100644 --- a/map/elevation_info.cpp +++ b/map/elevation_info.cpp @@ -44,26 +44,27 @@ ElevationInfo::ElevationInfo(Track const & track) auto const & baseAltitude = points[0].GetAltitude(); m_points.emplace_back(0, baseAltitude); + m_minAltitude = baseAltitude; + m_maxAltitude = baseAltitude; double distance = 0.0; - for (size_t i = 1; i < points.size(); ++i) { distance += mercator::DistanceOnEarth(points[i - 1].GetPoint(), points[i].GetPoint()); m_points.emplace_back(distance, points[i].GetAltitude()); - auto const & pt1 = points[i - 1].GetPoint(); - auto const & pt2 = points[i].GetPoint(); - auto const deltaAltitude = points[i].GetAltitude() - points[i - 1].GetAltitude(); + auto const & previousPointAltitude = points[i - 1].GetAltitude(); + auto const & currentPointAltitude = points[i].GetAltitude(); + auto const deltaAltitude = currentPointAltitude - previousPointAltitude; if (deltaAltitude > 0) m_ascent += deltaAltitude; else m_descent -= deltaAltitude; - if (m_minAltitude == geometry::kInvalidAltitude || points[i].GetAltitude() < m_minAltitude) - m_minAltitude = points[i].GetAltitude(); - if (m_maxAltitude == geometry::kInvalidAltitude || points[i].GetAltitude() > m_maxAltitude) - m_maxAltitude = points[i].GetAltitude(); + if (currentPointAltitude < m_minAltitude) + m_minAltitude = currentPointAltitude; + if (currentPointAltitude > m_maxAltitude) + m_maxAltitude = currentPointAltitude; } auto const & timestamps = trackData.m_geometry.m_timestamps[0]; diff --git a/map/framework.cpp b/map/framework.cpp index d05eae4e60..0473339acb 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -621,6 +621,7 @@ void Framework::FillUserMarkInfo(UserMark const * mark, place_page::Info & outIn void Framework::FillBookmarkInfo(Bookmark const & bmk, place_page::Info & info) const { + info.SetBookmarkData(bmk.GetData()); info.SetBookmarkCategoryName(GetBookmarkManager().GetCategoryName(bmk.GetGroupId())); info.SetBookmarkId(bmk.GetId()); info.SetBookmarkCategoryId(bmk.GetGroupId());