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