123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- //
- // VLCMasterViewController.m
- // AspenProject
- //
- // Created by Felix Paul Kühne on 27.02.13.
- // Copyright (c) 2013 VideoLAN. All rights reserved.
- //
- #import <MediaLibraryKit/MLFile.h>
- #import <MediaLibraryKit/MLMediaLibrary.h>
- #import "VLCPlaylistViewController.h"
- #import "VLCDetailViewController.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 Project";
- if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
- self.clearsSelectionOnViewWillAppear = NO;
- self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
- }
- }
- return self;
- }
- - (void)dealloc
- {
- [_detailViewController release];
- [_foundMedia release];
- [super dealloc];
- }
- - (void)viewDidLoad
- {
- [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
- {
- NSLog(@"found %u media", _foundMedia.count);
- return _foundMedia.count;
- }
- // Customize the appearance of table view cells.
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
- if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- }
- }
- MLFile *object = _foundMedia[indexPath.row];
- cell.textLabel.text = object.title;
- NSLog(@"returning cell with title %@", object.title);
- return cell;
- }
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // Return NO if you do not want the specified item to be editable.
- 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 *object = _foundMedia[indexPath.row];
- if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
- if (!self.detailViewController) {
- self.detailViewController = [[[VLCDetailViewController alloc] initWithNibName:@"VLCDetailViewController_iPhone" bundle:nil] autorelease];
- }
- self.detailViewController.detailItem = object;
- [self.navigationController pushViewController:self.detailViewController animated:YES];
- } else {
- self.detailViewController.detailItem = object;
- }
- }
- #pragma mark - UI implementation
- - (void)showAboutView:(id)sender
- {
- NSLog(@"asked to show the about view");
- }
- @end
|