VLCPlaylistViewController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 updateMediaDatabase];
  42. }
  43. - (void)didReceiveMemoryWarning
  44. {
  45. [super didReceiveMemoryWarning];
  46. // Dispose of any resources that can be recreated.
  47. }
  48. #pragma mark - Table View
  49. - (void)updateMediaDatabase
  50. {
  51. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  52. if (_foundMedia)
  53. [_foundMedia release];
  54. _foundMedia = [[NSMutableArray arrayWithArray:[MLFile allFiles]] retain];
  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 *object = _foundMedia[indexPath.row];
  110. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  111. if (!self.detailViewController) {
  112. self.detailViewController = [[[VLCDetailViewController alloc] initWithNibName:@"VLCDetailViewController_iPhone" bundle:nil] autorelease];
  113. }
  114. self.detailViewController.detailItem = object;
  115. [self.navigationController pushViewController:self.detailViewController animated:YES];
  116. } else {
  117. self.detailViewController.detailItem = object;
  118. }
  119. }
  120. @end