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

MWMPlacePageButtonCell.mm « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 203bc3bfbd1f8a74e8a331107a47ab66466b0bc1 (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
#import "Common.h"
#import "MWMPlacePageButtonCell.h"
#import "MWMFrameworkListener.h"
#import "MWMPlacePageViewManager.h"
#import "UIColor+MapsMeColor.h"
#import "MWMPlacePageProtocol.h"

@interface MWMPlacePageButtonCell ()<MWMFrameworkStorageObserver>

@property(weak, nonatomic) MWMPlacePageViewManager * manager;
@property(weak, nonatomic) IBOutlet UIButton * titleButton;
@property(nonatomic) MWMPlacePageCellType type;
@property(nonatomic) storage::TCountryId countryId;

@property(weak, nonatomic) id<MWMPlacePageButtonsProtocol> delegate;
@property(nonatomic) place_page::ButtonsRows rowType;
@end

@implementation MWMPlacePageButtonCell

- (void)config:(MWMPlacePageViewManager *)manager forType:(MWMPlacePageCellType)type
{
  self.countryId = GetFramework().GetCountryInfoGetter().GetRegionCountryId(manager.entity.mercator);
  self.manager = manager;
  self.type = type;
  [self refreshButtonEnabledState];
}

- (void)setEnabled:(BOOL)enabled
{
  self.titleButton.enabled = enabled;
}

- (BOOL)isEnabled
{
  return self.titleButton.isEnabled;
}

- (void)configForRow:(place_page::ButtonsRows)row withDelegate:(id<MWMPlacePageButtonsProtocol>)delegate
{
  self.delegate = delegate;
  self.rowType = row;
  switch(row)
  {
  case place_page::ButtonsRows::AddPlace:
    [self.titleButton setTitle:L(@"placepage_add_place_button") forState:UIControlStateNormal];
    break;
  case place_page::ButtonsRows::EditPlace:
    [self.titleButton setTitle:L(@"edit_place") forState:UIControlStateNormal];
    break;
  case place_page::ButtonsRows::AddBusiness:
    [self.titleButton setTitle:L(@"placepage_add_business_button") forState:UIControlStateNormal];
    break;
  case place_page::ButtonsRows::HotelDescription:
    [self.titleButton setTitle:L(@"details") forState:UIControlStateNormal];
    break;
  }
}

- (IBAction)buttonTap
{
  if (IPAD)
  {
    switch (self.type)
    {
    case MWMPlacePageCellTypeEditButton: [self.manager editPlace]; break;
    case MWMPlacePageCellTypeAddBusinessButton: [self.manager addBusiness]; break;
    case MWMPlacePageCellTypeAddPlaceButton: [self.manager addPlace]; break;
    case MWMPlacePageCellTypeBookingMore: [self.manager book:YES]; break;
    default: NSAssert(false, @"Incorrect cell type!"); break;
    }
    return;
  }

  using namespace place_page;
  switch (self.rowType)
  {
  case ButtonsRows::AddPlace: [self.delegate addPlace]; break;
  case ButtonsRows::EditPlace: [self.delegate editPlace]; break;
  case ButtonsRows::AddBusiness: [self.delegate addBusiness]; break;
  case ButtonsRows::HotelDescription: [self.delegate book:YES]; break;
  }
}

- (void)refreshButtonEnabledState
{
  if (self.countryId == kInvalidCountryId)
  {
    self.titleButton.enabled = YES;
    return;
  }
  NodeStatuses nodeStatuses;
  GetFramework().GetStorage().GetNodeStatuses(self.countryId, nodeStatuses);
  auto const & status = nodeStatuses.m_status;
  self.titleButton.enabled = status == NodeStatus::OnDisk || status == NodeStatus::OnDiskOutOfDate;
}

#pragma mark - MWMFrameworkStorageObserver

- (void)processCountryEvent:(TCountryId const &)countryId
{
  if (self.countryId != countryId)
    return;
  [self refreshButtonEnabledState];
}

#pragma mark - Properties

- (void)setType:(MWMPlacePageCellType)type
{
  _type = type;
  switch (type)
  {
  case MWMPlacePageCellTypeAddBusinessButton:
    [self.titleButton setTitle:L(@"placepage_add_business_button") forState:UIControlStateNormal];
    [MWMFrameworkListener addObserver:self];
    break;
  case MWMPlacePageCellTypeEditButton:
    [self.titleButton setTitle:L(@"edit_place") forState:UIControlStateNormal];
    [MWMFrameworkListener addObserver:self];
    break;
  case MWMPlacePageCellTypeAddPlaceButton:
    [self.titleButton setTitle:L(@"placepage_add_place_button") forState:UIControlStateNormal];
    [MWMFrameworkListener addObserver:self];
    break;
  case MWMPlacePageCellTypeBookingMore:
    [self.titleButton setTitle:L(@"details") forState:UIControlStateNormal];
    break;
  default: NSAssert(false, @"Invalid place page cell type!"); break;
  }
}

@end