OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/showcase/tab_grid/sc_tab_grid_coordinator.h" |
| 6 |
| 7 #import "base/format_macros.h" |
| 8 #import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h" |
| 9 |
| 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 11 #error "This file requires ARC support." |
| 12 #endif |
| 13 |
| 14 @interface SCTabGridCoordinator ()<TabGridDataSource, TabGridActionDelegate> |
| 15 @property(nonatomic, strong) TabGridViewController* viewController; |
| 16 @end |
| 17 |
| 18 @implementation SCTabGridCoordinator |
| 19 @synthesize baseViewController = _baseViewController; |
| 20 @synthesize viewController = _viewController; |
| 21 |
| 22 - (void)start { |
| 23 self.viewController = [[TabGridViewController alloc] init]; |
| 24 self.viewController.title = @"Tab Grid"; |
| 25 self.viewController.dataSource = self; |
| 26 self.viewController.actionDelegate = self; |
| 27 [self.baseViewController setHidesBarsOnSwipe:YES]; |
| 28 [self.baseViewController pushViewController:self.viewController animated:YES]; |
| 29 } |
| 30 |
| 31 #pragma mark - TabGridDataSource |
| 32 |
| 33 - (NSUInteger)numberOfTabsInTabGrid { |
| 34 return 3; |
| 35 } |
| 36 |
| 37 - (NSString*)titleAtIndex:(NSInteger)index { |
| 38 return [NSString stringWithFormat:@"Tab %" PRIdNS, index]; |
| 39 } |
| 40 |
| 41 #pragma mark - TabGridActionDelegate |
| 42 |
| 43 - (void)showTabAtIndexPath:(NSIndexPath*)indexPath { |
| 44 [self |
| 45 showAlertWithTitle:NSStringFromProtocol(@protocol(TabGridActionDelegate)) |
| 46 message:[NSString |
| 47 stringWithFormat:@"showTabAtIndexPath:%" PRIdNS, |
| 48 indexPath.item]]; |
| 49 } |
| 50 |
| 51 - (void)showTabGrid { |
| 52 [self |
| 53 showAlertWithTitle:NSStringFromProtocol(@protocol(TabGridActionDelegate)) |
| 54 message:NSStringFromSelector(_cmd)]; |
| 55 } |
| 56 |
| 57 - (void)showSettings { |
| 58 [self |
| 59 showAlertWithTitle:NSStringFromProtocol(@protocol(TabGridActionDelegate)) |
| 60 message:NSStringFromSelector(_cmd)]; |
| 61 } |
| 62 |
| 63 #pragma mark - Private |
| 64 |
| 65 // Helper to show simple alert. |
| 66 - (void)showAlertWithTitle:(NSString*)title message:(NSString*)message { |
| 67 UIAlertController* alertController = |
| 68 [UIAlertController alertControllerWithTitle:title |
| 69 message:message |
| 70 preferredStyle:UIAlertControllerStyleAlert]; |
| 71 UIAlertAction* action = |
| 72 [UIAlertAction actionWithTitle:@"Done" |
| 73 style:UIAlertActionStyleCancel |
| 74 handler:nil]; |
| 75 [alertController addAction:action]; |
| 76 [self.baseViewController presentViewController:alertController |
| 77 animated:YES |
| 78 completion:nil]; |
| 79 } |
| 80 |
| 81 @end |
OLD | NEW |