VLCPlaylistViewController.m 4.7 KB

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