// // 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" @interface VLCPlaylistViewController () { NSMutableArray *_foundMedia; } @end @implementation VLCPlaylistViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.title = @"Aspen"; if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { self.clearsSelectionOnViewWillAppear = NO; self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0); } } return self; } - (void)dealloc { [_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]; [self.tableView 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]; [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. } } /* // Override to support rearranging the table view. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */ /* // Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { MLFile *mediaObject = _foundMedia[indexPath.row]; if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { if (!self.movieViewController) { self.movieViewController = [[[VLCMovieViewController alloc] initWithNibName:@"VLCMovieViewController" bundle:nil] autorelease]; } self.movieViewController.mediaItem = mediaObject; [self.navigationController pushViewController:self.movieViewController animated:YES]; } else self.movieViewController.mediaItem = mediaObject; } #pragma mark - UI implementation - (void)showAboutView:(id)sender { APLog(@"asked to show the about view"); } @end