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

MWMBookmarkColorViewController.mm « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c7b7bac5e700cad4491e14d3667c25e596935587 (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 "MWMBookmarkColorViewController.h"
#import "UIKitCategories.h"
#import "MWMBookmarkColorCell.h"
#import "MWMPlacePageEntity.h"
#import "MWMPlacePageViewManager.h"
#import "UIViewController+navigation.h"

extern NSArray * const kBookmarkColorsVariant;

static NSString * const kBookmarkColorCellIdentifier = @"MWMBookmarkColorCell";

@interface MWMBookmarkColorViewController ()

@property (weak, nonatomic) IBOutlet UITableView * tableView;
@property (nonatomic) BOOL colorWasChanged;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * tableViewHeight;

@end

@interface MWMBookmarkColorViewController (TableView) <UITableViewDataSource, UITableViewDelegate>
@end

@implementation MWMBookmarkColorViewController

- (void)viewDidLoad
{
  [super viewDidLoad];
  self.title = L(@"bookmark_color");
  [self.tableView registerNib:[UINib nibWithNibName:kBookmarkColorCellIdentifier bundle:nil] forCellReuseIdentifier:kBookmarkColorCellIdentifier];
  self.colorWasChanged = NO;
}

- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];
  [self configureTableViewForOrientation:self.interfaceOrientation];
  [self.tableView reloadData];
  if (!self.iPadOwnerNavigationController)
    return;

  [self.iPadOwnerNavigationController setNavigationBarHidden:NO];
  CGFloat const bottomOffset = 88.;
  self.iPadOwnerNavigationController.view.height = self.tableView.height + bottomOffset;
  [self showBackButton];
}

- (void)backTap
{
  if (self.iPadOwnerNavigationController)
   [self.iPadOwnerNavigationController setNavigationBarHidden:YES];

  [self.navigationController popViewControllerAnimated:YES];
}

- (void)configureTableViewForOrientation:(UIInterfaceOrientation)orientation
{
  if (self.iPadOwnerNavigationController)
    return;

  CGSize const size = self.navigationController.view.bounds.size;
  CGFloat const defaultHeight = 352.;
  switch (orientation)
  {
    case UIInterfaceOrientationPortrait:
    case UIInterfaceOrientationPortraitUpsideDown:
    case UIInterfaceOrientationUnknown:
      self.tableViewHeight.constant = defaultHeight;
      break;
    case UIInterfaceOrientationLandscapeLeft:
    case UIInterfaceOrientationLandscapeRight:
    {
      CGFloat const topOffset = 24.;
      CGFloat const navBarHeight = 64.;
      self.tableViewHeight.constant = MIN(defaultHeight, MIN(size.width, size.height) - 2 * topOffset - navBarHeight);
      break;
    }
  }
  [self.tableView setNeedsLayout];
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
  [self configureTableViewForOrientation:self.interfaceOrientation];
}

- (BOOL)shouldAutorotate
{
  return YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
  [super viewWillDisappear:animated];
  if (self.colorWasChanged && !self.iPadOwnerNavigationController)
    [self.placePageManager reloadBookmark];
}

@end

@implementation MWMBookmarkColorViewController (TableView)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  MWMBookmarkColorCell * cell = (MWMBookmarkColorCell *)[tableView dequeueReusableCellWithIdentifier:kBookmarkColorCellIdentifier];
  if (!cell)
    cell = [[MWMBookmarkColorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kBookmarkColorCellIdentifier];

  NSString * const currentColor = kBookmarkColorsVariant[indexPath.row];
  [cell configureWithColorString:kBookmarkColorsVariant[indexPath.row]];

  if ([currentColor isEqualToString:self.placePageManager.entity.bookmarkColor] && !cell.selected)
    [tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];

  return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  return kBookmarkColorsVariant.count;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  self.colorWasChanged = YES;
  self.placePageManager.entity.bookmarkColor = kBookmarkColorsVariant[indexPath.row];
  if (!self.iPadOwnerNavigationController)
    return;

  [self.placePageManager reloadBookmark];
  GetFramework().Invalidate();
}

@end