Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladiMihaylenko <vxmihaylenko@gmail.com>2017-10-17 18:04:25 +0300
committerRoman Kuznetsov <r.kuznetsow@gmail.com>2017-10-17 18:12:34 +0300
commita96276a80c1066ced350b189dcf11c7834d2ed79 (patch)
tree33e8aef2519b7c831471514482026ca3dff2b192
parenteead1e56ec5a50703fcef64615e6e2a7b2b37f60 (diff)
[ios] Compressed empty reviews
-rw-r--r--iphone/Maps/Categories/String+BoundingRect.swift4
-rw-r--r--iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCReview.swift4
-rw-r--r--iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCReviewCell.swift5
-rw-r--r--iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReview.swift4
-rw-r--r--iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReviewCell.swift8
-rw-r--r--iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReviewCell.xib1
-rw-r--r--iphone/Maps/UI/PlacePage/UGCViewModel/MWMUGCViewModel.mm27
-rw-r--r--iphone/Maps/UI/Reviews/MWMReviewProtocol.h2
8 files changed, 39 insertions, 16 deletions
diff --git a/iphone/Maps/Categories/String+BoundingRect.swift b/iphone/Maps/Categories/String+BoundingRect.swift
index f3f2a004df..66dcb88b5e 100644
--- a/iphone/Maps/Categories/String+BoundingRect.swift
+++ b/iphone/Maps/Categories/String+BoundingRect.swift
@@ -2,6 +2,10 @@ import UIKit
extension String {
func size(width: CGFloat, font: UIFont, maxNumberOfLines: Int = 0) -> CGSize {
+ if (isEmpty) {
+ return CGSize(width: width, height: 0);
+ }
+
let maximumHeight = maxNumberOfLines == 0 ? CGFloat.greatestFiniteMagnitude : font.lineHeight * CGFloat(maxNumberOfLines + 1)
let constraintSize = CGSize(width: width, height: maximumHeight)
let options: NSStringDrawingOptions = [.usesLineFragmentOrigin, .usesFontLeading]
diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCReview.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCReview.swift
index bb11c9e958..f0bf756d2e 100644
--- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCReview.swift
+++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCReview.swift
@@ -1,11 +1,11 @@
@objc(MWMUGCReview)
final class UGCReview: NSObject, MWMReviewProtocol {
let title: String
- let date: Date
+ let date: String
let text: String
let rating: UGCRatingValueType
- @objc init(title: String, date: Date, text: String, rating: UGCRatingValueType) {
+ @objc init(title: String, date: String, text: String, rating: UGCRatingValueType) {
self.title = title
self.date = date
self.text = text
diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCReviewCell.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCReviewCell.swift
index cc95f4cddb..5209343f81 100644
--- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCReviewCell.swift
+++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCReviewCell.swift
@@ -37,10 +37,7 @@ final class UGCReviewCell: MWMTableViewCell {
@objc func config(review: UGCReview, onUpdate: @escaping () -> Void) {
titleLabel.text = review.title
- let dateFormatter = DateFormatter()
- dateFormatter.dateStyle = .medium
- dateFormatter.timeStyle = .none
- dateLabel.text = dateFormatter.string(from: review.date)
+ dateLabel.text = review.date
reviewLabel.text = review.text
reviewLabel.onUpdate = onUpdate
ratingView.value = review.rating.value
diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReview.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReview.swift
index 9391193ae0..3c3b2f5ec4 100644
--- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReview.swift
+++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReview.swift
@@ -1,10 +1,10 @@
@objc(MWMUGCYourReview)
final class UGCYourReview: NSObject, MWMReviewProtocol {
- let date: Date
+ let date: String
let text: String
let ratings: [UGCRatingStars]
- @objc init(date: Date, text: String, ratings: [UGCRatingStars]) {
+ @objc init(date: String, text: String, ratings: [UGCRatingStars]) {
self.date = date
self.text = text
self.ratings = ratings
diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReviewCell.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReviewCell.swift
index fe7583950a..4f23f6ac72 100644
--- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReviewCell.swift
+++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReviewCell.swift
@@ -1,6 +1,7 @@
@objc(MWMUGCYourReviewCell)
final class UGCYourReviewCell: MWMTableViewCell {
private enum Config {
+ static let defaultReviewBottomOffset: CGFloat = 16
static let minimumInteritemSpacing: CGFloat = 16
static let minItemsPerRow: CGFloat = 3
static let estimatedItemSize = CGSize(width: 96, height: 32)
@@ -30,6 +31,7 @@ final class UGCYourReviewCell: MWMTableViewCell {
}
}
+ @IBOutlet private weak var reviewBottomOffset: NSLayoutConstraint!
@IBOutlet private weak var ratingCollectionViewHeight: NSLayoutConstraint!
@IBOutlet private weak var ratingCollectionView: UICollectionView! {
didSet {
@@ -50,12 +52,10 @@ final class UGCYourReviewCell: MWMTableViewCell {
}
@objc func config(yourReview: UGCYourReview, onUpdate: @escaping () -> Void) {
- let dateFormatter = DateFormatter()
- dateFormatter.dateStyle = .medium
- dateFormatter.timeStyle = .none
- dateLabel.text = dateFormatter.string(from: yourReview.date)
+ dateLabel.text = yourReview.date
self.yourReview = yourReview
reviewLabel.text = yourReview.text
+ reviewBottomOffset.constant = yourReview.text.isEmpty ? 0 : Config.defaultReviewBottomOffset
reviewLabel.onUpdate = onUpdate
updateCollectionView { [weak self] in
self?.ratingCollectionView.reloadSections(IndexSet(integer: 0))
diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReviewCell.xib b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReviewCell.xib
index 5ea2a7cb5b..50e78095d7 100644
--- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReviewCell.xib
+++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCYourReviewCell.xib
@@ -111,6 +111,7 @@
<outlet property="dateLabel" destination="qZ5-I9-7dJ" id="Hkf-h6-ybf"/>
<outlet property="ratingCollectionView" destination="w6j-GC-6Bv" id="SbY-HY-zXO"/>
<outlet property="ratingCollectionViewHeight" destination="2hn-mr-UAw" id="xbR-Dl-OR3"/>
+ <outlet property="reviewBottomOffset" destination="NW0-Eu-IsI" id="emL-VB-8lD"/>
<outlet property="reviewLabel" destination="G4x-pj-fmv" id="pWq-RG-xv0"/>
<outlet property="titleLabel" destination="nht-6C-S3i" id="1lQ-nA-n7z"/>
</connections>
diff --git a/iphone/Maps/UI/PlacePage/UGCViewModel/MWMUGCViewModel.mm b/iphone/Maps/UI/PlacePage/UGCViewModel/MWMUGCViewModel.mm
index f9dc3b90ac..66f623c5f1 100644
--- a/iphone/Maps/UI/PlacePage/UGCViewModel/MWMUGCViewModel.mm
+++ b/iphone/Maps/UI/PlacePage/UGCViewModel/MWMUGCViewModel.mm
@@ -4,6 +4,8 @@
#include "ugc/types.hpp"
+#include <chrono>
+
using namespace place_page;
namespace
@@ -28,6 +30,7 @@ MWMUGCRatingValueType * ratingValueType(float rating)
@interface MWMUGCViewModel ()
@property(copy, nonatomic) MWMVoidBlock refreshCallback;
+@property(nonatomic) NSDateComponentsFormatter * formatter;
@end
@implementation MWMUGCViewModel
@@ -96,8 +99,7 @@ MWMUGCRatingValueType * ratingValueType(float rating)
{
auto const & review = m_ugcUpdate;
return [[MWMUGCYourReview alloc]
- initWithDate:[NSDate
- dateWithTimeIntervalSince1970:review.m_time.time_since_epoch().count()]
+ initWithDate:[self daysAgo:review.m_time]
text:@(review.m_text.m_text.c_str())
ratings:starsRatings(review.m_ratings)];
}
@@ -107,9 +109,28 @@ MWMUGCRatingValueType * ratingValueType(float rating)
auto const & review = m_ugc.m_reviews[idx];
return [[MWMUGCReview alloc]
initWithTitle:@(review.m_author.c_str())
- date:[NSDate dateWithTimeIntervalSince1970:review.m_time.time_since_epoch().count()]
+ date:[self daysAgo:review.m_time]
text:@(review.m_text.m_text.c_str())
rating:ratingValueType(review.m_rating)];
}
+#pragma mark - Propertis
+
+- (NSString *)daysAgo:(ugc::Time const &) time
+{
+ using namespace std::chrono;
+ NSDate * reviewDate = [NSDate dateWithTimeIntervalSince1970:duration_cast<seconds>(time.time_since_epoch()).count()];
+ return [self.formatter stringFromDate:reviewDate toDate:[NSDate date]];
+}
+
+- (NSDateComponentsFormatter *)formatter
+{
+ if (!_formatter)
+ {
+ _formatter = [[NSDateComponentsFormatter alloc] init];
+ _formatter.unitsStyle = NSDateComponentsFormatterUnitsStyleFull;
+ _formatter.allowedUnits = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
+ }
+ return _formatter;
+}
@end
diff --git a/iphone/Maps/UI/Reviews/MWMReviewProtocol.h b/iphone/Maps/UI/Reviews/MWMReviewProtocol.h
index 9189030b9d..11303b5e22 100644
--- a/iphone/Maps/UI/Reviews/MWMReviewProtocol.h
+++ b/iphone/Maps/UI/Reviews/MWMReviewProtocol.h
@@ -1,4 +1,4 @@
@protocol MWMReviewProtocol
-@property(nonatomic, readonly, copy) NSDate * _Nonnull date;
+@property(nonatomic, readonly, copy) NSString * _Nonnull date;
@property(nonatomic, readonly, copy) NSString * _Nonnull text;
@end