VLCPlaylistViewController.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 "VLCDetailViewController.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. [_detailViewController 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. NSLog(@"found %u media", _foundMedia.count);
  65. return _foundMedia.count;
  66. }
  67. // Customize the appearance of table view cells.
  68. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  69. {
  70. static NSString *CellIdentifier = @"Cell";
  71. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  72. if (cell == nil) {
  73. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  74. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  75. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  76. }
  77. }
  78. MLFile *object = _foundMedia[indexPath.row];
  79. cell.textLabel.text = object.title;
  80. NSLog(@"returning cell with title %@", object.title);
  81. return cell;
  82. }
  83. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  84. {
  85. // Return NO if you do not want the specified item to be editable.
  86. return YES;
  87. }
  88. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  89. {
  90. if (editingStyle == UITableViewCellEditingStyleDelete) {
  91. [_foundMedia removeObjectAtIndex:indexPath.row];
  92. [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  93. } else if (editingStyle == UITableViewCellEditingStyleInsert) {
  94. // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
  95. }
  96. }
  97. /*
  98. // Override to support rearranging the table view.
  99. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
  100. {
  101. }
  102. */
  103. /*
  104. // Override to support conditional rearranging of the table view.
  105. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  106. {
  107. // Return NO if you do not want the item to be re-orderable.
  108. return YES;
  109. }
  110. */
  111. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  112. {
  113. MLFile *object = _foundMedia[indexPath.row];
  114. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  115. if (!self.detailViewController) {
  116. self.detailViewController = [[[VLCDetailViewController alloc] initWithNibName:@"VLCDetailViewController_iPhone" bundle:nil] autorelease];
  117. }
  118. self.detailViewController.detailItem = object;
  119. [self.navigationController pushViewController:self.detailViewController animated:YES];
  120. } else {
  121. self.detailViewController.detailItem = object;
  122. }
  123. }
  124. #pragma mark - UI implementation
  125. - (void)showAboutView:(id)sender
  126. {
  127. NSLog(@"asked to show the about view");
  128. }
  129. @end