VLCPlaylistViewController.m 19.6 KB
Newer Older
Felix Paul Kühne's avatar
Felix Paul Kühne committed
1 2 3 4 5 6 7
//
//  VLCMasterViewController.m
//  AspenProject
//
//  Created by Felix Paul Kühne on 27.02.13.
//  Copyright (c) 2013 VideoLAN. All rights reserved.
//
8 9
//  Refer to the COPYING file of the official project for license.
//
Felix Paul Kühne's avatar
Felix Paul Kühne committed
10 11

#import "VLCPlaylistViewController.h"
12
#import "VLCMovieViewController.h"
13
#import "VLCPlaylistTableViewCell.h"
14
#import "VLCPlaylistGridView.h"
Romain Goyet's avatar
Romain Goyet committed
15
#import "UINavigationController+Theme.h"
16
#import "NSString+SupportedMedia.h"
17
#import "VLCBugreporter.h"
18
#import "VLCAppDelegate.h"
19
#import "UIBarButtonItem+Theme.h"
20
#import "AQGridView.h"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
21

22 23 24 25 26

#ifndef UIStatusBarStyleLightContent
#define UIStatusBarStyleLightContent 1
#endif

27 28 29
@implementation EmptyLibraryView
@end

30
@interface VLCPlaylistViewController () <AQGridViewDataSource, AQGridViewDelegate, UITableViewDataSource, UITableViewDelegate, MLMediaLibrary> {
Felix Paul Kühne's avatar
Felix Paul Kühne committed
31
    NSMutableArray *_foundMedia;
32
    VLCLibraryMode _libraryMode;
33
    UIBarButtonItem *_menuButton;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
34 35 36 37 38
}
@end

@implementation VLCPlaylistViewController

39 40 41
- (void)loadView {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
42
        _tableView.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
43 44 45 46 47 48 49
        _tableView.delegate = self;
        _tableView.dataSource = self;
        self.view = _tableView;
    } else {
        _gridView = [[AQGridView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        _gridView.delegate = self;
        _gridView.dataSource = self;
50
        _gridView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"libraryBackground"]];
51 52 53
        self.view = _gridView;
    }

54
    _libraryMode = VLCLibraryModeAllFiles;
55

56 57 58 59 60 61
    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    self.emptyLibraryView = [[[NSBundle mainBundle] loadNibNamed:@"VLCEmptyLibraryView" owner:self options:nil] lastObject];
}

#pragma mark -

Felix Paul Kühne's avatar
Felix Paul Kühne committed
62 63 64 65
- (void)viewDidLoad
{
    [super viewDidLoad];

66
    _menuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(leftButtonAction:)];
67 68 69 70 71 72 73 74 75 76

    /* After day 354 of the year, the usual VLC cone is replaced by another cone
     * wearing a Father Xmas hat.
     * Note: this icon doesn't represent an endorsement of The Coca-Cola Company
     * and should not be confused with the idea of religious statements or propagation there off
     */
    NSCalendar *gregorian =
    [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
    if (dayOfYear >= 354)
77
        _menuButton.image = [UIImage imageNamed:@"vlc-xmas"];
78

79
    self.navigationItem.leftBarButtonItem = _menuButton;
80

81 82 83 84 85 86 87 88
    if (SYSTEM_RUNS_IN_THE_FUTURE)
        self.editButtonItem.tintColor = [UIColor whiteColor];
    else {
        [self.editButtonItem setBackgroundImage:[UIImage imageNamed:@"button"]
                                       forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        [self.editButtonItem setBackgroundImage:[UIImage imageNamed:@"buttonHighlight"]
                                       forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
    }
Felix Paul Kühne's avatar
Felix Paul Kühne committed
89

90
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
91 92 93
        _gridView.separatorStyle = AQGridViewCellSeparatorStyleEmptySpace;
        _gridView.alwaysBounceVertical = YES;
        _gridView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
94 95
    } else {
        _tableView.rowHeight = [VLCPlaylistTableViewCell heightOfCell];
96
        _tableView.separatorColor = [UIColor colorWithWhite:.122 alpha:1.];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
97
    }
Felix Paul Kühne's avatar
Felix Paul Kühne committed
98
    self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
99

100 101 102 103 104
    _emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", @"");
    _emptyLibraryView.emptyLibraryLongDescriptionLabel.lineBreakMode = UILineBreakModeWordWrap;
    _emptyLibraryView.emptyLibraryLongDescriptionLabel.numberOfLines = 0;
    _emptyLibraryView.emptyLibraryLongDescriptionLabel.text = NSLocalizedString(@"EMPTY_LIBRARY_LONG", @"");
    [_emptyLibraryView.emptyLibraryLongDescriptionLabel sizeToFit];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
105 106
}

107 108 109
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
110
    [self _displayEmptyLibraryViewIfNeeded];
111 112
}

113 114
- (void)viewDidAppear:(BOOL)animated
{
115 116
    [super viewDidAppear:animated];

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
    if ([[MLMediaLibrary sharedMediaLibrary] libraryNeedsUpgrade]) {
        self.navigationItem.rightBarButtonItem = nil;
        self.navigationItem.leftBarButtonItem = nil;
        self.emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"UPGRADING_LIBRARY", @"");
        self.emptyLibraryView.emptyLibraryLongDescriptionLabel.hidden = YES;
        [self.emptyLibraryView.activityIndicator startAnimating];
        self.emptyLibraryView.frame = self.view.frame;
        self.title = @"";
        [self.view addSubview:self.emptyLibraryView];

        [[MLMediaLibrary sharedMediaLibrary] setDelegate: self];
        [[MLMediaLibrary sharedMediaLibrary] performSelectorInBackground:@selector(upgradeLibrary) withObject:nil];
        return;
    }

132
    if (_foundMedia.count < 1)
133
        [self updateViewContents];
134
    [[MLMediaLibrary sharedMediaLibrary] performSelector:@selector(libraryDidAppear) withObject:nil afterDelay:1.];
135 136 137

    if (SYSTEM_RUNS_IN_THE_FUTURE)
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
138 139 140 141 142 143 144 145
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [[MLMediaLibrary sharedMediaLibrary] libraryDidDisappear];
}

146 147 148 149 150 151 152 153 154 155 156
- (BOOL)canBecomeFirstResponder
{
    return YES;
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    if (motion == UIEventSubtypeMotionShake)
        [[VLCBugreporter sharedInstance] handleBugreportRequest];
}

157 158
- (void)removeMediaObject:(MLFile *)mediaObject
{
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *folderLocation = [[[NSURL URLWithString:mediaObject.url] path] stringByDeletingLastPathComponent];
    NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
    NSString *fileName = [[[[NSURL URLWithString:mediaObject.url] path] lastPathComponent] stringByDeletingPathExtension];
    NSIndexSet *indexSet = [allfiles indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
       return ([obj rangeOfString:fileName].location != NSNotFound);
    }];
    unsigned int count = indexSet.count;
    NSString *additionalFilePath;
    NSUInteger currentIndex = [indexSet firstIndex];
    for (unsigned int x = 0; x < count; x++) {
        additionalFilePath = allfiles[currentIndex];
        if ([additionalFilePath isSupportedSubtitleFormat])
            [fileManager removeItemAtPath:[folderLocation stringByAppendingPathComponent:additionalFilePath] error:nil];
        currentIndex = [indexSet indexGreaterThanIndex:currentIndex];
    }
    [fileManager removeItemAtPath:[[NSURL URLWithString:mediaObject.url] path] error:nil];
176
    [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
177
    [self updateViewContents];
178 179 180 181
}

- (void)_displayEmptyLibraryViewIfNeeded
{
182 183 184 185
    if (self.emptyLibraryView.superview)
        [self.emptyLibraryView removeFromSuperview];

    if (_foundMedia.count <= 0) {
186
        self.emptyLibraryView.frame = self.view.frame;
187 188
        [self.view addSubview:self.emptyLibraryView];
    }
189
    if (_libraryMode == VLCLibraryModeAllFiles && _foundMedia.count > 0)
190 191 192
        self.navigationItem.rightBarButtonItem = self.editButtonItem;
    else
        self.navigationItem.rightBarButtonItem = nil;
193 194 195 196 197

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        _tableView.separatorStyle = (_foundMedia.count > 0)? UITableViewCellSeparatorStyleSingleLine:
                                                             UITableViewCellSeparatorStyleNone;
    }
198 199
}

200 201 202 203 204 205 206 207 208
- (void)libraryUpgradeComplete
{
    self.emptyLibraryView.emptyLibraryLongDescriptionLabel.hidden = NO;
    self.emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", @"");
    [self.emptyLibraryView.activityIndicator stopAnimating];
    self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
    self.navigationItem.leftBarButtonItem = _menuButton;
    [self.emptyLibraryView removeFromSuperview];

209 210 211 212 213 214 215
    [self updateViewContents];
}

- (void)libraryWasUpdated
{
    NSLog(@"libraryWasUpdated");
    [self updateViewContents];
216 217
}

218
- (void)updateViewContents
Felix Paul Kühne's avatar
Felix Paul Kühne committed
219
{
220
    if (_libraryMode == VLCLibraryModeAllAlbums) {
221 222 223 224 225 226 227 228 229 230 231
        NSArray *rawAlbums = [MLAlbum allAlbums];
        _foundMedia = [[NSMutableArray alloc] init];
        NSUInteger count = rawAlbums.count;
        MLAlbum *album;

        for (NSUInteger x = 0; x < count; x++) {
            album = rawAlbums[x];
            if (album.name.length > 0 && album.tracks.count > 0)
                [_foundMedia addObject:album];
        }
        rawAlbums = nil;
232
    } else if (_libraryMode == VLCLibraryModeAllSeries) {
233 234 235 236 237 238 239 240 241 242 243
        NSArray *rawShows = [MLShow allShows];
        _foundMedia = [[NSMutableArray alloc] init];
        NSUInteger count = rawShows.count;
        MLShow *show;

        for (NSUInteger x = 0; x < count; x++) {
            show = rawShows[x];
            if (show.name.length > 0 && show.episodes.count > 0)
                [_foundMedia addObject:show];
        }
        rawShows = nil;
244 245 246
    } else
        _foundMedia = [NSMutableArray arrayWithArray:[MLFile allFiles]];

247
    [self reloadViews];
248
}
249

250
- (void)reloadViews
251
{
252
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
253
        [self.tableView reloadData];
254
    else {
255
        [self.gridView reloadData];
256
        [self.gridView performSelector:@selector(reloadData) withObject:nil afterDelay:2.];
257
    }
258 259

    [self _displayEmptyLibraryViewIfNeeded];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
260 261
}

262 263
#pragma mark - Table View

Felix Paul Kühne's avatar
Felix Paul Kühne committed
264 265 266 267 268 269 270 271 272 273 274 275 276
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _foundMedia.count;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
277
    static NSString *CellIdentifier = @"PlaylistCell";
Felix Paul Kühne's avatar
Felix Paul Kühne committed
278

279
    VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
280
    if (cell == nil)
281
        cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
282

283 284
    NSInteger row = indexPath.row;
    cell.mediaObject = _foundMedia[row];
285

Felix Paul Kühne's avatar
Felix Paul Kühne committed
286 287 288
    return cell;
}

289 290 291 292 293
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor colorWithWhite:.122 alpha:1.];
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
294 295 296 297 298 299 300
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
301 302
    if (editingStyle == UITableViewCellEditingStyleDelete)
        [self removeMediaObject: _foundMedia[indexPath.row]];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
303 304
}

305
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Felix Paul Kühne's avatar
Felix Paul Kühne committed
306
{
307 308
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

309 310 311
    NSManagedObject *currentObject = _foundMedia[indexPath.row];
    if ([currentObject isKindOfClass:[MLAlbum class]]) {
        _foundMedia = [NSMutableArray arrayWithArray:[[(MLAlbum *)currentObject tracks] allObjects]];
312 313 314
        self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
        [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_MUSIC", @"")];
        self.title = [(MLAlbum*)currentObject name];
315
        [self reloadViews];
316 317
    } else if ([currentObject isKindOfClass:[MLShow class]]) {
        _foundMedia = [NSMutableArray arrayWithArray:[[(MLShow *)currentObject episodes] allObjects]];
318 319 320
        self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
        [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_SERIES", @"")];
        self.title = [(MLShow*)currentObject name];
321
        [self reloadViews];
322 323 324
    } else {
        if (!self.movieViewController)
            self.movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
325

326 327
        if ([currentObject isKindOfClass:[MLFile class]])
            self.movieViewController.mediaItem = (MLFile *)currentObject;
328
        else if ([currentObject isKindOfClass:[MLAlbumTrack class]])
329
            self.movieViewController.mediaItem = [(MLAlbumTrack*)currentObject files].anyObject;
330 331
        else if ([currentObject isKindOfClass:[MLShowEpisode class]])
            self.movieViewController.mediaItem = [(MLShowEpisode*)currentObject files].anyObject;
332 333 334

        [self.navigationController pushViewController:self.movieViewController animated:YES];
    }
Felix Paul Kühne's avatar
Felix Paul Kühne committed
335 336
}

337 338
#pragma mark - AQGridView
- (NSUInteger)numberOfItemsInGridView:(AQGridView *)gridView
Felix Paul Kühne's avatar
Felix Paul Kühne committed
339
{
340
    return _foundMedia.count;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
341 342
}

343
- (AQGridViewCell *)gridView:(AQGridView *)gridView cellForItemAtIndex:(NSUInteger)index
Felix Paul Kühne's avatar
Felix Paul Kühne committed
344
{
345
    static NSString *AQCellIdentifier = @"AQPlaylistCell";
346

347
    VLCPlaylistGridView *cell = (VLCPlaylistGridView *)[gridView dequeueReusableCellWithIdentifier:AQCellIdentifier];
348
    if (cell == nil) {
349
        cell = [[[NSBundle mainBundle] loadNibNamed:@"VLCPlaylistGridView" owner:self options:nil] lastObject];
350
        cell.selectionStyle = AQGridViewCellSelectionStyleNone;
351
        cell.gridView = gridView;
352 353
    }

354
    cell.mediaObject = _foundMedia[index];
355 356 357 358 359 360

    return cell;
}

- (CGSize)portraitGridCellSizeForGridView:(AQGridView *)gridView
{
361
    return [VLCPlaylistGridView preferredSize];
362 363 364 365
}

- (void)gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index
{
366 367
    [self.gridView deselectItemAtIndex:index animated:YES];

368 369 370 371 372 373
    NSManagedObject *currentObject = _foundMedia[index];
    if ([currentObject isKindOfClass:[MLAlbum class]]) {
        _foundMedia = [NSMutableArray arrayWithArray:[[(MLAlbum *)currentObject tracks] allObjects]];
        self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
        [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_MUSIC", @"")];
        self.title = [(MLAlbum*)currentObject name];
374
        [self reloadViews];
375 376 377 378 379
    } else if ([currentObject isKindOfClass:[MLShow class]]) {
        _foundMedia = [NSMutableArray arrayWithArray:[[(MLShow *)currentObject episodes] allObjects]];
        self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
        [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_SERIES", @"")];
        self.title = [(MLShow*)currentObject name];
380
        [self reloadViews];
381 382 383 384 385 386 387 388 389 390
    } else {
        if (!self.movieViewController)
            self.movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];

        if ([currentObject isKindOfClass:[MLFile class]])
            self.movieViewController.mediaItem = (MLFile *)currentObject;
        else if ([currentObject isKindOfClass:[MLAlbumTrack class]])
            self.movieViewController.mediaItem = [(MLAlbumTrack*)currentObject files].anyObject;
        else if ([currentObject isKindOfClass:[MLShowEpisode class]])
            self.movieViewController.mediaItem = [(MLShowEpisode*)currentObject files].anyObject;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
391

392 393
        [self.navigationController pushViewController:self.movieViewController animated:YES];
    }
Felix Paul Kühne's avatar
Felix Paul Kühne committed
394 395
}

396 397 398 399 400 401
- (void)gridView:(AQGridView *)aGridView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndex:(NSUInteger)index
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
        [self removeMediaObject: _foundMedia[index]];
}

402
#pragma mark - UI implementation
403 404
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
405
    if (_libraryMode != VLCLibraryModeAllFiles)
406 407
        return;

408
    [super setEditing:editing animated:animated];
409

Felix Paul Kühne's avatar
Felix Paul Kühne committed
410
    UIBarButtonItem *editButton = self.editButtonItem;
411 412
    NSString *editImage = editing? @"doneButton": @"button";
    NSString *editImageHighlight = editing? @"doneButtonHighlight": @"buttonHighlight";
413 414 415 416 417 418 419 420 421
    if (SYSTEM_RUNS_IN_THE_FUTURE)
        editButton.tintColor = [UIColor whiteColor];
    else {
        [editButton setBackgroundImage:[UIImage imageNamed:editImage] forState:UIControlStateNormal
                                     barMetrics:UIBarMetricsDefault];
        [editButton setBackgroundImage:[UIImage imageNamed:editImageHighlight]
                                       forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
        [editButton setTitleTextAttributes: editing ? @{UITextAttributeTextShadowColor : [UIColor whiteColor], UITextAttributeTextColor : [UIColor blackColor]} : @{UITextAttributeTextShadowColor : [UIColor colorWithWhite:0. alpha:.37], UITextAttributeTextColor : [UIColor whiteColor]} forState:UIControlStateNormal];
    }
Felix Paul Kühne's avatar
Felix Paul Kühne committed
422

423
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
424
        [self.gridView setEditing:editing];
425
    else
426
        [self.tableView setEditing:editing animated:YES];
427 428
}

429 430
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
431
    if (_libraryMode != VLCLibraryModeAllFiles)
432 433 434 435 436
        return UITableViewCellEditingStyleNone;

    return UITableViewCellEditingStyleDelete;
}

437
- (IBAction)leftButtonAction:(id)sender
438
{
439
    [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
440 441
}

442 443 444 445 446 447
- (IBAction)backToAllItems:(id)sender
{
    self.navigationItem.leftBarButtonItem = _menuButton;
    [self setLibraryMode:_libraryMode];
}

448
/* deprecated in iOS 6 */
449 450
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
451 452 453 454
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return YES;

    return (_foundMedia.count > 0) || toInterfaceOrientation == UIInterfaceOrientationPortrait;
455 456
}

457 458
// RootController is responsible for supporting interface orientation(iOS6.0+), i.e. navigation controller
// so this will not work as intended without "voodoo magic"(UINavigationController category, subclassing, etc)
459 460
/* introduced in iOS 6 */
- (NSUInteger)supportedInterfaceOrientations {
461 462 463 464 465
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return UIInterfaceOrientationMaskAll;

    return (_foundMedia.count > 0)? UIInterfaceOrientationMaskAllButUpsideDown:
                                    UIInterfaceOrientationMaskPortrait;
466 467 468 469
}

/* introduced in iOS 6 */
- (BOOL)shouldAutorotate {
470
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (_foundMedia.count > 0);
471 472
}

473
#pragma mark - coin coin
474

475 476 477
- (void)openMovieFromURL:(NSURL *)url
{
    if (!self.movieViewController)
478
        self.movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
479

480 481 482
    if (self.navigationController.topViewController != self.movieViewController)
        [self.navigationController pushViewController:self.movieViewController animated:YES];

483
    self.movieViewController.url = url;
484 485
}

486
- (void)setLibraryMode:(VLCLibraryMode)mode
487 488
{
    _libraryMode = mode;
489

490
    if (_libraryMode == VLCLibraryModeAllAlbums)
491
        self.title = NSLocalizedString(@"LIBRARY_MUSIC", @"");
492
    else if( _libraryMode == VLCLibraryModeAllSeries)
493 494 495 496
        self.title = NSLocalizedString(@"LIBRARY_SERIES", @"");
    else
        self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");

497
    [self updateViewContents];
498 499
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
500
@end