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

MWMSearchCommonCell.mm « TableView « Search « MapViewControls « CustomViews « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fbf0ffc296c65ec104a25d4b5c6e5828be3d9d4a (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#import "Common.h"
#import "MapsAppDelegate.h"
#import "MWMLocationManager.h"
#import "MWMSearchCommonCell.h"
#import "UIColor+MapsMeColor.h"
#import "UIFont+MapsMeFonts.h"

#include "Framework.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 UIView * closedView;

@end

@implementation MWMSearchCommonCell

- (void)config:(search::Result &)result forHeight:(BOOL)forHeight
{
  [super config:result];
  self.typeLabel.text = @(result.GetFeatureType().c_str()).capitalizedString;
  self.locationLabel.text = @(result.GetAddress().c_str());
  [self.locationLabel sizeToFit];

  if (!forHeight)
  {
    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());
        MeasurementUtils::FormatDistance(dist, distanceStr);
      }
      self.distanceLabel.text = @(distanceStr.c_str());
    }
  }
  if (isIOS7)
    [self layoutIfNeeded];
}

- (void)layoutSubviews
{
  [super layoutSubviews];
  if (isIOS7)
  {
    self.typeLabel.preferredMaxLayoutWidth = floor(self.typeLabel.width);
    self.infoLabel.preferredMaxLayoutWidth = floor(self.infoLabel.width);
    self.locationLabel.preferredMaxLayoutWidth = floor(self.locationLabel.width);
    self.distanceLabel.preferredMaxLayoutWidth = floor(self.distanceLabel.width);
    [super layoutSubviews];
  }
}

- (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
  };
}

+ (CGFloat)defaultCellHeight
{
  return 80.0;
}

- (CGFloat)cellHeight
{
  return ceil([self.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height);
}

@end