#import "SelectSetVC.h" #import "AddSetVC.h" #import "MWMPlacePageViewManager.h" #import "MWMPlacePageEntity.h" #import "UIViewController+Navigation.h" #include "Framework.h" @interface SelectSetVC () @property (weak, nonatomic) MWMPlacePageViewManager * manager; @end @implementation SelectSetVC - (instancetype)initWithPlacePageManager:(MWMPlacePageViewManager *)manager { self = [super initWithStyle:UITableViewStyleGrouped]; if (self) { self.manager = manager; self.title = L(@"bookmark_sets"); } return self; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (!self.iPadOwnerNavigationController) return; [self.iPadOwnerNavigationController setNavigationBarHidden:NO]; [(UIViewController *)self showBackButton]; CGFloat const bottomOffset = 88.; self.iPadOwnerNavigationController.view.height = self.tableView.height + bottomOffset; } - (void)popViewController { if (self.iPadOwnerNavigationController) [self.iPadOwnerNavigationController setNavigationBarHidden:YES]; [self.navigationController popViewControllerAnimated:YES]; } - (void)backTap { [self popViewController]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (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 { static NSString * kSetCellId = @"AddSetCell"; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:kSetCellId]; if (cell == nil) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kSetCellId]; // Customize cell 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()); BookmarkAndCategory const bac = self.manager.entity.bac; if (bac.first == 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.manager reloadBookmark]; } - (void)moveBookmarkToSetWithIndex:(int)setIndex { MWMPlacePageEntity * entity = self.manager.entity; BookmarkAndCategory bac; bac.second = static_cast(GetFramework().MoveBookmark(entity.bac.second, entity.bac.first, setIndex)); bac.first = setIndex; entity.bac = bac; BookmarkCategory const * category = GetFramework().GetBookmarkManager().GetBmCategory(bac.first); entity.bookmarkCategory = @(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; if (IPAD) asVC.preferredContentSize = self.preferredContentSize; [self.navigationController pushViewController:asVC animated:YES]; } else { [self moveBookmarkToSetWithIndex:static_cast(indexPath.row)]; [self.manager reloadBookmark]; [self popViewController]; } } @end