123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- //
- // 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
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- self.title = @"Aspen";
- }
- return self;
- }
- - (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:)];
- 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];
- _foundMedia = [NSMutableArray arrayWithArray:[MLFile allFiles]];
- 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];
- }
- 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];
- }
- 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];
- }
- [self.navigationController pushViewController:self.aboutViewController animated:YES];
- } else
- APLog(@"about panel not supported on iPad");
- }
- @end
|