VLCPlaylistViewController.m 19 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;

66
        if (SYSTEM_RUNS_IOS7_OR_LATER) {
67
            [_collectionView registerNib:[UINib nibWithNibName:@"VLCFuturePlaylistCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"PlaylistCell"];
68 69
            self.view.backgroundColor = [UIColor colorWithWhite:.125 alpha:1.];
        } else {
70
            [_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];
116 117 118

    if (SYSTEM_RUNS_IOS7_OR_LATER)
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
119 120
}

121 122 123
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
124
    [self _displayEmptyLibraryViewIfNeeded];
125 126
}

127 128
- (void)viewDidAppear:(BOOL)animated
{
129 130
    [super viewDidAppear:animated];

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

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

146
    if (_foundMedia.count < 1)
147
        [self updateViewContents];
148 149 150 151 152 153 154 155 156
    [[MLMediaLibrary sharedMediaLibrary] performSelector:@selector(libraryDidAppear) withObject:nil afterDelay:1.];
}

- (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
- (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];
182 183
    } else
        [(VLCAppDelegate*)[UIApplication sharedApplication].delegate openMediaFromManagedObject:mediaObject];
184 185
}

186 187
- (void)removeMediaObject:(MLFile *)mediaObject
{
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
    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];
205
    [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
206
    [self updateViewContents];
207 208 209 210
}

- (void)_displayEmptyLibraryViewIfNeeded
{
211 212 213
    if (self.emptyLibraryView.superview)
        [self.emptyLibraryView removeFromSuperview];

Gleb Pinigin's avatar
Gleb Pinigin committed
214 215
    if (_foundMedia.count == 0) {
        self.emptyLibraryView.frame = self.view.bounds;
216 217
        [self.view addSubview:self.emptyLibraryView];
    }
218
    if (_libraryMode == VLCLibraryModeAllFiles && _foundMedia.count > 0)
219 220 221
        self.navigationItem.rightBarButtonItem = self.editButtonItem;
    else
        self.navigationItem.rightBarButtonItem = nil;
222 223 224 225 226

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

229 230
- (void)libraryUpgradeComplete
{
Gleb Pinigin's avatar
Gleb Pinigin committed
231 232
    self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
    self.navigationItem.leftBarButtonItem = _menuButton;
233 234 235 236 237
    self.emptyLibraryView.emptyLibraryLongDescriptionLabel.hidden = NO;
    self.emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", @"");
    [self.emptyLibraryView.activityIndicator stopAnimating];
    [self.emptyLibraryView removeFromSuperview];

238 239 240 241 242 243 244
    [self updateViewContents];
}

- (void)libraryWasUpdated
{
    NSLog(@"libraryWasUpdated");
    [self updateViewContents];
245 246
}

247
- (void)updateViewContents
Felix Paul Kühne's avatar
Felix Paul Kühne committed
248
{
249
    if (_libraryMode == VLCLibraryModeAllAlbums) {
250 251
        NSArray *rawAlbums = [MLAlbum allAlbums];
        _foundMedia = [[NSMutableArray alloc] init];
252
        for (MLAlbum *album in rawAlbums) {
253 254 255
            if (album.name.length > 0 && album.tracks.count > 0)
                [_foundMedia addObject:album];
        }
256

257
    } else if (_libraryMode == VLCLibraryModeAllSeries) {
258 259
        NSArray *rawShows = [MLShow allShows];
        _foundMedia = [[NSMutableArray alloc] init];
260
        for (MLShow *show in rawShows) {
261 262 263
            if (show.name.length > 0 && show.episodes.count > 0)
                [_foundMedia addObject:show];
        }
264 265 266
    } else
        _foundMedia = [NSMutableArray arrayWithArray:[MLFile allFiles]];

267
    [self reloadViews];
268
}
269

270
- (void)reloadViews
271
{
272
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
273
        [self.tableView reloadData];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
274 275
    else
        [self.collectionView reloadData];
276 277

    [self _displayEmptyLibraryViewIfNeeded];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
278 279
}

280 281
#pragma mark - Table View

Felix Paul Kühne's avatar
Felix Paul Kühne committed
282 283 284 285 286 287 288 289 290 291 292 293 294
- (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
{
295
    static NSString *CellIdentifier = @"PlaylistCell";
Felix Paul Kühne's avatar
Felix Paul Kühne committed
296

297
    VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
298
    if (cell == nil)
299
        cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
300

301 302
    NSInteger row = indexPath.row;
    cell.mediaObject = _foundMedia[row];
303

Felix Paul Kühne's avatar
Felix Paul Kühne committed
304 305 306
    return cell;
}

307 308 309 310 311
- (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
312 313 314 315 316 317 318
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

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

323
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Felix Paul Kühne's avatar
Felix Paul Kühne committed
324
{
325
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
326 327
    NSManagedObject *selectedObject = _foundMedia[indexPath.row];
    [self openMediaObject:selectedObject];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
328 329
}

330 331 332 333 334 335 336 337 338
#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.;
339
    else if (recognizer.state == UIGestureRecognizerStateBegan)
340 341 342 343 344 345 346 347
        frame.size.height = 180;

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

    void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
        cell.frame = frame;
348
        [self.tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionNone animated:YES];
349 350 351 352 353 354
    };

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

355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
#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
374
    if (SYSTEM_RUNS_IOS7_OR_LATER)
375
        return CGSizeMake(308.0, 174.0);
376

377 378 379 380 381 382 383 384
    return CGSizeMake(298.0, 220.0);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0.0, 34.0, 0.0, 34.0);
}

385 386 387 388 389 390 391 392 393 394
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 10.0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 10.0;
}

395 396 397 398 399 400
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSManagedObject *selectedObject = _foundMedia[indexPath.row];
    [self openMediaObject:selectedObject];
}

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

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

Felix Paul Kühne's avatar
Felix Paul Kühne committed
409
    UIBarButtonItem *editButton = self.editButtonItem;
410 411
    NSString *editImage = editing? @"doneButton": @"button";
    NSString *editImageHighlight = editing? @"doneButtonHighlight": @"buttonHighlight";
Felix Paul Kühne's avatar
Felix Paul Kühne committed
412
    if (SYSTEM_RUNS_IOS7_OR_LATER)
413 414 415 416 417 418 419 420
        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
421

422
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Felix Paul Kühne's avatar
Felix Paul Kühne committed
423
        NSArray *visibleCells = self.collectionView.visibleCells;
424

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

Felix Paul Kühne's avatar
Felix Paul Kühne committed
428 429
            [aCell setEditing:editing animated:animated];
        }];
430
    } else
431
        [self.tableView setEditing:editing animated:YES];
432 433
}

434 435
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
436
    if (_libraryMode != VLCLibraryModeAllFiles)
437 438 439 440 441
        return UITableViewCellEditingStyleNone;

    return UITableViewCellEditingStyleDelete;
}

442
- (IBAction)leftButtonAction:(id)sender
443
{
444
    [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
445 446 447

    if (self.isEditing)
        [self setEditing:NO animated:YES];
448 449
}

450 451 452 453 454 455
- (IBAction)backToAllItems:(id)sender
{
    self.navigationItem.leftBarButtonItem = _menuButton;
    [self setLibraryMode:_libraryMode];
}

456
#pragma mark - coin coin
457

458
- (void)setLibraryMode:(VLCLibraryMode)mode
459 460
{
    _libraryMode = mode;
461

462
    if (_libraryMode == VLCLibraryModeAllAlbums)
463
        self.title = NSLocalizedString(@"LIBRARY_MUSIC", @"");
464
    else if( _libraryMode == VLCLibraryModeAllSeries)
465 466 467 468
        self.title = NSLocalizedString(@"LIBRARY_SERIES", @"");
    else
        self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");

469
    [self updateViewContents];
470 471
}

Gleb Pinigin's avatar
Gleb Pinigin committed
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
#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
490
@end