diff --git a/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.h b/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.h index 1510deea3c..7dc713b887 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.h +++ b/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.h @@ -83,6 +83,7 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, readonly, nullable) NSString *sponsoredDeeplink; @property(nonatomic, copy, nullable) MWMVoidBlock onBookmarkStatusUpdate; @property(nonatomic, copy, nullable) MWMVoidBlock onMapNodeStatusUpdate; +@property(nonatomic, copy, nullable) MWMVoidBlock onUgcStatusUpdate; @property(nonatomic, copy, nullable) void (^onMapNodeProgressUpdate)(uint64_t downloadedBytes, uint64_t totalBytes); - (instancetype)initWithLocalizationProvider:(id)localization; @@ -92,6 +93,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)loadUgcWithCompletion:(MWMVoidBlock)completion; - (void)loadCatalogPromoWithCompletion:(MWMVoidBlock)completion; - (void)updateBookmarkStatus; +- (void)updateUgcStatus; @end diff --git a/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.mm b/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.mm index ac293fe413..fe6ff7b504 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.mm +++ b/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.mm @@ -298,6 +298,20 @@ static PlacePageRoadType convertRoadType(RoadWarningMarkType roadType) { } } +- (void)updateUgcStatus { + if (!GetFramework().HasPlacePageInfo()) { + return; + } + + __weak __typeof(self) wSelf = self; + [self loadUgcWithCompletion:^{ + __strong __typeof(wSelf) self = wSelf; + if (self.onUgcStatusUpdate != nil) { + self.onUgcStatusUpdate(); + } + }]; +} + #pragma mark - MWMStorageObserver - (void)processCountryEvent:(NSString *)countryId { diff --git a/iphone/Maps/UI/PlacePage/Components/PlacePageReviewsViewController.swift b/iphone/Maps/UI/PlacePage/Components/PlacePageReviewsViewController.swift index c9f3f1ea06..547098f4e9 100644 --- a/iphone/Maps/UI/PlacePage/Components/PlacePageReviewsViewController.swift +++ b/iphone/Maps/UI/PlacePage/Components/PlacePageReviewsViewController.swift @@ -25,6 +25,11 @@ final class PlacePageReviewsViewController: UIViewController { private func updateReviews() { guard let ugcData = ugcData else { return } + stackView.arrangedSubviews.forEach { + stackView.removeArrangedSubview($0) + $0.removeFromSuperview() + } + if let myReview = ugcData.myReview { let myReviewView = MyReviewView() myReviewView.defaultConfig() diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift index b4a55d34a7..bf8d6967e6 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift @@ -1,43 +1,45 @@ @objc(MWMGCReviewSaver) protocol UGCReviewSaver { typealias onSaveHandler = (Bool) -> Void - func saveUgc(model: UGCAddReviewController.Model, language: String, resultHandler: @escaping onSaveHandler) + func saveUgc(placePageData: PlacePageData, model: UGCReviewModel, language: String, resultHandler: @escaping onSaveHandler) } @objc(MWMUGCAddReviewController) final class UGCAddReviewController: MWMTableViewController { - typealias Model = UGCReviewModel + private weak var textCell: UGCAddReviewTextCell? + private var reviewPosted = false - weak var textCell: UGCAddReviewTextCell? - var reviewPosted = false - - enum Sections { + private enum Sections { case ratings case text } - @objc static func instance(model: Model, saver: UGCReviewSaver) -> UGCAddReviewController { - let vc = UGCAddReviewController(nibName: toString(self), bundle: nil) - vc.model = model - vc.saver = saver - return vc - } - - private var model: Model! { - didSet { - sections = [] - assert(!model.ratings.isEmpty) - sections.append(.ratings) - sections.append(.text) - } - } - + private let placePageData: PlacePageData + private let model: UGCReviewModel + private let saver: UGCReviewSaver private var sections: [Sections] = [] - private var saver: UGCReviewSaver! + + @objc init(placePageData: PlacePageData, rating: UgcSummaryRatingType, saver: UGCReviewSaver) { + self.placePageData = placePageData + self.saver = saver + let ratings = placePageData.ratingCategories.map { + UGCRatingStars(title: $0, value: CGFloat(rating.rawValue)) + } + model = UGCReviewModel(ratings: ratings, text: "") + super.init(nibName: toString(UGCAddReviewController.self), bundle: nil) + title = placePageData.previewData.title + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } override func viewDidLoad() { super.viewDidLoad() - configNavBar() + sections.append(.ratings) + sections.append(.text) + + navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(onDone)) configTableView() } @@ -48,11 +50,6 @@ final class UGCAddReviewController: MWMTableViewController { } } - private func configNavBar() { - title = model.title - navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(onDone)) - } - private func configTableView() { tableView.registerNib(cellClass: UGCAddReviewRatingCell.self) tableView.registerNib(cellClass: UGCAddReviewTextCell.self) @@ -70,7 +67,10 @@ final class UGCAddReviewController: MWMTableViewController { reviewPosted = true model.text = text - saver.saveUgc(model: model, language: textCell?.reviewLanguage ?? "en", resultHandler: { (saveResult) in + saver.saveUgc(placePageData: placePageData, + model: model, + language: textCell?.reviewLanguage ?? "en", + resultHandler: { (saveResult) in guard let nc = self.navigationController else { return } if !saveResult { diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCReviewModel.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCReviewModel.swift index 42abfde712..f1b0d6e51c 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCReviewModel.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCReviewModel.swift @@ -1,16 +1,10 @@ @objc(MWMUGCReviewModel) final class UGCReviewModel: NSObject { - let reviewValue: UgcSummaryRatingType - @objc let ratings: [UGCRatingStars] @objc var text: String - let title: String - - @objc init(reviewValue: UgcSummaryRatingType, ratings: [UGCRatingStars], title: String, text: String) { - self.reviewValue = reviewValue + init(ratings: [UGCRatingStars], text: String) { self.ratings = ratings - self.title = title self.text = text } } diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCRating.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCRating.swift index b468368f86..57f2768e94 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCRating.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCRating.swift @@ -2,11 +2,9 @@ final class UGCRatingStars: NSObject { @objc let title: String @objc var value: CGFloat - let maxValue: CGFloat - @objc init(title: String, value: CGFloat, maxValue: CGFloat) { + init(title: String, value: CGFloat) { self.title = title self.value = value - self.maxValue = maxValue } } diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageCommonLayout.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageCommonLayout.swift index c0e0563823..e9631d3409 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageCommonLayout.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageCommonLayout.swift @@ -221,6 +221,9 @@ class PlacePageCommonLayout: NSObject, IPlacePageLayout { placePageData.onBookmarkStatusUpdate = { [weak self] in self?.updateBookmarkSection() } + placePageData.onUgcStatusUpdate = { [weak self] in + self?.onLoadUgc() + } MWMLocationManager.add(observer: self) if let lastLocation = MWMLocationManager.lastLocation() { @@ -300,17 +303,15 @@ extension PlacePageCommonLayout { } func onLoadUgc() { - if let ugcData = self.placePageData.ugcData { + if let ugcData = self.placePageData.ugcData { previewViewController.updateUgc(ugcData) if !ugcData.isTotalRatingEmpty { ratingSummaryViewController.ugcData = ugcData ratingSummaryViewController.view.isHidden = false } - if ugcData.isUpdateEmpty { - addReviewViewController.view.isHidden = false - } - if !ugcData.isEmpty { + addReviewViewController.view.isHidden = !ugcData.isUpdateEmpty + if !ugcData.isEmpty || !ugcData.isUpdateEmpty { reviewsViewController.ugcData = ugcData reviewsViewController.view.isHidden = false } diff --git a/iphone/Maps/UI/PlacePage/PlacePageManager/MWMPlacePageManager.mm b/iphone/Maps/UI/PlacePage/PlacePageManager/MWMPlacePageManager.mm index f4a2337590..3867abe785 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageManager/MWMPlacePageManager.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageManager/MWMPlacePageManager.mm @@ -372,17 +372,11 @@ void RegisterEventIfPossible(eye::MapObject::Event::Type const type) [self closePlacePage]; } -- (void)showUGCAddReview:(PlacePageData *)data rating:(UgcSummaryRatingType)value fromSource:(MWMUGCReviewSource)source -{ - NSMutableArray *ratings = [NSMutableArray array]; - for (NSString *cat in data.ratingCategories) { - [ratings addObject:[[MWMUGCRatingStars alloc] initWithTitle:cat - value:value - maxValue:5.0f]]; - } - +- (void)showUGCAddReview:(PlacePageData *)data + rating:(UgcSummaryRatingType)value + fromSource:(MWMUGCReviewSource)source { RegisterEventIfPossible(eye::MapObject::Event::Type::UgcEditorOpened); - NSString * sourceString; + NSString *sourceString; switch (source) { case MWMUGCReviewSourcePlacePage: sourceString = kStatPlacePage; @@ -401,9 +395,10 @@ void RegisterEventIfPossible(eye::MapObject::Event::Type const type) kStatMode: kStatAdd, kStatFrom: sourceString }]; - auto ugcReviewModel = - [[MWMUGCReviewModel alloc] initWithReviewValue:value ratings:ratings title:data.previewData.title text:@""]; - auto ugcVC = [MWMUGCAddReviewController instanceWithModel:ugcReviewModel saver:self]; + + MWMUGCAddReviewController *ugcVC = [[MWMUGCAddReviewController alloc] initWithPlacePageData:data + rating:value + saver:self]; [[MapViewController sharedController].navigationController pushViewController:ugcVC animated:YES]; } @@ -501,9 +496,10 @@ void RegisterEventIfPossible(eye::MapObject::Event::Type const type) - (MapViewController *)ownerViewController { return [MapViewController sharedController]; } -- (void)saveUgcWithModel:(MWMUGCReviewModel *)model - language:(NSString *)language - resultHandler:(void (^)(BOOL))resultHandler { +- (void)saveUgcWithPlacePageData:(PlacePageData *)placePageData + model:(MWMUGCReviewModel *)model + language:(NSString *)language + resultHandler:(void (^)(BOOL))resultHandler { using namespace ugc; auto appInfo = AppInfo.sharedInfo; auto const locale = @@ -522,7 +518,7 @@ void RegisterEventIfPossible(eye::MapObject::Event::Type const type) place_page::Info const & info = GetFramework().GetCurrentPlacePageInfo(); GetFramework().GetUGCApi()->SetUGCUpdate(info.GetID(), update, - [resultHandler, info](ugc::Storage::SettingResult const result) + [resultHandler, info, placePageData](ugc::Storage::SettingResult const result) { if (result != ugc::Storage::SettingResult::Success) { @@ -532,6 +528,7 @@ void RegisterEventIfPossible(eye::MapObject::Event::Type const type) resultHandler(YES); GetFramework().UpdatePlacePageInfoForCurrentSelection(); + [placePageData updateUgcStatus]; utils::RegisterEyeEventIfPossible(eye::MapObject::Event::Type::UgcSaved, GetFramework().GetCurrentPosition(), info);