VLCPlaylistViewController.m 20.1 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 "VLCPlaylistCollectionViewCell.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 21 22 23 24

#ifndef UIStatusBarStyleLightContent
#define UIStatusBarStyleLightContent 1
#endif

25 26 27
@implementation EmptyLibraryView
@end

Felix Paul Kühne's avatar
Felix Paul Kühne committed
28
@interface VLCPlaylistViewController () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UITableViewDataSource, UITableViewDelegate, MLMediaLibrary> {
Felix Paul Kühne's avatar
Felix Paul Kühne committed
29
    NSMutableArray *_foundMedia;
30
    VLCLibraryMode _libraryMode;
31
    UIBarButtonItem *_menuButton;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
32
}
33 34

@property (nonatomic, strong) UITableView *tableView;
35
@property (nonatomic, strong) UICollectionView *collectionView;
36 37
@property (nonatomic, strong) EmptyLibraryView *emptyLibraryView;

Felix Paul Kühne's avatar
Felix Paul Kühne committed
38 39 40 41
@end

@implementation VLCPlaylistViewController

42 43 44
- (void)loadView {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
45
        _tableView.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
46 47
        _tableView.rowHeight = [VLCPlaylistTableViewCell heightOfCell];
        _tableView.separatorColor = [UIColor colorWithWhite:.122 alpha:1.];
48 49 50
        _tableView.delegate = self;
        _tableView.dataSource = self;
        self.view = _tableView;
51

Felix Paul Kühne's avatar
Felix Paul Kühne committed
52
        if (SYSTEM_RUNS_IOS7_OR_LATER) {
53 54 55
            UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tableViewLongTouchGestureAction:)];
            [self.view addGestureRecognizer:gestureRecognizer];
        }
56
    } else {
Felix Paul Kühne's avatar
Felix Paul Kühne committed
57 58 59 60 61 62 63 64 65
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];

        _collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:flowLayout];
        _collectionView.alwaysBounceVertical = YES;
        _collectionView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        self.view = _collectionView;

Felix Paul Kühne's avatar
Felix Paul Kühne committed
66
        if (SYSTEM_RUNS_IOS7_OR_LATER)
67 68 69 70
            [_collectionView registerNib:[UINib nibWithNibName:@"VLCFuturePlaylistCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"PlaylistCell"];
        else
            [_collectionView registerNib:[UINib nibWithNibName:@"VLCPlaylistCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"PlaylistCell"];

71 72

        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"libraryBackground"]];
73 74
    }

75
    _libraryMode = VLCLibraryModeAllFiles;
76

77 78
    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    self.emptyLibraryView = [[[NSBundle mainBundle] loadNibNamed:@"VLCEmptyLibraryView" owner:self options:nil] lastObject];
79
    _emptyLibraryView.emptyLibraryLongDescriptionLabel.lineBreakMode = NSLineBreakByWordWrapping;
80
    _emptyLibraryView.emptyLibraryLongDescriptionLabel.numberOfLines = 0;
81 82 83 84
}

#pragma mark -

Felix Paul Kühne's avatar
Felix Paul Kühne committed
85 86 87
- (void)viewDidLoad
{
    [super viewDidLoad];
88
    self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
89
    _menuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(leftButtonAction:)];
90 91 92 93 94 95 96 97 98 99

    /* 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)
100
        _menuButton.image = [UIImage imageNamed:@"vlc-xmas"];
101

102
    self.navigationItem.leftBarButtonItem = _menuButton;
103

Felix Paul Kühne's avatar
Felix Paul Kühne committed
104
    if (SYSTEM_RUNS_IOS7_OR_LATER)
105 106 107 108 109 110 111
        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
112

113 114 115
    _emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", @"");
    _emptyLibraryView.emptyLibraryLongDescriptionLabel.text = NSLocalizedString(@"EMPTY_LIBRARY_LONG", @"");
    [_emptyLibraryView.emptyLibraryLongDescriptionLabel sizeToFit];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
116 117
}

118 119 120
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
121
    [self _displayEmptyLibraryViewIfNeeded];
122 123
}

124 125
- (void)viewDidAppear:(BOOL)animated
{
126 127
    [super viewDidAppear:animated];

128 129 130
    if ([[MLMediaLibrary sharedMediaLibrary] libraryNeedsUpgrade]) {
        self.navigationItem.rightBarButtonItem = nil;
        self.navigationItem.leftBarButtonItem = nil;
Gleb Pinigin's avatar
Gleb Pinigin committed
131
        self.title = @"";
132 133 134
        self.emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"UPGRADING_LIBRARY", @"");
        self.emptyLibraryView.emptyLibraryLongDescriptionLabel.hidden = YES;
        [self.emptyLibraryView.activityIndicator startAnimating];
Gleb Pinigin's avatar
Gleb Pinigin committed
135
        self.emptyLibraryView.frame = self.view.bounds;
136 137 138 139 140 141 142
        [self.view addSubview:self.emptyLibraryView];

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

143
    if (_foundMedia.count < 1)
144
        [self updateViewContents];
145
    [[MLMediaLibrary sharedMediaLibrary] performSelector:@selector(libraryDidAppear) withObject:nil afterDelay:1.];
146

Felix Paul Kühne's avatar
Felix Paul Kühne committed
147
    if (SYSTEM_RUNS_IOS7_OR_LATER)
148
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
149 150 151 152 153 154 155 156
}

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

157 158 159 160 161 162 163 164 165 166 167
- (BOOL)canBecomeFirstResponder
{
    return YES;
}

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

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
- (void)openMediaObject:(NSManagedObject *)mediaObject
{
    if ([mediaObject isKindOfClass:[MLAlbum class]]) {
        _foundMedia = [NSMutableArray arrayWithArray:[[(MLAlbum *)mediaObject tracks] allObjects]];
        self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
        [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_MUSIC", @"")];
        self.title = [(MLAlbum*)mediaObject name];
        [self reloadViews];
    } else if ([mediaObject isKindOfClass:[MLShow class]]) {
        _foundMedia = [NSMutableArray arrayWithArray:[[(MLShow *)mediaObject episodes] allObjects]];
        self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
        [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_SERIES", @"")];
        self.title = [(MLShow*)mediaObject name];
        [self reloadViews];
    } else {
        if (!self.movieViewController)
            self.movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];

        if ([mediaObject isKindOfClass:[MLFile class]])
            self.movieViewController.mediaItem = (MLFile *)mediaObject;
        else if ([mediaObject isKindOfClass:[MLAlbumTrack class]])
            self.movieViewController.mediaItem = [(MLAlbumTrack*)mediaObject files].anyObject;
        else if ([mediaObject isKindOfClass:[MLShowEpisode class]])
            self.movieViewController.mediaItem = [(MLShowEpisode*)mediaObject files].anyObject;

        [self.navigationController pushViewController:self.movieViewController animated:YES];
    }
}

197 198
- (void)removeMediaObject:(MLFile *)mediaObject
{
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
    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];
216
    [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
217
    [self updateViewContents];
218 219 220 221
}

- (void)_displayEmptyLibraryViewIfNeeded
{
222 223 224
    if (self.emptyLibraryView.superview)
        [self.emptyLibraryView removeFromSuperview];

Gleb Pinigin's avatar
Gleb Pinigin committed
225 226
    if (_foundMedia.count == 0) {
        self.emptyLibraryView.frame = self.view.bounds;
227 228
        [self.view addSubview:self.emptyLibraryView];
    }
229
    if (_libraryMode == VLCLibraryModeAllFiles && _foundMedia.count > 0)
230 231 232
        self.navigationItem.rightBarButtonItem = self.editButtonItem;
    else
        self.navigationItem.rightBarButtonItem = nil;
233 234 235 236 237

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

240 241
- (void)libraryUpgradeComplete
{
Gleb Pinigin's avatar
Gleb Pinigin committed
242 243
    self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
    self.navigationItem.leftBarButtonItem = _menuButton;
244 245 246 247 248
    self.emptyLibraryView.emptyLibraryLongDescriptionLabel.hidden = NO;
    self.emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", @"");
    [self.emptyLibraryView.activityIndicator stopAnimating];
    [self.emptyLibraryView removeFromSuperview];

249 250 251 252 253 254 255
    [self updateViewContents];
}

- (void)libraryWasUpdated
{
    NSLog(@"libraryWasUpdated");
    [self updateViewContents];
256 257
}

258
- (void)updateViewContents
Felix Paul Kühne's avatar
Felix Paul Kühne committed
259
{
260
    if (_libraryMode == VLCLibraryModeAllAlbums) {
261 262
        NSArray *rawAlbums = [MLAlbum allAlbums];
        _foundMedia = [[NSMutableArray alloc] init];
263
        for (MLAlbum *album in rawAlbums) {
264 265 266
            if (album.name.length > 0 && album.tracks.count > 0)
                [_foundMedia addObject:album];
        }
267

268
    } else if (_libraryMode == VLCLibraryModeAllSeries) {
269 270
        NSArray *rawShows = [MLShow allShows];
        _foundMedia = [[NSMutableArray alloc] init];
271
        for (MLShow *show in rawShows) {
272 273 274
            if (show.name.length > 0 && show.episodes.count > 0)
                [_foundMedia addObject:show];
        }
275 276 277
    } else
        _foundMedia = [NSMutableArray arrayWithArray:[MLFile allFiles]];

278
    [self reloadViews];
279
}
280

281
- (void)reloadViews
282
{
283
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
284
        [self.tableView reloadData];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
285 286
    else
        [self.collectionView reloadData];
287 288

    [self _displayEmptyLibraryViewIfNeeded];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
289 290
}

291 292
#pragma mark - Table View

Felix Paul Kühne's avatar
Felix Paul Kühne committed
293 294 295 296 297 298 299 300 301 302 303 304 305
- (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
{
306
    static NSString *CellIdentifier = @"PlaylistCell";
Felix Paul Kühne's avatar
Felix Paul Kühne committed
307

308
    VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
309
    if (cell == nil)
310
        cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
311

312 313
    NSInteger row = indexPath.row;
    cell.mediaObject = _foundMedia[row];
314

Felix Paul Kühne's avatar
Felix Paul Kühne committed
315 316 317
    return cell;
}

318 319 320 321 322
- (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
323 324 325 326 327 328 329
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

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

334
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Felix Paul Kühne's avatar
Felix Paul Kühne committed
335
{
336
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
337 338
    NSManagedObject *selectedObject = _foundMedia[indexPath.row];
    [self openMediaObject:selectedObject];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
339 340
}

341 342 343 344 345 346 347 348 349
#pragma mark - table view gestures
- (void)tableViewLongTouchGestureAction:(UIGestureRecognizer *)recognizer
{
    NSIndexPath *path = [(UITableView *)self.view indexPathForRowAtPoint:[recognizer locationInView:self.view]];
    UITableViewCell *cell = [(UITableView *)self.view cellForRowAtIndexPath:path];

    CGRect frame = cell.frame;
    if (frame.size.height > 90.)
        frame.size.height = 90.;
350
    else if (recognizer.state == UIGestureRecognizerStateBegan)
351 352 353 354 355 356 357 358
        frame.size.height = 180;

    void (^animationBlock)() = ^() {
        cell.frame = frame;
    };

    void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
        cell.frame = frame;
359
        [self.tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionNone animated:YES];
360 361 362 363 364 365
    };

    NSTimeInterval animationDuration = .2;
    [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
 }

366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
#pragma mark - Collection View
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _foundMedia.count;
}

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    VLCPlaylistCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PlaylistCell" forIndexPath:indexPath];
    cell.mediaObject = _foundMedia[indexPath.row];
    cell.collectionView = _collectionView;

    [cell setEditing:self.editing animated:NO];

    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
385
    if (SYSTEM_RUNS_IOS7_OR_LATER)
386 387
        return CGSizeMake(334.0, 191.0);

388 389 390 391 392
    return CGSizeMake(298.0, 220.0);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
393
    if (SYSTEM_RUNS_IOS7_OR_LATER)
394
        return UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0);
395 396 397
    return UIEdgeInsetsMake(0.0, 34.0, 0.0, 34.0);
}

398 399
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
400
    if (SYSTEM_RUNS_IOS7_OR_LATER)
401 402 403 404 405 406
        return 0.0;
    return 10.0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
407
    if (SYSTEM_RUNS_IOS7_OR_LATER)
408 409 410 411
        return 0.0;
    return 10.0;
}

412 413 414 415 416 417
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSManagedObject *selectedObject = _foundMedia[indexPath.row];
    [self openMediaObject:selectedObject];
}

418
#pragma mark - UI implementation
419 420
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
421
    if (_libraryMode != VLCLibraryModeAllFiles)
422 423
        return;

424
    [super setEditing:editing animated:animated];
425

Felix Paul Kühne's avatar
Felix Paul Kühne committed
426
    UIBarButtonItem *editButton = self.editButtonItem;
427 428
    NSString *editImage = editing? @"doneButton": @"button";
    NSString *editImageHighlight = editing? @"doneButtonHighlight": @"buttonHighlight";
Felix Paul Kühne's avatar
Felix Paul Kühne committed
429
    if (SYSTEM_RUNS_IOS7_OR_LATER)
430 431 432 433 434 435 436 437
        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
438

439
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Felix Paul Kühne's avatar
Felix Paul Kühne committed
440
        NSArray *visibleCells = self.collectionView.visibleCells;
441

Felix Paul Kühne's avatar
Felix Paul Kühne committed
442 443
        [visibleCells enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            VLCPlaylistCollectionViewCell *aCell = (VLCPlaylistCollectionViewCell*)obj;
444

Felix Paul Kühne's avatar
Felix Paul Kühne committed
445 446
            [aCell setEditing:editing animated:animated];
        }];
447
    } else
448
        [self.tableView setEditing:editing animated:YES];
449 450
}

451 452
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
453
    if (_libraryMode != VLCLibraryModeAllFiles)
454 455 456 457 458
        return UITableViewCellEditingStyleNone;

    return UITableViewCellEditingStyleDelete;
}

459
- (IBAction)leftButtonAction:(id)sender
460
{
461
    [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
462 463 464

    if (self.isEditing)
        [self setEditing:NO animated:YES];
465 466
}

467 468 469 470 471 472
- (IBAction)backToAllItems:(id)sender
{
    self.navigationItem.leftBarButtonItem = _menuButton;
    [self setLibraryMode:_libraryMode];
}

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
}

Gleb Pinigin's avatar
Gleb Pinigin committed
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
#pragma mark - autorotation

// 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)
/* introduced in iOS 6 */
- (NSUInteger)supportedInterfaceOrientations {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return UIInterfaceOrientationMaskAll;

    return (_foundMedia.count > 0)? UIInterfaceOrientationMaskAllButUpsideDown:
    UIInterfaceOrientationMaskPortrait;
}

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

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