VLCPlaylistViewController.m 5.1 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 "VLCPlaylistViewController.h"
  9. #import "VLCMovieViewController.h"
  10. #import "VLCPlaylistTableViewCell.h"
  11. #import "VLCAboutViewController.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";
  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. [_aboutViewController release];
  32. [_movieViewController release];
  33. [_foundMedia release];
  34. [super dealloc];
  35. }
  36. - (void)viewDidLoad
  37. {
  38. self.tableView.rowHeight = [VLCPlaylistTableViewCell heightOfCell];
  39. self.tableView.separatorColor = [UIColor colorWithWhite:.2 alpha:1.];
  40. [super viewDidLoad];
  41. UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStyleBordered target:self action:@selector(showAboutView:)] autorelease];
  42. self.navigationItem.leftBarButtonItem = addButton;
  43. self.navigationItem.rightBarButtonItem = self.editButtonItem;
  44. [self updateViewContents];
  45. [[MLMediaLibrary sharedMediaLibrary] libraryDidAppear];
  46. }
  47. - (void)didReceiveMemoryWarning
  48. {
  49. [super didReceiveMemoryWarning];
  50. // Dispose of any resources that can be recreated.
  51. }
  52. #pragma mark - Table View
  53. - (void)updateViewContents
  54. {
  55. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  56. if (_foundMedia)
  57. [_foundMedia release];
  58. _foundMedia = [[NSMutableArray arrayWithArray:[MLFile allFiles]] retain];
  59. [self.tableView reloadData];
  60. }
  61. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  62. {
  63. return 1;
  64. }
  65. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  66. {
  67. return _foundMedia.count;
  68. }
  69. // Customize the appearance of table view cells.
  70. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  71. {
  72. static NSString *CellIdentifier = @"Cell";
  73. VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  74. if (cell == nil)
  75. cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier];
  76. MLFile *object = _foundMedia[indexPath.row];
  77. cell.titleLabel.text = object.title;
  78. cell.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[object duration]], [object fileSizeInBytes] / 2e6];
  79. cell.thumbnailView.image = object.computedThumbnail;
  80. return cell;
  81. }
  82. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  83. {
  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" 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. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  125. if (!self.aboutViewController) {
  126. self.aboutViewController = [[[VLCAboutViewController alloc] initWithNibName:@"VLCAboutViewController" bundle:nil] autorelease];
  127. }
  128. [self.navigationController pushViewController:self.aboutViewController animated:YES];
  129. } else
  130. APLog(@"about panel not supported on iPad");
  131. }
  132. @end