VLCSidebarController.m 2.18 KB
Newer Older
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
//
//  VLCSidebarController.m
//  VLC for iOS
//
//  Created by Felix Paul Kühne on 15/06/15.
//  Copyright © 2015 VideoLAN. All rights reserved.
//

#import "VLCSidebarController.h"
#import "GHRevealViewController.h"
#import "VLCMenuTableViewController.h"

@interface VLCSidebarController()
{
    GHRevealViewController *_revealController;
    VLCMenuTableViewController *_menuViewController;
    UIViewController *_contentViewController;
}

@end

@implementation VLCSidebarController

+ (instancetype)sharedInstance
{
    static VLCSidebarController *sharedInstance = nil;
    static dispatch_once_t pred;

    dispatch_once(&pred, ^{
30
        sharedInstance = [VLCSidebarController new];
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
    });

    return sharedInstance;
}

- (instancetype)init
{
    self = [super init];

    if (!self)
        return self;

    _revealController = [[GHRevealViewController alloc] initWithNibName:nil bundle:nil];
    _revealController.extendedLayoutIncludesOpaqueBars = YES;
    _revealController.edgesForExtendedLayout = UIRectEdgeAll;

    _menuViewController = [[VLCMenuTableViewController alloc] initWithNibName:nil bundle:nil];
    _revealController.sidebarViewController = _menuViewController;

    return self;
}

#pragma mark - VC handling

- (UIViewController *)fullViewController
{
    return _revealController;
}

- (void)setContentViewController:(UIViewController *)contentViewController
{
    contentViewController.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
    _revealController.contentViewController = contentViewController;
}

- (UIViewController *)contentViewController
{
    return _revealController.contentViewController;
}

#pragma mark - actual work

- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath scrollPosition:(UITableViewScrollPosition)scrollPosition
{
    [_menuViewController selectRowAtIndexPath:indexPath
                                     animated:NO
                               scrollPosition:scrollPosition];
}

- (void)hideSidebar
{
    [_revealController toggleSidebar:NO duration:kGHRevealSidebarDefaultAnimationDuration];
}

- (void)toggleSidebar
{
    [_revealController toggleSidebar:!_revealController.sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
}

@end