VLCPlaylistViewController.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 "VLCPlaylistGridViewCell.h"
  12. #import "VLCAboutViewController.h"
  13. @interface VLCPlaylistViewController () {
  14. NSMutableArray *_foundMedia;
  15. }
  16. @end
  17. @implementation VLCPlaylistViewController
  18. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  19. {
  20. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  21. if (self) {
  22. self.title = @"Aspen";
  23. }
  24. return self;
  25. }
  26. - (void)dealloc
  27. {
  28. [_tableView release];
  29. [_gridView release];
  30. [_aboutViewController release];
  31. [_movieViewController release];
  32. [_foundMedia release];
  33. [super dealloc];
  34. }
  35. - (void)viewDidLoad
  36. {
  37. self.tableView.rowHeight = [VLCPlaylistTableViewCell heightOfCell];
  38. self.tableView.separatorColor = [UIColor colorWithWhite:.2 alpha:1.];
  39. [super viewDidLoad];
  40. UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStyleBordered target:self action:@selector(showAboutView:)] autorelease];
  41. self.navigationItem.leftBarButtonItem = addButton;
  42. self.navigationItem.rightBarButtonItem = self.editButtonItem;
  43. [self updateViewContents];
  44. [[MLMediaLibrary sharedMediaLibrary] libraryDidAppear];
  45. }
  46. - (void)didReceiveMemoryWarning
  47. {
  48. [super didReceiveMemoryWarning];
  49. // Dispose of any resources that can be recreated.
  50. }
  51. #pragma mark - Table View
  52. - (void)updateViewContents
  53. {
  54. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  55. if (_foundMedia)
  56. [_foundMedia release];
  57. _foundMedia = [[NSMutableArray arrayWithArray:[MLFile allFiles]] retain];
  58. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
  59. [self.tableView reloadData];
  60. else
  61. [self.gridView reloadData];
  62. }
  63. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  64. {
  65. return 1;
  66. }
  67. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  68. {
  69. return _foundMedia.count;
  70. }
  71. // Customize the appearance of table view cells.
  72. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  73. {
  74. static NSString *CellIdentifier = @"Cell";
  75. VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  76. if (cell == nil)
  77. cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier];
  78. MLFile *object = _foundMedia[indexPath.row];
  79. cell.titleLabel.text = object.title;
  80. cell.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[object duration]], [object fileSizeInBytes] / 2e6];
  81. cell.thumbnailView.image = object.computedThumbnail;
  82. return cell;
  83. }
  84. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  85. {
  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. [self.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. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  98. {
  99. MLFile *mediaObject = _foundMedia[indexPath.row];
  100. if (!self.movieViewController) {
  101. self.movieViewController = [[[VLCMovieViewController alloc] initWithNibName:@"VLCMovieViewController" bundle:nil] autorelease];
  102. }
  103. self.movieViewController.mediaItem = mediaObject;
  104. [self.navigationController pushViewController:self.movieViewController animated:YES];
  105. }
  106. #pragma mark - AQGridView
  107. - (NSUInteger)numberOfItemsInGridView:(AQGridView *)gridView
  108. {
  109. return _foundMedia.count;
  110. }
  111. - (AQGridViewCell *)gridView:(AQGridView *)gridView cellForItemAtIndex:(NSUInteger)index
  112. {
  113. static NSString *AQCellIdentifier = @"AQCell";
  114. VLCPlaylistGridViewCell *cell = (VLCPlaylistGridViewCell *)[gridView dequeueReusableCellWithIdentifier:AQCellIdentifier];
  115. if (cell == nil) {
  116. cell = [[VLCPlaylistGridViewCell alloc] initWithFrame:CGRectMake(0.0, 0.0, 384.,216.) reuseIdentifier:AQCellIdentifier];
  117. cell.selectionStyle = AQGridViewCellSelectionStyleBlueGray;
  118. }
  119. MLFile *object = _foundMedia[index];
  120. cell.title = object.title;
  121. cell.subtitle = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[object duration]], [object fileSizeInBytes] / 2e6];
  122. cell.thumbnail = object.computedThumbnail;
  123. return cell;
  124. }
  125. - (CGSize)portraitGridCellSizeForGridView:(AQGridView *)gridView
  126. {
  127. static CGSize cellSize = { 384., 216. };
  128. return cellSize;
  129. }
  130. - (void)gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index
  131. {
  132. MLFile *mediaObject = _foundMedia[index];
  133. if (!self.movieViewController) {
  134. self.movieViewController = [[[VLCMovieViewController alloc] initWithNibName:@"VLCMovieViewController" bundle:nil] autorelease];
  135. }
  136. self.movieViewController.mediaItem = mediaObject;
  137. [self.navigationController pushViewController:self.movieViewController animated:YES];
  138. }
  139. #pragma mark - UI implementation
  140. - (void)showAboutView:(id)sender
  141. {
  142. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  143. if (!self.aboutViewController) {
  144. self.aboutViewController = [[[VLCAboutViewController alloc] initWithNibName:@"VLCAboutViewController" bundle:nil] autorelease];
  145. }
  146. [self.navigationController pushViewController:self.aboutViewController animated:YES];
  147. } else
  148. APLog(@"about panel not supported on iPad");
  149. }
  150. @end