VLCMenuTableViewController.m 13.2 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * VLCMenuTableViewController.m
 * VLC for iOS
 *****************************************************************************
Felix Paul Kühne's avatar
Felix Paul Kühne committed
5
 * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
6 7 8 9 10 11 12 13 14 15 16
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne # videolan.org>
 *          Gleb Pinigin <gpinigin # gmail.com>
 *          Jean-Romain Prévost <jr # 3on.fr>
 *          Carola Nitz <nitz.carola # googlemail.com>
 *          Tamas Timar <ttimar.vlc # gmail.com>
 *          Pierre Sagaspe <pierre.sagaspe # me.com>
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/
17 18

#import "VLCMenuTableViewController.h"
19
#import "VLCSidebarViewCell.h"
20 21 22 23
#import <QuartzCore/QuartzCore.h>
#import "VLCWiFiUploadTableViewCell.h"
#import "VLCAppDelegate.h"
#import "IASKAppSettingsViewController.h"
24
#import "VLCServerListViewController.h"
25 26 27
#import "VLCOpenNetworkStreamViewController.h"
#import "VLCSettingsController.h"
#import "VLCAboutViewController.h"
28
#import "VLCLibraryViewController.h"
29
#import "VLCBugreporter.h"
30
#import "VLCCloudServicesTableViewController.h"
31
#import "VLCNavigationController.h"
32
#import "GHRevealViewController.h"
33

34 35 36 37
#define ROW_HEIGHT 50
static NSString *CellIdentifier = @"VLCMenuCell";
static NSString *WiFiCellIdentifier = @"VLCMenuWiFiCell";

38 39 40 41 42 43
@interface VLCMenuTableViewController () <UITableViewDataSource, UITableViewDelegate>
{
    NSArray *_sectionHeaderTexts;
    NSArray *_menuItemsSectionOne;
    NSArray *_menuItemsSectionTwo;
    NSArray *_menuItemsSectionThree;
44
    NSMutableSet *_hiddenSettingKeys;
45
    
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
}

@end

@implementation VLCMenuTableViewController

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.frame = CGRectMake(0.0f, 0.0f, kGHRevealSidebarWidth, CGRectGetHeight(self.view.bounds));
62
    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
63

Felix Paul Kühne's avatar
Felix Paul Kühne committed
64
    _sectionHeaderTexts = @[@"SECTION_HEADER_LIBRARY", @"SECTION_HEADER_NETWORK", @"Settings"];
65
    _menuItemsSectionOne = @[@"LIBRARY_ALL_FILES", @"LIBRARY_MUSIC", @"LIBRARY_SERIES"];
66
    _menuItemsSectionTwo = @[@"LOCAL_NETWORK", @"OPEN_NETWORK", @"DOWNLOAD_FROM_HTTP", @"WEBINTF_TITLE", @"CLOUD_SERVICES"];
67

68 69
    _menuItemsSectionThree = @[@"Settings", @"ABOUT_APP"];

70 71
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, 44.0f + 20.0f, kGHRevealSidebarWidth, CGRectGetHeight(self.view.bounds) - (44.0f + 20.0f)) style:UITableViewStylePlain];
    _tableView.delegate = self;
72 73 74 75
    _tableView.dataSource = self;
    _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    _tableView.backgroundColor = [UIColor colorWithRed:(43.0f/255.0f) green:(43.0f/255.0f) blue:(43.0f/255.0f) alpha:1.0f];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
76
    _tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
77
    _tableView.rowHeight = ROW_HEIGHT;
78
    _tableView.scrollsToTop = NO;
79
    [_tableView registerClass:[VLCWiFiUploadTableViewCell class] forCellReuseIdentifier:WiFiCellIdentifier];
80

Felix Paul Kühne's avatar
Felix Paul Kühne committed
81
    self.view = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kGHRevealSidebarWidth, CGRectGetHeight(self.view.bounds))];
82
    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
83 84
    [self.view addSubview:_tableView];

Felix Paul Kühne's avatar
Felix Paul Kühne committed
85 86 87 88
    UIView *brandingBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kGHRevealSidebarWidth, 64.0f)];
    brandingBackgroundView.backgroundColor = [UIColor colorWithRed:0.1608 green:0.1608 blue:0.1608 alpha:1.0000];
    [self.view addSubview:brandingBackgroundView];

89
    UIImageView *brandingImageView;
90
    brandingImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kGHRevealSidebarWidth, 44.0f + 40.0f)];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
91 92 93 94 95
    brandingImageView.contentMode = UIViewContentModeCenter;
    brandingImageView.image = [UIImage imageNamed:@"title"];
    [self.view addSubview:brandingImageView];

    [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
96 97 98

}

99 100
- (void)viewWillAppear:(BOOL)animated
{
sanmarcos's avatar
sanmarcos committed
101
    [super viewWillAppear:animated];
102
    self.view.frame = CGRectMake(0.0f, 0.0f,kGHRevealSidebarWidth, CGRectGetHeight(self.view.bounds));
103 104
}

105 106 107
- (BOOL)shouldAutorotate
{
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
108
    return (orientation == UIInterfaceOrientationPortraitUpsideDown) ? (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) : YES;
109 110
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
111 112 113 114 115 116 117
- (BOOL)canBecomeFirstResponder
{
    return YES;
}

#pragma mark - table view data source

118 119
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
120 121 122
    return 3;
}

123 124
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
125
    if (section == 0) // media
126
        return _menuItemsSectionOne.count;
127
    else if (section == 1) // network
128
        return _menuItemsSectionTwo.count;
129
    else if (section == 2) // settings & co
130
        return _menuItemsSectionThree.count;
131 132 133 134
    else
        return 0;
}

135 136
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
137

Felix Paul Kühne's avatar
Felix Paul Kühne committed
138 139 140 141 142 143 144 145
    NSString *rawTitle;
    NSUInteger section = indexPath.section;
    if (section == 0)
        rawTitle = _menuItemsSectionOne[indexPath.row];
    else if(section == 1)
        rawTitle = _menuItemsSectionTwo[indexPath.row];
    else if(section == 2)
        rawTitle = _menuItemsSectionThree[indexPath.row];
146 147

    UITableViewCell *cell;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
148
    if ([rawTitle isEqualToString:@"WEBINTF_TITLE"]) {
149 150
        cell = (VLCWiFiUploadTableViewCell *)[tableView dequeueReusableCellWithIdentifier:WiFiCellIdentifier];
    } else {
151
        cell = (VLCSidebarViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
152
        if (cell == nil)
153
            cell = [[VLCSidebarViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
154 155
    }

Felix Paul Kühne's avatar
Felix Paul Kühne committed
156 157 158 159 160 161
    if (section == 0) {
        if ([rawTitle isEqualToString:@"LIBRARY_ALL_FILES"])
            cell.imageView.image = [UIImage imageNamed:@"AllFiles"];
        else if ([rawTitle isEqualToString:@"LIBRARY_MUSIC"])
            cell.imageView.image = [UIImage imageNamed:@"MusicAlbums"];
        else if ([rawTitle isEqualToString:@"LIBRARY_SERIES"])
162
            cell.imageView.image = [UIImage imageNamed:@"TVShowsIcon"];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
163 164 165 166 167 168 169
    } else if (section == 1) {
        if ([rawTitle isEqualToString:@"LOCAL_NETWORK"])
            cell.imageView.image = [UIImage imageNamed:@"Local"];
        else if ([rawTitle isEqualToString:@"OPEN_NETWORK"])
            cell.imageView.image = [UIImage imageNamed:@"OpenNetStream"];
        else if ([rawTitle isEqualToString:@"DOWNLOAD_FROM_HTTP"])
            cell.imageView.image = [UIImage imageNamed:@"Downloads"];
170
        else if ([rawTitle isEqualToString:@"CLOUD_SERVICES"])
Felix Paul Kühne's avatar
Felix Paul Kühne committed
171
            cell.imageView.image = [UIImage imageNamed:@"iCloudIcon"];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
172 173 174 175
    } else if (section == 2) {
        if ([rawTitle isEqualToString:@"Settings"])
            cell.imageView.image = [UIImage imageNamed:@"Settings"];
        else
Felix Paul Kühne's avatar
Felix Paul Kühne committed
176
            cell.imageView.image = [UIImage imageNamed:@"menuCone"];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
177 178
    }

179
    if (![rawTitle isEqualToString:@"WEBINTF_TITLE"])
180
        cell.textLabel.text = NSLocalizedString(rawTitle, nil);
181 182 183 184

    return cell;
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
185
#pragma mark - table view delegation
186 187
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
188 189 190 191 192
    if (section < 3)
        return 21.f;
    return 0.;
}

193 194
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
195
    NSObject *headerText = NSLocalizedString(_sectionHeaderTexts[section], nil);
196 197 198
    UIView *headerView = nil;
    if (headerText != [NSNull null]) {
        headerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.height, 21.0f)];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
199
        headerView.backgroundColor = [UIColor VLCDarkBackgroundColor];
200

201 202 203 204
        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectInset(headerView.bounds, 12.0f, 5.0f)];
        textLabel.text = (NSString *) headerText;
        textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:([UIFont systemFontSize] * 0.8f)];
        textLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
205
        textLabel.shadowColor = [UIColor VLCDarkTextShadowColor];
206 207 208 209 210 211 212 213 214 215 216 217 218
        textLabel.textColor = [UIColor colorWithRed:(118.0f/255.0f) green:(118.0f/255.0f) blue:(118.0f/255.0f) alpha:1.0f];
        textLabel.backgroundColor = [UIColor clearColor];
        [headerView addSubview:textLabel];

        UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)];
        topLine.backgroundColor = [UIColor colorWithRed:(95.0f/255.0f) green:(95.0f/255.0f) blue:(95.0f/255.0f) alpha:1.0f];
        [headerView addSubview:topLine];

        UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 21.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)];
        bottomLine.backgroundColor = [UIColor colorWithRed:(16.0f/255.0f) green:(16.0f/255.0f) blue:(16.0f/255.0f) alpha:1.0f];
        [headerView addSubview:bottomLine];
    }
    return headerView;
219 220 221 222 223 224 225
}

#pragma mark - menu implementation

- (void)_revealItem:(NSUInteger)itemIndex inSection:(NSUInteger)sectionNumber
{
    UIViewController *viewController;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
226
    VLCAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
227 228
    if (sectionNumber == 1) {
        if (itemIndex == 0)
229
            viewController = [[VLCServerListViewController alloc] init];
230
        else if (itemIndex == 1) {
Felix Paul Kühne's avatar
Felix Paul Kühne committed
231
            viewController = [[VLCOpenNetworkStreamViewController alloc] initWithNibName:@"VLCOpenNetworkStreamViewController" bundle:nil];
232
        } else if (itemIndex == 2)
233
            viewController = [VLCDownloadViewController sharedInstance];
234
        else if (itemIndex == 3)
235
            [((VLCWiFiUploadTableViewCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:itemIndex inSection:sectionNumber]]) toggleHTTPServer];
236
        else if (itemIndex == 4)
237
            viewController = [[VLCCloudServicesTableViewController alloc] initWithNibName:@"VLCCloudServicesTableViewController" bundle:nil];
238 239 240 241
    } else if (sectionNumber == 2) {
        if (itemIndex == 0) {
            if (!self.settingsController)
                self.settingsController = [[VLCSettingsController alloc] init];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
242
            VLCSettingsController *settingsController = self.settingsController;
243 244 245

            if (!self.settingsViewController) {
                self.settingsViewController = [[IASKAppSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
246
                settingsController.viewController = self.settingsViewController;
247
                self.settingsViewController.navigationItem.leftBarButtonItem = [UIBarButtonItem themedRevealMenuButtonWithTarget:self.settingsController.viewController andSelector:@selector(dismiss:)];
248 249
            }

250
            _hiddenSettingKeys = [[NSMutableSet alloc] init];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
251 252 253 254 255
            IASKAppSettingsViewController *settingsVC = self.settingsViewController;
            settingsVC.modalPresentationStyle = UIModalPresentationFormSheet;
            settingsVC.delegate = self.settingsController;
            settingsVC.showDoneButton = NO;
            settingsVC.showCreditsFooter = NO;
256

257 258 259 260
            if (![[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingPlaybackGestures] boolValue])
                [_hiddenSettingKeys addObject:@"EnableVariableJumpDuration"];

            [self.settingsController.viewController setHiddenKeys:_hiddenSettingKeys];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
261
            viewController = settingsVC;
262 263
        } else if (itemIndex == 1)
            viewController = [[VLCAboutViewController alloc] init];
264
    } else {
265 266
        viewController = appDelegate.libraryViewController;
        [(VLCLibraryViewController *)viewController setLibraryMode:(int)itemIndex];
267
    }
268 269 270 271

    if (!viewController)
        return;

272 273 274
    VLCSidebarController *sidebarController = [VLCSidebarController sharedInstance];
    if ([sidebarController.contentViewController isKindOfClass:[UINavigationController class]]) {
        UINavigationController *navCon = (UINavigationController*)sidebarController.contentViewController;
275
        navCon.viewControllers = @[viewController];
276
    } else
277 278
        sidebarController.contentViewController = [[VLCNavigationController alloc] initWithRootViewController:viewController];
    [sidebarController hideSidebar];
279 280
}

281 282 283
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self _revealItem:indexPath.row inSection:indexPath.section];
284 285 286
}

#pragma mark Public Methods
287 288
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
289 290
    UITableView *tableView = self.tableView;
    [tableView selectRowAtIndexPath:indexPath animated:animated scrollPosition:scrollPosition];
291
    if (scrollPosition == UITableViewScrollPositionNone)
Felix Paul Kühne's avatar
Felix Paul Kühne committed
292
        [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:scrollPosition animated:animated];
293 294 295
    [self _revealItem:indexPath.row inSection:indexPath.section];
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
296
#pragma mark - shake for support
297 298
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
299 300 301 302 303
    if (motion == UIEventSubtypeMotionShake)
        [[VLCBugreporter sharedInstance] handleBugreportRequest];
}

@end