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

MWMSearchCommonCell.mm « TableView « Search « UI « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 06aebb06e0cd0fad9b239c01553b1e39bf401c03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#import "MWMSearchCommonCell.h"
#import "CLLocation+Mercator.h"
#import "MWMLocationManager.h"

#include "geometry/mercator.hpp"
#include "platform/measurement_utils.hpp"

@interface MWMSearchCommonCell ()

@property(weak, nonatomic) IBOutlet UILabel * typeLabel;
@property(weak, nonatomic) IBOutlet UIView * infoView;
@property(weak, nonatomic) IBOutlet UILabel * infoLabel;
@property(weak, nonatomic) IBOutlet UIView * infoRatingView;
@property(nonatomic) IBOutletCollection(UIImageView) NSArray * infoRatingStars;
@property(weak, nonatomic) IBOutlet UILabel * locationLabel;
@property(weak, nonatomic) IBOutlet UILabel * distanceLabel;
@property(weak, nonatomic) IBOutlet UILabel * ratingLabel;
@property(weak, nonatomic) IBOutlet UILabel * priceLabel;

@property(weak, nonatomic) IBOutlet UIView * closedView;

@end

@implementation MWMSearchCommonCell

- (void)config:(search::Result const &)result isLocalAds:(BOOL)isLocalAds
{
  [super config:result];
  self.typeLabel.text = @(result.GetFeatureType().c_str()).capitalizedString;
  auto const & ratingStr = result.GetHotelRating();
  self.ratingLabel.text =
      ratingStr.empty() ? @"" : [NSString stringWithFormat:L(@"place_page_booking_rating"),
                                                            ratingStr.c_str()];
  self.priceLabel.text = @(result.GetHotelApproximatePricing().c_str());
  self.locationLabel.text = @(result.GetAddress().c_str());
  [self.locationLabel sizeToFit];

  NSUInteger const starsCount = result.GetStarsCount();
  NSString * cuisine = @(result.GetCuisine().c_str());
  if (starsCount > 0)
    [self setInfoRating:starsCount];
  else if (cuisine.length > 0)
    [self setInfoText:cuisine.capitalizedString];
  else
    [self clearInfo];

  switch (result.IsOpenNow())
  {
    case osm::Unknown:
    // TODO: Correctly handle Open Now = YES value (show "OPEN" mark).
    case osm::Yes: self.closedView.hidden = YES; break;
    case osm::No: self.closedView.hidden = NO; break;
    }

    if (result.HasPoint())
    {
      string distanceStr;
      CLLocation * lastLocation = [MWMLocationManager lastLocation];
      if (lastLocation)
      {
        double const dist =
            MercatorBounds::DistanceOnEarth(lastLocation.mercator, result.GetFeatureCenter());
        measurement_utils::FormatDistance(dist, distanceStr);
      }
      self.distanceLabel.text = @(distanceStr.c_str());
  }

  self.backgroundColor = isLocalAds ? [UIColor bannerBackground] : [UIColor white];
}

- (void)setInfoText:(NSString *)infoText
{
  self.infoView.hidden = NO;
  self.infoLabel.hidden = NO;
  self.infoRatingView.hidden = YES;
  self.infoLabel.text = infoText;
}

- (void)setInfoRating:(NSUInteger)infoRating
{
  self.infoView.hidden = NO;
  self.infoRatingView.hidden = NO;
  self.infoLabel.hidden = YES;
  [self.infoRatingStars
      enumerateObjectsUsingBlock:^(UIImageView * star, NSUInteger idx, BOOL * stop) {
        star.highlighted = star.tag <= infoRating;
      }];
}

- (void)clearInfo { self.infoView.hidden = YES; }
- (NSDictionary *)selectedTitleAttributes
{
  return @{
    NSForegroundColorAttributeName : UIColor.blackPrimaryText,
    NSFontAttributeName : UIFont.bold17
  };
}

- (NSDictionary *)unselectedTitleAttributes
{
  return @{
    NSForegroundColorAttributeName : UIColor.blackPrimaryText,
    NSFontAttributeName : UIFont.regular17
  };
}

@end