forked from organicmaps/organicmaps
[ios] Uncommented dummy impl.
This commit is contained in:
parent
18874322a2
commit
3271d0f5dd
14 changed files with 159 additions and 155 deletions
|
@ -7472,7 +7472,7 @@
|
|||
SWIFT_OBJC_BRIDGING_HEADER = "Bridging-Header.h";
|
||||
SWIFT_OBJC_INTERFACE_HEADER_NAME = SwiftBridge.h;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = On;
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
|
||||
SWIFT_VERSION = 4.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
|
|
|
@ -142,6 +142,7 @@ using CianIsReady = void (^)(NSArray<MWMCianItemModel *> * items);
|
|||
@class MWMViatorItemModel;
|
||||
@class MWMCianItemModel;
|
||||
@class MWMUGCViewModel;
|
||||
@class MWMUGCReviewModel;
|
||||
@class MWMUGCRatingValueType;
|
||||
@protocol MWMBanner;
|
||||
|
||||
|
@ -187,6 +188,10 @@ using CianIsReady = void (^)(NSArray<MWMCianItemModel *> * items);
|
|||
- (NSURL *)URLToAllReviews;
|
||||
- (NSArray<MWMGalleryItemModel *> *)photos;
|
||||
|
||||
// UGC
|
||||
- (ftraits::UGCRatingCategories)ugcRatingCategories;
|
||||
- (void)setUGCUpdateFrom:(MWMUGCReviewModel *)reviewModel;
|
||||
|
||||
// Viator
|
||||
- (void)fillOnlineViatorSection;
|
||||
- (NSArray<MWMViatorItemModel *> *)viatorItems;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#import "MWMPlacePageData.h"
|
||||
#import "LocaleTranslator.h"
|
||||
#import "MWMBannerHelpers.h"
|
||||
#import "MWMNetworkPolicy.h"
|
||||
#import "MWMUGCViewModel.h"
|
||||
|
@ -8,6 +9,8 @@
|
|||
|
||||
#include "local_ads/event.hpp"
|
||||
|
||||
#include "platform/preferred_languages.hpp"
|
||||
|
||||
#include "partners_api/booking_api.hpp"
|
||||
|
||||
#include "3party/opening_hours/opening_hours.hpp"
|
||||
|
@ -54,40 +57,8 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS";
|
|||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
m_info = info;
|
||||
|
||||
__weak auto weakSelf = self;
|
||||
_ugc = [[MWMUGCViewModel alloc]
|
||||
initWithInfo:info
|
||||
refresh:^{
|
||||
__strong auto self = weakSelf;
|
||||
auto ugc = self.ugc;
|
||||
if ([ugc isAvailable])
|
||||
{
|
||||
self.refreshPreviewCallback();
|
||||
|
||||
auto & sections = self->m_sections;
|
||||
auto const begin = sections.begin();
|
||||
auto const end = sections.end();
|
||||
|
||||
auto it = find(begin, end, Sections::UGCRating);
|
||||
if (it == end)
|
||||
return;
|
||||
NSUInteger const position = std::distance(begin, it);
|
||||
NSUInteger length = 1;
|
||||
|
||||
sections.push_back(Sections::UGCRating);
|
||||
if ([ugc canAddReview] && ![ugc isYourReviewAvailable])
|
||||
length++;
|
||||
if ([ugc isReviewsAvailable])
|
||||
length++;
|
||||
|
||||
self.sectionsAreReadyCallback({position, length}, self, YES /* It's a section */);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -131,23 +102,70 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS";
|
|||
[Statistics logEvent:kStatPlacepageTaxiShow withParameters:@{ @"provider" : provider }];
|
||||
}
|
||||
|
||||
auto ugc = self.ugc;
|
||||
if ([ugc isAvailable])
|
||||
{
|
||||
m_sections.push_back(Sections::UGCRating);
|
||||
if ([ugc canAddReview] && ![ugc isYourReviewAvailable])
|
||||
m_sections.push_back(Sections::UGCAddReview);
|
||||
if ([ugc isReviewsAvailable])
|
||||
m_sections.push_back(Sections::UGCReviews);
|
||||
}
|
||||
|
||||
// There is at least one of these buttons.
|
||||
if (m_info.ShouldShowAddPlace() || m_info.ShouldShowEditPlace() ||
|
||||
m_info.ShouldShowAddBusiness() || m_info.IsSponsored())
|
||||
{
|
||||
m_sections.push_back(Sections::Buttons);
|
||||
[self fillButtonsSection];
|
||||
}
|
||||
|
||||
if (m_info.ShouldShowUGC())
|
||||
[self addUGCSections];
|
||||
}
|
||||
|
||||
- (void)addUGCSections
|
||||
{
|
||||
NSAssert(m_info.ShouldShowUGC(), @"");
|
||||
|
||||
__weak auto wself = self;
|
||||
GetFramework().GetUGCApi()->GetUGC(
|
||||
m_info.GetID(), [wself](ugc::UGC const & ugc, ugc::UGCUpdate const & update) {
|
||||
__strong auto self = wself;
|
||||
self.ugc = [[MWMUGCViewModel alloc] initWithUGC:ugc update:update];
|
||||
|
||||
{
|
||||
auto & previewRows = self->m_previewRows;
|
||||
auto it = find(previewRows.begin(), previewRows.end(), PreviewRows::Address);
|
||||
if (it == previewRows.end())
|
||||
it = find(previewRows.begin(), previewRows.end(), PreviewRows::Space);
|
||||
|
||||
previewRows.insert(it, PreviewRows::Review);
|
||||
self.refreshPreviewCallback();
|
||||
}
|
||||
|
||||
auto & sections = self->m_sections;
|
||||
auto const begin = sections.begin();
|
||||
auto const end = sections.end();
|
||||
|
||||
auto it = find(begin, end, Sections::Buttons);
|
||||
NSUInteger const position = std::distance(begin, it);
|
||||
NSUInteger length = 0;
|
||||
|
||||
if (!self.ugc.isUGCEmpty)
|
||||
{
|
||||
length = 2;
|
||||
it = sections.insert(it, Sections::UGCRating) + 1;
|
||||
if (self.ugc.isUGCUpdateEmpty)
|
||||
{
|
||||
it = sections.insert(it, Sections::UGCAddReview) + 1;
|
||||
length++;
|
||||
}
|
||||
|
||||
it = sections.insert(it, Sections::UGCReviews) + 1;
|
||||
}
|
||||
else if (self.ugc.isUGCUpdateEmpty)
|
||||
{
|
||||
it = sections.insert(it, Sections::UGCAddReview);
|
||||
length = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
it = sections.insert(it, Sections::UGCReviews);
|
||||
length = 1;
|
||||
}
|
||||
|
||||
self.sectionsAreReadyCallback({position, length}, self, YES /* It's a section */);
|
||||
});
|
||||
}
|
||||
|
||||
- (void)fillPreviewSection
|
||||
|
@ -156,10 +174,11 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS";
|
|||
if (self.externalTitle.length) m_previewRows.push_back(PreviewRows::ExternalTitle);
|
||||
if (self.subtitle.length || self.isMyPosition) m_previewRows.push_back(PreviewRows::Subtitle);
|
||||
if (self.schedule != OpeningHours::Unknown) m_previewRows.push_back(PreviewRows::Schedule);
|
||||
if (self.isBooking || [self.ugc isAvailable])
|
||||
if (self.isBooking)
|
||||
m_previewRows.push_back(PreviewRows::Review);
|
||||
if (self.address.length) m_previewRows.push_back(PreviewRows::Address);
|
||||
|
||||
m_previewRows.push_back(PreviewRows::Space);
|
||||
|
||||
NSAssert(!m_previewRows.empty(), @"Preview row's can't be empty!");
|
||||
|
||||
if (network_policy::CanUseNetwork() && ![MWMSettings adForbidden] && m_info.HasBanner() &&
|
||||
|
@ -670,6 +689,27 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS";
|
|||
return _photos;
|
||||
}
|
||||
|
||||
#pragma mark - UGC
|
||||
|
||||
- (ftraits::UGCRatingCategories)ugcRatingCategories { return m_info.GetRatingCategories(); }
|
||||
|
||||
- (void)setUGCUpdateFrom:(MWMUGCReviewModel *)reviewModel
|
||||
{
|
||||
using namespace ugc;
|
||||
|
||||
auto const locale =
|
||||
static_cast<uint8_t>(StringUtf8Multilang::GetLangIndex(languages::GetCurrentNorm()));
|
||||
Text t{reviewModel.text.UTF8String, locale};
|
||||
Ratings r;
|
||||
for (MWMUGCRatingStars * star in reviewModel.ratings)
|
||||
r.emplace_back(star.title.UTF8String, star.value);
|
||||
|
||||
UGCUpdate update{r, t, std::chrono::system_clock::now()};
|
||||
auto & f = GetFramework();
|
||||
f.GetUGCApi()->SetUGCUpdate(m_info.GetID(), update);
|
||||
f.UpdatePlacePageInfoForCurrentSelection();
|
||||
}
|
||||
|
||||
#pragma mark - Bookmark
|
||||
|
||||
- (NSString *)externalTitle
|
||||
|
|
|
@ -571,20 +571,24 @@ void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName)
|
|||
auto data = self.data;
|
||||
if (!data)
|
||||
return;
|
||||
// TODO(ios, UGC): Fill ratings.
|
||||
NSArray<MWMUGCRatingStars *> * ratings = @[];
|
||||
auto const canAddTextToReview = [data.ugc canAddTextToReview];
|
||||
auto title = [data title];
|
||||
// TODO(ios, UGC): Fill your review text.
|
||||
auto text = @"";
|
||||
auto ugcReviewModel = [[MWMUGCReviewModel alloc] initWithReviewValue:value
|
||||
ratings:ratings
|
||||
canAddTextToReview:canAddTextToReview
|
||||
title:title
|
||||
text:text];
|
||||
|
||||
NSMutableArray<MWMUGCRatingStars *> * ratings = [@[] mutableCopy];
|
||||
for (auto & cat : data.ugcRatingCategories)
|
||||
[ratings addObject:[[MWMUGCRatingStars alloc] initWithTitle:@(cat.c_str())
|
||||
value:value
|
||||
maxValue:5.0f]];
|
||||
auto title = data.title;
|
||||
auto ugcReviewModel =
|
||||
[[MWMUGCReviewModel alloc] initWithReviewValue:value ratings:ratings title:title text:@""];
|
||||
auto ugcVC = [MWMUGCAddReviewController instanceWithModel:ugcReviewModel
|
||||
onSave:^(MWMUGCReviewModel * model){
|
||||
// TODO(ios, UGC): Save review (model).
|
||||
onSave:^(MWMUGCReviewModel * model) {
|
||||
auto data = self.data;
|
||||
if (!data)
|
||||
{
|
||||
NSAssert(false, @"");
|
||||
return;
|
||||
}
|
||||
[data setUGCUpdateFrom:model];
|
||||
}];
|
||||
[[MapViewController controller].navigationController pushViewController:ugcVC animated:YES];
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
final class UGCAddReviewController: MWMTableViewController {
|
||||
typealias Model = UGCReviewModel
|
||||
|
||||
weak var textCell: UGCAddReviewTextCell?
|
||||
|
||||
enum Sections {
|
||||
case ratings
|
||||
case text
|
||||
|
@ -17,12 +19,9 @@ final class UGCAddReviewController: MWMTableViewController {
|
|||
private var model: Model! {
|
||||
didSet {
|
||||
sections = []
|
||||
if !model.ratings.isEmpty {
|
||||
sections.append(.ratings)
|
||||
}
|
||||
if model.canAddTextToReview {
|
||||
sections.append(.text)
|
||||
}
|
||||
assert(!model.ratings.isEmpty);
|
||||
sections.append(.ratings)
|
||||
sections.append(.text)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +48,11 @@ final class UGCAddReviewController: MWMTableViewController {
|
|||
}
|
||||
|
||||
@objc private func onDone() {
|
||||
guard let text = textCell?.reviewText else {
|
||||
assert(false);
|
||||
return
|
||||
}
|
||||
model.text = text
|
||||
onSave(model)
|
||||
guard let nc = navigationController else { return }
|
||||
if MWMAuthorizationViewModel.isAuthenticated() {
|
||||
|
@ -80,6 +84,7 @@ final class UGCAddReviewController: MWMTableViewController {
|
|||
case .text:
|
||||
let cell = tableView.dequeueReusableCell(withCellClass: UGCAddReviewTextCell.self, indexPath: indexPath) as! UGCAddReviewTextCell
|
||||
cell.reviewText = model.text
|
||||
textCell = cell;
|
||||
return cell
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
|
@ -15,7 +15,7 @@
|
|||
</connections>
|
||||
</placeholder>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<tableView opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" bouncesZoom="NO" style="grouped" separatorStyle="none" allowsSelection="NO" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="i5M-Pr-FkT">
|
||||
<tableView opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" bouncesZoom="NO" keyboardDismissMode="interactive" style="grouped" separatorStyle="none" allowsSelection="NO" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="i5M-Pr-FkT">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
|
||||
|
|
|
@ -2,17 +2,14 @@
|
|||
final class UGCReviewModel: NSObject {
|
||||
let reviewValue: MWMRatingSummaryViewValueType
|
||||
|
||||
let ratings: [UGCRatingStars]
|
||||
|
||||
let canAddTextToReview: Bool
|
||||
@objc let ratings: [UGCRatingStars]
|
||||
@objc var text: String
|
||||
|
||||
let title: String
|
||||
let text: String
|
||||
|
||||
@objc init(reviewValue: MWMRatingSummaryViewValueType, ratings: [UGCRatingStars], canAddTextToReview: Bool, title: String, text: String) {
|
||||
@objc init(reviewValue: MWMRatingSummaryViewValueType, ratings: [UGCRatingStars], title: String, text: String) {
|
||||
self.reviewValue = reviewValue
|
||||
self.ratings = ratings
|
||||
self.canAddTextToReview = canAddTextToReview
|
||||
self.title = title
|
||||
self.text = text
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ class UGCRatingValueType: NSObject {
|
|||
|
||||
@objc(MWMUGCRatingStars)
|
||||
final class UGCRatingStars: NSObject {
|
||||
let title: String
|
||||
var value: CGFloat
|
||||
@objc let title: String
|
||||
@objc var value: CGFloat
|
||||
let maxValue: CGFloat
|
||||
|
||||
@objc init(title: String, value: CGFloat, maxValue: CGFloat) {
|
||||
|
|
|
@ -83,6 +83,7 @@ final class UGCYourReviewCell: MWMTableViewCell {
|
|||
layout.minimumInteritemSpacing = interitemSpacing
|
||||
layout.itemSize = CGSize(width: itemWidth, height: Config.estimatedItemSize.height)
|
||||
|
||||
assert(itemsPerRow > 0);
|
||||
let rowsCount = ceil(ratingsCount / itemsPerRow)
|
||||
self.ratingCollectionViewHeight.constant = rowsCount * Config.estimatedItemSize.height + (rowsCount - 1) * layout.minimumLineSpacing + inset.top + inset.bottom
|
||||
self.ratingCollectionView.performBatchUpdates(updates, completion: nil)
|
||||
|
|
|
@ -689,6 +689,7 @@ map<MetainfoRows, Class> const kMetaInfoCells = {
|
|||
auto tv = self.placePageView.tableView;
|
||||
[tv reloadSections:[NSIndexSet indexSetWithIndex:0]
|
||||
withRowAnimation:UITableViewRowAnimationFade];
|
||||
[self.previewLayoutHelper notifyHeightWashChanded];
|
||||
};
|
||||
|
||||
data.sectionsAreReadyCallback = ^(NSRange const & range, MWMPlacePageData * d, BOOL isSection) {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
- (void)setDistanceToObject:(NSString *)distance;
|
||||
- (void)setSpeedAndAltitude:(NSString *)speedAndAltitude;
|
||||
- (void)insertRowAtTheEnd;
|
||||
- (void)notifyHeightWashChanded;
|
||||
- (CGFloat)height;
|
||||
|
||||
- (void)layoutInOpenState:(BOOL)isOpen;
|
||||
|
|
|
@ -244,10 +244,10 @@ array<Class, 8> const kPreviewCells = {{[_MWMPPPTitle class],
|
|||
}
|
||||
else
|
||||
{
|
||||
auto ugc = data.ugc;
|
||||
[reviewCell configWithRating:[ugc summaryRating]
|
||||
canAddReview:[ugc canAddReview] && ![ugc isYourReviewAvailable]
|
||||
reviewsCount:[ugc totalReviewsCount]
|
||||
NSAssert(data.ugc, @"");
|
||||
[reviewCell configWithRating:data.ugc.summaryRating
|
||||
canAddReview:data.ugc.isUGCUpdateEmpty
|
||||
reviewsCount:data.ugc.totalReviewsCount
|
||||
priceSetter:^(UILabel * _Nonnull) {
|
||||
}
|
||||
onAddReview:^{
|
||||
|
@ -349,6 +349,8 @@ array<Class, 8> const kPreviewCells = {{[_MWMPPPTitle class],
|
|||
[self.delegate heightWasChanged];
|
||||
}
|
||||
|
||||
- (void)notifyHeightWashChanded { [self.delegate heightWasChanged]; }
|
||||
|
||||
- (CGFloat)height
|
||||
{
|
||||
auto const rect = [self.tableView rectForRowAtIndexPath:self.lastCellIndexPath];
|
||||
|
|
|
@ -6,9 +6,10 @@ typedef NS_ENUM(NSUInteger, MWMUGCViewModelPrice) {
|
|||
MWMUGCViewModelPriceHigh
|
||||
};
|
||||
|
||||
namespace place_page
|
||||
namespace ugc
|
||||
{
|
||||
class Info;
|
||||
struct UGC;
|
||||
struct UGCUpdate;
|
||||
}
|
||||
|
||||
@class MWMUGCRatingValueType;
|
||||
|
@ -19,18 +20,15 @@ class Info;
|
|||
|
||||
@interface MWMUGCViewModel : NSObject<MWMReviewsViewModelProtocol>
|
||||
|
||||
- (instancetype)initWithInfo:(place_page::Info const &)info refresh:(MWMVoidBlock)refresh;
|
||||
- (instancetype)initWithUGC:(ugc::UGC const &)ugc update:(ugc::UGCUpdate const &)update;
|
||||
|
||||
- (BOOL)isAvailable;
|
||||
- (BOOL)canAddReview;
|
||||
- (BOOL)canAddTextToReview;
|
||||
- (BOOL)isYourReviewAvailable;
|
||||
- (BOOL)isReviewsAvailable;
|
||||
- (BOOL)isUGCEmpty;
|
||||
- (BOOL)isUGCUpdateEmpty;
|
||||
|
||||
- (NSInteger)ratingCellsCount;
|
||||
- (NSInteger)addReviewCellsCount;
|
||||
- (NSUInteger)ratingCellsCount;
|
||||
- (NSUInteger)addReviewCellsCount;
|
||||
|
||||
- (NSInteger)totalReviewsCount;
|
||||
- (NSUInteger)totalReviewsCount;
|
||||
- (MWMUGCRatingValueType *)summaryRating;
|
||||
- (NSArray<MWMUGCRatingStars *> *)ratings;
|
||||
|
||||
|
|
|
@ -2,12 +2,8 @@
|
|||
#import "MWMPlacePageData.h"
|
||||
#import "SwiftBridge.h"
|
||||
|
||||
#include "Framework.h"
|
||||
|
||||
#include "ugc/types.hpp"
|
||||
|
||||
#include "map/place_page_info.hpp"
|
||||
|
||||
using namespace place_page;
|
||||
|
||||
namespace
|
||||
|
@ -32,7 +28,6 @@ MWMUGCRatingValueType * ratingValueType(float rating)
|
|||
|
||||
@interface MWMUGCViewModel ()
|
||||
@property(copy, nonatomic) MWMVoidBlock refreshCallback;
|
||||
@property(nonatomic) BOOL isFilled;
|
||||
@end
|
||||
|
||||
@implementation MWMUGCViewModel
|
||||
|
@ -42,79 +37,34 @@ MWMUGCRatingValueType * ratingValueType(float rating)
|
|||
ugc::UGCUpdate m_ugcUpdate;
|
||||
}
|
||||
|
||||
- (instancetype)initWithInfo:(place_page::Info const &)info refresh:(MWMVoidBlock)refresh
|
||||
- (instancetype)initWithUGC:(ugc::UGC const &)ugc update:(ugc::UGCUpdate const &)update
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
m_info = info;
|
||||
|
||||
if ([self isAvailable])
|
||||
{
|
||||
[self fill];
|
||||
self.refreshCallback = refresh;
|
||||
m_ugc = ugc;
|
||||
m_ugcUpdate = update;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)isAvailable { return m_info.ShouldShowUGC(); }
|
||||
- (BOOL)canAddReview { return m_info.CanBeRated(); }
|
||||
- (BOOL)canAddTextToReview { return m_info.CanBeRated() && m_info.CanBeReviewed(); }
|
||||
- (BOOL)isYourReviewAvailable
|
||||
{
|
||||
if (!self.isFilled)
|
||||
return NO;
|
||||
// TODO(ios, UGC): Add logic
|
||||
// return m_ugcUpdate.isValid();
|
||||
return YES;
|
||||
}
|
||||
- (BOOL)isReviewsAvailable { return [self numberOfReviews] != 0; }
|
||||
|
||||
- (void)fill
|
||||
{
|
||||
self.isFilled = NO;
|
||||
auto & f = GetFramework();
|
||||
auto const featureID = m_info.GetID();
|
||||
f.GetUGCApi()->GetUGC(featureID, [self](ugc::UGC const & ugc, ugc::UGCUpdate const & update) {
|
||||
self->m_ugc = ugc;
|
||||
self->m_ugcUpdate = update;
|
||||
self.isFilled = YES;
|
||||
self.refreshCallback();
|
||||
});
|
||||
}
|
||||
|
||||
- (NSInteger)ratingCellsCount { return 1; }
|
||||
- (NSInteger)addReviewCellsCount { return [self isYourReviewAvailable] ? 0 : 1; }
|
||||
|
||||
- (NSInteger)totalReviewsCount
|
||||
{
|
||||
// TODO(ios, UGC): Add logic
|
||||
// Used for display in string
|
||||
return 32;
|
||||
}
|
||||
- (MWMUGCRatingValueType *)summaryRating { return ratingValueType(m_ugc.m_aggRating); }
|
||||
|
||||
- (NSArray<MWMUGCRatingStars *> *)ratings
|
||||
{
|
||||
NSAssert(self.isFilled, @"UGC is not filled");
|
||||
return starsRatings(m_ugc.m_ratings);
|
||||
}
|
||||
- (BOOL)isUGCEmpty { return static_cast<BOOL>(m_ugc.IsEmpty()); }
|
||||
- (BOOL)isUGCUpdateEmpty { return static_cast<BOOL>(m_ugcUpdate.IsEmpty()); }
|
||||
- (NSUInteger)ratingCellsCount { return 1; }
|
||||
- (NSUInteger)addReviewCellsCount { return 1; }
|
||||
- (NSUInteger)totalReviewsCount { return static_cast<NSUInteger>(m_ugc.m_basedOn); }
|
||||
- (MWMUGCRatingValueType *)summaryRating { return ratingValueType(m_ugc.m_totalRating); }
|
||||
- (NSArray<MWMUGCRatingStars *> *)ratings { return starsRatings(m_ugc.m_ratings); }
|
||||
|
||||
#pragma mark - MWMReviewsViewModelProtocol
|
||||
|
||||
- (NSInteger)numberOfReviews
|
||||
{
|
||||
if (!self.isFilled)
|
||||
return 0;
|
||||
return m_ugc.m_reviews.size() + ([self isYourReviewAvailable] ? 1 : 0);
|
||||
}
|
||||
- (NSUInteger)numberOfReviews { return m_ugc.m_reviews.size() + !self.isUGCUpdateEmpty; }
|
||||
|
||||
- (id<MWMReviewProtocol> _Nonnull)reviewWithIndex:(NSInteger)index
|
||||
- (id<MWMReviewProtocol> _Nonnull)reviewWithIndex:(NSUInteger)index
|
||||
{
|
||||
NSAssert(self.isFilled, @"UGC is not filled");
|
||||
auto idx = index;
|
||||
NSAssert(idx >= 0, @"Invalid index");
|
||||
if ([self isYourReviewAvailable])
|
||||
if (!self.isUGCUpdateEmpty)
|
||||
{
|
||||
if (idx == 0)
|
||||
{
|
||||
|
@ -130,7 +80,7 @@ MWMUGCRatingValueType * ratingValueType(float rating)
|
|||
NSAssert(idx < m_ugc.m_reviews.size(), @"Invalid index");
|
||||
auto const & review = m_ugc.m_reviews[idx];
|
||||
return [[MWMUGCReview alloc]
|
||||
initWithTitle:@(review.m_author.m_name.c_str())
|
||||
initWithTitle:@(review.m_author.c_str())
|
||||
date:[NSDate dateWithTimeIntervalSince1970:review.m_time.time_since_epoch().count()]
|
||||
text:@(review.m_text.m_text.c_str())
|
||||
rating:ratingValueType(review.m_rating)];
|
||||
|
|
Loading…
Add table
Reference in a new issue