From 88244ee326746469fa12f3301aff2f1466fc61ac Mon Sep 17 00:00:00 2001 From: VladiMihaylenko Date: Wed, 8 Jun 2016 19:16:41 +0300 Subject: [PATCH] [ios] Get online pricing. --- iphone/Maps/Classes/MWMBasePlacePageView.mm | 24 ++++++++++++++++- iphone/Maps/Classes/MWMPlacePageEntity.h | 2 ++ iphone/Maps/Classes/MWMPlacePageEntity.mm | 29 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/iphone/Maps/Classes/MWMBasePlacePageView.mm b/iphone/Maps/Classes/MWMBasePlacePageView.mm index 8dbddcb18b..f6d5db0297 100644 --- a/iphone/Maps/Classes/MWMBasePlacePageView.mm +++ b/iphone/Maps/Classes/MWMBasePlacePageView.mm @@ -229,7 +229,29 @@ using namespace storage; BOOL const isMyPosition = entity.isMyPosition; self.addressLabel.text = entity.address; - self.bookingPriceLabel.text = entity.bookingPrice; + + if (!entity.bookingOnlinePrice.length) + { + self.bookingPriceLabel.text = entity.bookingPrice; + [entity onlinePricingWithCompletionBlock:^ + { + self.bookingPriceLabel.text = entity.bookingOnlinePrice; + [self setNeedsLayout]; + [UIView animateWithDuration:kDefaultAnimationDuration animations:^ + { + [self layoutIfNeeded]; + }]; + } + failure:^ + { + //TODO(Vlad): Process error. + }]; + } + else + { + self.bookingPriceLabel.text = entity.bookingOnlinePrice; + } + self.bookingRatingLabel.text = entity.bookingRating; self.bookingView.hidden = !entity.bookingPrice.length && !entity.bookingRating.length; BOOL const isHeadingAvaible = [CLLocationManager headingAvailable]; diff --git a/iphone/Maps/Classes/MWMPlacePageEntity.h b/iphone/Maps/Classes/MWMPlacePageEntity.h index c97d79ad9a..d0729e6ab8 100644 --- a/iphone/Maps/Classes/MWMPlacePageEntity.h +++ b/iphone/Maps/Classes/MWMPlacePageEntity.h @@ -51,6 +51,7 @@ using MWMPlacePageCellTypeValueMap = map; @property (copy, nonatomic) NSString * bookmarkColor; @property (copy, nonatomic) NSString * bookingRating; @property (copy, nonatomic) NSString * bookingPrice; +@property (copy, nonatomic) NSString * bookingOnlinePrice; @property (nonatomic) BookmarkAndCategory bac; @property (weak, nonatomic) MWMPlacePageViewManager * manager; @@ -68,6 +69,7 @@ using MWMPlacePageCellTypeValueMap = map; - (instancetype)initWithInfo:(place_page::Info const &)info; - (void)synchronize; +- (void)onlinePricingWithCompletionBlock:(TMWMVoidBlock)completion failure:(TMWMVoidBlock)failure; - (void)toggleCoordinateSystem; diff --git a/iphone/Maps/Classes/MWMPlacePageEntity.mm b/iphone/Maps/Classes/MWMPlacePageEntity.mm index 5f5603fd0d..872e82489c 100644 --- a/iphone/Maps/Classes/MWMPlacePageEntity.mm +++ b/iphone/Maps/Classes/MWMPlacePageEntity.mm @@ -10,6 +10,7 @@ #include "platform/measurement_utils.hpp" #include "platform/mwm_version.hpp" +#include "platform/platform.hpp" using feature::Metadata; @@ -121,6 +122,34 @@ void initFieldsMap() } } +- (void)onlinePricingWithCompletionBlock:(TMWMVoidBlock)completion failure:(TMWMVoidBlock)failure +{ + if (Platform::ConnectionStatus() == Platform::EConnectionType::CONNECTION_NONE || !self.isBooking) + { + failure(); + return; + } + + NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; + [formatter setNumberStyle:NSNumberFormatterCurrencyStyle]; + [formatter setLocale:[NSLocale currentLocale]]; + string const currency = formatter.currencyCode.UTF8String; + GetFramework().GetBookingApi().GetMinPrice(m_info.GetMetadata().Get(Metadata::FMD_SPONSORED_ID), + currency, + [self, completion, failure, currency, formatter](string const & minPrice, string const & priceCurrency) + { + if (currency != priceCurrency) + { + failure(); + return; + } + NSNumberFormatter * f = [[NSNumberFormatter alloc] init]; + f.numberStyle = NSNumberFormatterDecimalStyle; + self.bookingOnlinePrice = [formatter stringFromNumber:[f numberFromString:@(minPrice.c_str())]]; + completion(); + }); +} + - (void)configureBookmark { auto const bac = m_info.GetBookmarkAndCategory();