From d3c01802323daf8843f594beb7e35999cd298eee Mon Sep 17 00:00:00 2001 From: Aleksey Belousov Date: Tue, 7 Apr 2020 18:06:34 +0300 Subject: [PATCH] [iOS] add altitude and speed to my location PP --- .../Common/PlacePagePreviewData.h | 1 + .../Common/PlacePagePreviewData.mm | 1 + .../Maps/Core/Location/MWMLocationHelpers.h | 32 ------------ .../PlacePagePreviewViewController.swift | 35 +++++++++---- iphone/Maps/UI/PlacePage/PlacePage.storyboard | 7 ++- .../Layouts/PlacePageCommonLayout.swift | 51 +++++++++++++++---- 6 files changed, 72 insertions(+), 55 deletions(-) diff --git a/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.h b/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.h index 7127fdaaff..687f3aa6d9 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.h +++ b/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.h @@ -36,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, readonly) float rawRating; @property(nonatomic, readonly) PlacePageDataSchedule schedule; @property(nonatomic, readonly) PlacePageDataHotelType hotelType; +@property(nonatomic, readonly) BOOL isMyPosition; @property(nonatomic, readonly) BOOL hasBanner; @property(nonatomic, readonly) BOOL isPopular; @property(nonatomic, readonly) BOOL isBookingPlace; diff --git a/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.mm b/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.mm index d46104c924..e46f487a8c 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.mm +++ b/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.mm @@ -79,6 +79,7 @@ static PlacePageDataHotelType convertHotelType(std::optional 0; _isBookingPlace = rawData.GetSponsoredType() == place_page::SponsoredType::Booking; _schedule = convertOpeningHours(rawData.GetOpeningHours()); diff --git a/iphone/Maps/Core/Location/MWMLocationHelpers.h b/iphone/Maps/Core/Location/MWMLocationHelpers.h index fd0979b5ca..d7cd8a2caf 100644 --- a/iphone/Maps/Core/Location/MWMLocationHelpers.h +++ b/iphone/Maps/Core/Location/MWMLocationHelpers.h @@ -10,27 +10,6 @@ namespace location_helpers { -static inline NSString * formattedSpeedAndAltitude(CLLocation * location) -{ - if (!location) - return nil; - NSMutableString * result = [@"" mutableCopy]; - if (location.altitude) - [result appendString:[NSString stringWithFormat:@"%@ %@", @"\xE2\x96\xB2", @(measurement_utils::FormatAltitude(location.altitude).c_str())]]; - - // Speed is actual only for just received location - if (location.speed > 0. && location.timestamp.timeIntervalSinceNow >= -2.0) - { - if (result.length) - [result appendString:@" "]; - - [result appendString:[NSString stringWithFormat:@"%@%@", - [MWMLocationManager speedSymbolFor:location.speed], - @(measurement_utils::FormatSpeedWithDeviceUnits(location.speed).c_str())]]; - } - return result; -} - static inline NSString * formattedDistance(double const & meters) { if (meters < 0.) return nil; @@ -64,17 +43,6 @@ static inline BOOL isMyPositionPendingOrNoPosition() mode == location::EMyPositionMode::NotFollowNoPosition; } -static inline double headingToNorthRad(CLHeading * heading) -{ - double north = -1.0; - if (heading) - { - north = (heading.trueHeading < 0) ? heading.magneticHeading : heading.trueHeading; - north = base::DegToRad(north); - } - return north; -} - static inline ms::LatLon ToLatLon(m2::PointD const & p) { return mercator::ToLatLon(p); } static inline m2::PointD ToMercator(CLLocationCoordinate2D const & l) diff --git a/iphone/Maps/UI/PlacePage/Components/PlacePagePreviewViewController.swift b/iphone/Maps/UI/PlacePage/Components/PlacePagePreviewViewController.swift index e25d2315cc..6c7a647186 100644 --- a/iphone/Maps/UI/PlacePage/Components/PlacePagePreviewViewController.swift +++ b/iphone/Maps/UI/PlacePage/Components/PlacePagePreviewViewController.swift @@ -46,25 +46,33 @@ class PlacePagePreviewViewController: UIViewController { weak var delegate: PlacePagePreviewViewControllerDelegate? private var distance: String? = nil + private var speedAndAltitude: String? = nil private var heading: CGFloat? = nil override func viewDidLoad() { super.viewDidLoad() - let subtitleString = NSMutableAttributedString() - if placePagePreviewData.isPopular { - subtitleString.append(NSAttributedString(string: L("popular_place"), - attributes: [.foregroundColor : UIColor.linkBlue(), - .font : UIFont.regular14()])) - } + if placePagePreviewData.isMyPosition { + if let speedAndAltitude = speedAndAltitude { + subtitleLabel.text = speedAndAltitude + } + } else { + let subtitleString = NSMutableAttributedString() + if placePagePreviewData.isPopular { + subtitleString.append(NSAttributedString(string: L("popular_place"), + attributes: [.foregroundColor : UIColor.linkBlue(), + .font : UIFont.regular14()])) + } - if let subtitle = placePagePreviewData.subtitle ?? placePagePreviewData.coordinates { - subtitleString.append(NSAttributedString(string: placePagePreviewData.isPopular ? " • " + subtitle : subtitle, - attributes: [.foregroundColor : UIColor.blackSecondaryText(), - .font : UIFont.regular14()])) + if let subtitle = placePagePreviewData.subtitle ?? placePagePreviewData.coordinates { + subtitleString.append(NSAttributedString(string: placePagePreviewData.isPopular ? " • " + subtitle : subtitle, + attributes: [.foregroundColor : UIColor.blackSecondaryText(), + .font : UIFont.regular14()])) + } + + subtitleLabel.attributedText = subtitleString } directionView = subtitleDirectionView - subtitleLabel.attributedText = subtitleString if let address = placePagePreviewData.address { addressLabel.text = address @@ -173,6 +181,11 @@ class PlacePagePreviewViewController: UIViewController { }) } + func updateSpeedAndAltitude(_ speedAndAltitude: String) { + self.speedAndAltitude = speedAndAltitude + subtitleLabel?.text = speedAndAltitude + } + @IBAction func onAddReview(_ sender: UIButton) { delegate?.previewDidPressAddReview() } diff --git a/iphone/Maps/UI/PlacePage/PlacePage.storyboard b/iphone/Maps/UI/PlacePage/PlacePage.storyboard index 5ef9fbe145..9e05f31795 100644 --- a/iphone/Maps/UI/PlacePage/PlacePage.storyboard +++ b/iphone/Maps/UI/PlacePage/PlacePage.storyboard @@ -1,9 +1,9 @@ - + - + @@ -146,6 +146,9 @@ + + +