VLCPlaylistViewController.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // VLCMasterViewController.m
  3. // AspenProject
  4. //
  5. // Created by Felix Paul Kühne on 27.02.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. #import "VLCPlaylistViewController.h"
  9. #import "VLCMovieViewController.h"
  10. @interface VLCPlaylistViewController () {
  11. NSMutableArray *_foundMedia;
  12. }
  13. @end
  14. @implementation VLCPlaylistViewController
  15. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  16. {
  17. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  18. if (self) {
  19. self.title = @"Aspen Project";
  20. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
  21. self.clearsSelectionOnViewWillAppear = NO;
  22. self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
  23. }
  24. }
  25. return self;
  26. }
  27. - (void)dealloc
  28. {
  29. [_movieViewController release];
  30. [_foundMedia release];
  31. [super dealloc];
  32. }
  33. - (void)viewDidLoad
  34. {
  35. [super viewDidLoad];
  36. UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStyleBordered target:self action:@selector(showAboutView:)] autorelease];
  37. self.navigationItem.leftBarButtonItem = addButton;
  38. self.navigationItem.rightBarButtonItem = self.editButtonItem;
  39. [self updateViewContents];
  40. [[MLMediaLibrary sharedMediaLibrary] libraryDidAppear];
  41. }
  42. - (void)didReceiveMemoryWarning
  43. {
  44. [super didReceiveMemoryWarning];
  45. // Dispose of any resources that can be recreated.
  46. }
  47. #pragma mark - Table View
  48. - (void)updateViewContents
  49. {
  50. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  51. if (_foundMedia)
  52. [_foundMedia release];
  53. _foundMedia = [[NSMutableArray arrayWithArray:[MLFile allFiles]] retain];
  54. [self.tableView reloadData];
  55. }
  56. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  57. {
  58. return 1;
  59. }
  60. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  61. {
  62. return _foundMedia.count;
  63. }
  64. // Customize the appearance of table view cells.
  65. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  66. {
  67. static NSString *CellIdentifier = @"Cell";
  68. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  69. if (cell == nil) {
  70. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  71. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  72. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  73. }
  74. }
  75. MLFile *object = _foundMedia[indexPath.row];
  76. cell.textLabel.text = object.title;
  77. return cell;
  78. }
  79. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  80. {
  81. // Return NO if you do not want the specified item to be editable.
  82. return YES;
  83. }
  84. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  85. {
  86. if (editingStyle == UITableViewCellEditingStyleDelete) {
  87. [_foundMedia removeObjectAtIndex:indexPath.row];
  88. [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  89. } else if (editingStyle == UITableViewCellEditingStyleInsert) {
  90. // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
  91. }
  92. }
  93. /*
  94. // Override to support rearranging the table view.
  95. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
  96. {
  97. }
  98. */
  99. /*
  100. // Override to support conditional rearranging of the table view.
  101. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  102. {
  103. // Return NO if you do not want the item to be re-orderable.
  104. return YES;
  105. }
  106. */
  107. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  108. {
  109. MLFile *mediaObject = _foundMedia[indexPath.row];
  110. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  111. if (!self.movieViewController) {
  112. self.movieViewController = [[[VLCMovieViewController alloc] initWithNibName:@"VLCMovieViewController_iPhone" bundle:nil] autorelease];
  113. }
  114. self.movieViewController.mediaItem = mediaObject;
  115. [self.navigationController pushViewController:self.movieViewController animated:YES];
  116. } else
  117. self.movieViewController.mediaItem = mediaObject;
  118. }
  119. #pragma mark - UI implementation
  120. - (void)showAboutView:(id)sender
  121. {
  122. APLog(@"asked to show the about view");
  123. }
  124. @end