// // VLCMasterViewController.m // AspenProject // // Created by Felix Paul Kühne on 27.02.13. // Copyright (c) 2013 VideoLAN. All rights reserved. // #import "VLCPlaylistViewController.h" #import "VLCMovieViewController.h" #import "VLCPlaylistTableViewCell.h" #import "VLCPlaylistGridViewCell.h" #import "VLCAboutViewController.h" @interface VLCPlaylistViewController () { NSMutableArray *_foundMedia; } @end @implementation VLCPlaylistViewController @synthesize gridView=_gridview; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.title = @"Aspen"; } return self; } - (void)dealloc { [_tableView release]; [_gridview release]; [_aboutViewController release]; [_movieViewController release]; [_foundMedia release]; [super dealloc]; } - (void)viewDidLoad { self.tableView.rowHeight = [VLCPlaylistTableViewCell heightOfCell]; self.tableView.separatorColor = [UIColor colorWithWhite:.2 alpha:1.]; [super viewDidLoad]; UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStyleBordered target:self action:@selector(showAboutView:)] autorelease]; self.navigationItem.leftBarButtonItem = addButton; self.navigationItem.rightBarButtonItem = self.editButtonItem; [self updateViewContents]; [[MLMediaLibrary sharedMediaLibrary] libraryDidAppear]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table View - (void)updateViewContents { [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase]; if (_foundMedia) [_foundMedia release]; _foundMedia = [[NSMutableArray arrayWithArray:[MLFile allFiles]] retain]; if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) [self.tableView reloadData]; else [self.gridView reloadData]; } - (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 { static NSString *CellIdentifier = @"Cell"; VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier]; MLFile *object = _foundMedia[indexPath.row]; cell.titleLabel.text = object.title; cell.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[object duration]], [object fileSizeInBytes] / 2e6]; cell.thumbnailView.image = object.computedThumbnail; return cell; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [_foundMedia removeObjectAtIndex:indexPath.row]; [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { MLFile *mediaObject = _foundMedia[indexPath.row]; if (!self.movieViewController) { self.movieViewController = [[[VLCMovieViewController alloc] initWithNibName:@"VLCMovieViewController" bundle:nil] autorelease]; } self.movieViewController.mediaItem = mediaObject; [self.navigationController pushViewController:self.movieViewController animated:YES]; } #pragma mark - AQGridView - (NSUInteger)numberOfItemsInGridView:(AQGridView *)gridView { return _foundMedia.count; } - (AQGridViewCell *)gridView:(AQGridView *)gridView cellForItemAtIndex:(NSUInteger)index { static NSString *AQCellIdentifier = @"AQCell"; VLCPlaylistGridViewCell *cell = (VLCPlaylistGridViewCell *)[gridView dequeueReusableCellWithIdentifier:AQCellIdentifier]; if (cell == nil) { cell = [[VLCPlaylistGridViewCell alloc] initWithFrame:CGRectMake(0.0, 0.0, 384.,216.) reuseIdentifier:AQCellIdentifier]; cell.selectionStyle = AQGridViewCellSelectionStyleBlueGray; } MLFile *object = _foundMedia[index]; cell.title = object.title; cell.subtitle = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[object duration]], [object fileSizeInBytes] / 2e6]; cell.thumbnail = object.computedThumbnail; return cell; } - (CGSize)portraitGridCellSizeForGridView:(AQGridView *)gridView { static CGSize cellSize = { 384., 216. }; return cellSize; } - (void)gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index { MLFile *mediaObject = _foundMedia[index]; if (!self.movieViewController) { self.movieViewController = [[[VLCMovieViewController alloc] initWithNibName:@"VLCMovieViewController" bundle:nil] autorelease]; } self.movieViewController.mediaItem = mediaObject; [self.navigationController pushViewController:self.movieViewController animated:YES]; } #pragma mark - UI implementation - (void)showAboutView:(id)sender { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { if (!self.aboutViewController) { self.aboutViewController = [[[VLCAboutViewController alloc] initWithNibName:@"VLCAboutViewController" bundle:nil] autorelease]; } [self.navigationController pushViewController:self.aboutViewController animated:YES]; } else APLog(@"about panel not supported on iPad"); } @end