blob: c3952b5cb4d3d010adbd8341c1c99799b1c82bec (
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
|
#import "AddSetVC.h"
#import "SelectSetVC.h"
#import "UIViewController+Navigation.h"
#include "Framework.h"
@interface SelectSetVC () <AddSetVCDelegate>
{
BookmarkAndCategory m_bac;
}
@property (copy, nonatomic) NSString * category;
@property (weak, nonatomic) id<MWMSelectSetDelegate> delegate;
@end
@implementation SelectSetVC
- (instancetype)initWithCategory:(NSString *)category
bac:(BookmarkAndCategory const &)bac
delegate:(id<MWMSelectSetDelegate>)delegate
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self)
{
_category = category;
m_bac = bac;
_delegate = delegate;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSAssert(self.category, @"Category can't be nil!");
NSAssert(self.delegate, @"Delegate can't be nil!");
NSAssert(m_bac.IsValid(), @"Invalid BookmarkAndCategory's instance!");
self.title = L(@"bookmark_sets");
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// "Add new set" button
if (section == 0)
return 1;
return GetFramework().GetBmCategoriesCount();
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:[UITableViewCell className]];
if (indexPath.section == 0)
{
cell.textLabel.text = L(@"add_new_set");
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else
{
BookmarkCategory * cat = GetFramework().GetBmCategory(indexPath.row);
if (cat)
cell.textLabel.text = @(cat->GetName().c_str());
if (m_bac.m_categoryIndex == indexPath.row)
cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
- (void)addSetVC:(AddSetVC *)vc didAddSetWithIndex:(int)setIndex
{
[self moveBookmarkToSetWithIndex:setIndex];
[self.tableView reloadData];
[self.delegate didSelectCategory:self.category withBac:m_bac];
}
- (void)moveBookmarkToSetWithIndex:(int)setIndex
{
BookmarkAndCategory bac;
bac.m_bookmarkIndex = static_cast<int>(GetFramework().MoveBookmark(m_bac.m_bookmarkIndex, m_bac.m_categoryIndex, setIndex));
bac.m_categoryIndex = setIndex;
m_bac = bac;
BookmarkCategory const * category = GetFramework().GetBookmarkManager().GetBmCategory(bac.m_categoryIndex);
self.category = @(category->GetName().c_str());
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section == 0)
{
AddSetVC * asVC = [[AddSetVC alloc] init];
asVC.delegate = self;
[self.navigationController pushViewController:asVC animated:YES];
}
else
{
[self moveBookmarkToSetWithIndex:static_cast<int>(indexPath.row)];
[self.delegate didSelectCategory:self.category withBac:m_bac];
[self backTap];
}
}
@end
|