VLCPlaylistViewController.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. @synthesize gridView=_gridview;
  19. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  20. {
  21. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  22. if (self) {
  23. self.title = @"Aspen";
  24. }
  25. return self;
  26. }
  27. - (void)dealloc
  28. {
  29. [_tableView release];
  30. [_gridview release];
  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. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
  60. [self.tableView reloadData];
  61. else
  62. [self.gridView reloadData];
  63. }
  64. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  65. {
  66. return 1;
  67. }
  68. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  69. {
  70. return _foundMedia.count;
  71. }
  72. // Customize the appearance of table view cells.
  73. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  74. {
  75. static NSString *CellIdentifier = @"Cell";
  76. VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  77. if (cell == nil)
  78. cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier];
  79. MLFile *object = _foundMedia[indexPath.row];
  80. cell.titleLabel.text = object.title;
  81. cell.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[object duration]], [object fileSizeInBytes] / 2e6];
  82. cell.thumbnailView.image = object.computedThumbnail;
  83. return cell;
  84. }
  85. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  86. {
  87. return YES;
  88. }
  89. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  90. {
  91. if (editingStyle == UITableViewCellEditingStyleDelete) {
  92. [_foundMedia removeObjectAtIndex:indexPath.row];
  93. [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  94. } else if (editingStyle == UITableViewCellEditingStyleInsert) {
  95. // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
  96. }
  97. }
  98. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  99. {
  100. MLFile *mediaObject = _foundMedia[indexPath.row];
  101. if (!self.movieViewController) {
  102. self.movieViewController = [[[VLCMovieViewController alloc] initWithNibName:@"VLCMovieViewController" bundle:nil] autorelease];
  103. }
  104. self.movieViewController.mediaItem = mediaObject;
  105. [self.navigationController pushViewController:self.movieViewController animated:YES];
  106. }
  107. #pragma mark - AQGridView
  108. - (NSUInteger)numberOfItemsInGridView:(AQGridView *)gridView
  109. {
  110. return _foundMedia.count;
  111. }
  112. - (AQGridViewCell *)gridView:(AQGridView *)gridView cellForItemAtIndex:(NSUInteger)index
  113. {
  114. static NSString *AQCellIdentifier = @"AQCell";
  115. VLCPlaylistGridViewCell *cell = (VLCPlaylistGridViewCell *)[gridView dequeueReusableCellWithIdentifier:AQCellIdentifier];
  116. if (cell == nil) {
  117. cell = [[VLCPlaylistGridViewCell alloc] initWithFrame:CGRectMake(0.0, 0.0, 384.,216.) reuseIdentifier:AQCellIdentifier];
  118. cell.selectionStyle = AQGridViewCellSelectionStyleBlueGray;
  119. }
  120. MLFile *object = _foundMedia[index];
  121. cell.title = object.title;
  122. cell.subtitle = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[object duration]], [object fileSizeInBytes] / 2e6];
  123. cell.thumbnail = object.computedThumbnail;
  124. return cell;
  125. }
  126. - (CGSize)portraitGridCellSizeForGridView:(AQGridView *)gridView
  127. {
  128. static CGSize cellSize = { 384., 216. };
  129. return cellSize;
  130. }
  131. - (void)gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index
  132. {
  133. MLFile *mediaObject = _foundMedia[index];
  134. if (!self.movieViewController) {
  135. self.movieViewController = [[[VLCMovieViewController alloc] initWithNibName:@"VLCMovieViewController" bundle:nil] autorelease];
  136. }
  137. self.movieViewController.mediaItem = mediaObject;
  138. [self.navigationController pushViewController:self.movieViewController animated:YES];
  139. }
  140. #pragma mark - UI implementation
  141. - (void)showAboutView:(id)sender
  142. {
  143. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  144. if (!self.aboutViewController) {
  145. self.aboutViewController = [[[VLCAboutViewController alloc] initWithNibName:@"VLCAboutViewController" bundle:nil] autorelease];
  146. }
  147. [self.navigationController pushViewController:self.aboutViewController animated:YES];
  148. } else
  149. APLog(@"about panel not supported on iPad");
  150. }
  151. @end