[ios] Correct showing more reviews button

This commit is contained in:
VladiMihaylenko 2017-10-17 16:05:41 +03:00 committed by r.kuznetsov
parent 9ae5833fca
commit c29b1deb65
4 changed files with 76 additions and 21 deletions

View file

@ -1263,6 +1263,9 @@
F6BD1D231CA412E30047B8E8 /* MWMOsmAuthAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = F6BD1D221CA412E30047B8E8 /* MWMOsmAuthAlert.xib */; };
F6BD1D241CA412E40047B8E8 /* MWMOsmAuthAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = F6BD1D221CA412E30047B8E8 /* MWMOsmAuthAlert.xib */; };
F6BD33871B62412E00F2CE18 /* MWMNavigationDashboardEntity.mm in Sources */ = {isa = PBXBuildFile; fileRef = F6BD33861B62412E00F2CE18 /* MWMNavigationDashboardEntity.mm */; };
F6C16A651F9626B1000FE296 /* ReviewsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3430291B1F87BC3000D0A07C /* ReviewsViewController.xib */; };
F6C16A661F9626B2000FE296 /* ReviewsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3430291B1F87BC3000D0A07C /* ReviewsViewController.xib */; };
F6C16A671F9626B2000FE296 /* ReviewsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3430291B1F87BC3000D0A07C /* ReviewsViewController.xib */; };
F6C269F61F14D76F00EB6519 /* ugc_types.csv in Resources */ = {isa = PBXBuildFile; fileRef = F642D1221F0F9D1D005E3C25 /* ugc_types.csv */; };
F6C269F71F14D76F00EB6519 /* ugc_types.csv in Resources */ = {isa = PBXBuildFile; fileRef = F642D1221F0F9D1D005E3C25 /* ugc_types.csv */; };
F6E2FD4F1E097BA00083EBEC /* MWMMapDownloaderAdsTableViewCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = F6E2FBFF1E097B9F0083EBEC /* MWMMapDownloaderAdsTableViewCell.mm */; };
@ -5110,6 +5113,7 @@
349D1AD41E2E325B004A2006 /* MWMBottomMenuCollectionViewPortraitCell.xib in Resources */,
349D1AE01E2E325C004A2006 /* MWMBottomMenuViewController.xib in Resources */,
34D3B01D1E389D05004100F9 /* MWMButtonCell.xib in Resources */,
F6C16A651F9626B1000FE296 /* ReviewsViewController.xib in Resources */,
349A357B1B53D4C9009677EE /* MWMCircularProgress.xib in Resources */,
F64F199E1AB81A00006EAF7E /* MWMDefaultAlert.xib in Resources */,
F6E2FE451E097BA00083EBEC /* MWMDirectionView.xib in Resources */,
@ -5344,6 +5348,7 @@
F6E2FE0D1E097BA00083EBEC /* MWMOpeningHoursDeleteScheduleTableViewCell.xib in Resources */,
F6E2FE161E097BA00083EBEC /* MWMOpeningHoursTimeSelectorTableViewCell.xib in Resources */,
F6E2FE1C1E097BA00083EBEC /* MWMOpeningHoursTimeSpanTableViewCell.xib in Resources */,
F6C16A671F9626B2000FE296 /* ReviewsViewController.xib in Resources */,
F6BD1D241CA412E40047B8E8 /* MWMOsmAuthAlert.xib in Resources */,
F6FE3C3C1CC5106500A73196 /* MWMPlaceDoesntExistAlert.xib in Resources */,
F6E2FE581E097BA00083EBEC /* MWMPlacePageActionBar.xib in Resources */,
@ -5532,6 +5537,7 @@
F6E2FE0E1E097BA00083EBEC /* MWMOpeningHoursDeleteScheduleTableViewCell.xib in Resources */,
F6E2FE171E097BA00083EBEC /* MWMOpeningHoursTimeSelectorTableViewCell.xib in Resources */,
F6E2FE1D1E097BA00083EBEC /* MWMOpeningHoursTimeSpanTableViewCell.xib in Resources */,
F6C16A661F9626B2000FE296 /* ReviewsViewController.xib in Resources */,
849CF65A1DE842290024A8A5 /* MWMOsmAuthAlert.xib in Resources */,
849CF5E81DE842290024A8A5 /* MWMPlaceDoesntExistAlert.xib in Resources */,
F6E2FE591E097BA00083EBEC /* MWMPlacePageActionBar.xib in Resources */,

View file

@ -294,9 +294,9 @@ map<MetainfoRows, Class> const kMetaInfoCells = {
case Sections::HotelDescription: return data.descriptionRows.size();
case Sections::HotelFacilities: return data.hotelFacilitiesRows.size();
case Sections::HotelReviews: return data.hotelReviewsRows.size();
case Sections::UGCRating: return [data.ugc ratingCellsCount];
case Sections::UGCAddReview: return [data.ugc addReviewCellsCount];
case Sections::UGCReviews: return MIN([data.ugc numberOfReviews], 3) + 1 /* More button */;
case Sections::UGCRating: return data.ugc.ratingCellsCount;
case Sections::UGCAddReview: return data.ugc.addReviewCellsCount;
case Sections::UGCReviews: return data.ugc.reviewRows.size();
}
}
@ -530,7 +530,33 @@ map<MetainfoRows, Class> const kMetaInfoCells = {
case Sections::UGCReviews:
{
auto ugc = data.ugc;
if ([tableView numberOfRowsInSection:indexPath.section] - 1 == indexPath.row)
auto const & reviewRows = ugc.reviewRows;
using namespace ugc::view_model;
auto onUpdate = ^{
[tableView refresh];
};
switch (reviewRows[indexPath.row])
{
case ReviewRow::YourReview:
{
Class cls = [MWMUGCYourReviewCell class];
auto c = static_cast<MWMUGCYourReviewCell *>(
[tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath]);
[c configWithYourReview:static_cast<MWMUGCYourReview *>([ugc reviewWithIndex:indexPath.row])
onUpdate:onUpdate];
return c;
}
case ReviewRow::Review:
{
Class cls = [MWMUGCReviewCell class];
auto c = static_cast<MWMUGCReviewCell *>(
[tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath]);
[c configWithReview:static_cast<MWMUGCReview *>([ugc reviewWithIndex:indexPath.row])
onUpdate:onUpdate];
return c;
}
case ReviewRow::MoreReviews:
{
Class cls = [MWMPlacePageButtonCell class];
auto c = static_cast<MWMPlacePageButtonCell *>(
@ -542,23 +568,7 @@ map<MetainfoRows, Class> const kMetaInfoCells = {
isInsetButton:NO];
return c;
}
auto onUpdate = ^{
[tableView refresh];
};
id review = [ugc reviewWithIndex:indexPath.row];
if ([review isKindOfClass:[MWMUGCYourReview class]])
{
Class cls = [MWMUGCYourReviewCell class];
auto c = static_cast<MWMUGCYourReviewCell *>(
[tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath]);
[c configWithYourReview:static_cast<MWMUGCYourReview *>(review) onUpdate:onUpdate];
return c;
}
Class cls = [MWMUGCReviewCell class];
auto c = static_cast<MWMUGCReviewCell *>(
[tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath]);
[c configWithReview:static_cast<MWMUGCReview *>(review) onUpdate:onUpdate];
return c;
}
}
}

View file

@ -1,5 +1,7 @@
#import "MWMReviewsViewModelProtocol.h"
#include <vector>
typedef NS_ENUM(NSUInteger, MWMUGCViewModelPrice) {
MWMUGCViewModelPriceLow,
MWMUGCViewModelPriceMedium,
@ -10,7 +12,17 @@ namespace ugc
{
struct UGC;
struct UGCUpdate;
}
namespace view_model
{
enum class ReviewRow
{
YourReview,
Review,
MoreReviews
};
} // namespace view_model
} // namespace ugc
@class MWMUGCRatingValueType;
@class MWMUGCRatingStars;
@ -27,6 +39,7 @@ struct UGCUpdate;
- (NSUInteger)ratingCellsCount;
- (NSUInteger)addReviewCellsCount;
- (std::vector<ugc::view_model::ReviewRow> const &)reviewRows;
- (NSUInteger)totalReviewsCount;
- (MWMUGCRatingValueType *)summaryRating;

View file

@ -35,6 +35,7 @@ MWMUGCRatingValueType * ratingValueType(float rating)
place_page::Info m_info;
ugc::UGC m_ugc;
ugc::UGCUpdate m_ugcUpdate;
std::vector<ugc::view_model::ReviewRow> m_reviewRows;
}
- (instancetype)initWithUGC:(ugc::UGC const &)ugc update:(ugc::UGCUpdate const &)update
@ -44,10 +45,34 @@ MWMUGCRatingValueType * ratingValueType(float rating)
{
m_ugc = ugc;
m_ugcUpdate = update;
[self fillReviewRows];
}
return self;
}
- (void)fillReviewRows
{
using namespace ugc::view_model;
m_reviewRows.clear();
if (!m_ugcUpdate.IsEmpty())
m_reviewRows.push_back(ReviewRow::YourReview);
if (m_ugc.IsEmpty())
return;
auto const reviewsSize = m_ugc.m_reviews.size();
auto constexpr kMaxSize = 3;
if (reviewsSize > kMaxSize)
{
m_reviewRows.insert(m_reviewRows.end(), kMaxSize, ReviewRow::Review);
m_reviewRows.push_back(ReviewRow::MoreReviews);
}
else
{
m_reviewRows.insert(m_reviewRows.end(), reviewsSize, ReviewRow::Review);
}
}
- (BOOL)isUGCEmpty { return static_cast<BOOL>(m_ugc.IsEmpty()); }
- (BOOL)isUGCUpdateEmpty { return static_cast<BOOL>(m_ugcUpdate.IsEmpty()); }
- (NSUInteger)ratingCellsCount { return 1; }
@ -55,6 +80,7 @@ MWMUGCRatingValueType * ratingValueType(float rating)
- (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); }
- (std::vector<ugc::view_model::ReviewRow> const &)reviewRows { return m_reviewRows; }
#pragma mark - MWMReviewsViewModelProtocol