VLCPlaylistViewController.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 ipadAboutButton=_ipadAboutButton, gridView=_gridview, ipadToolBar=_ipadToolBar;
  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. [_ipadAboutButton release];
  31. [_ipadToolBar release];
  32. [_gridview release];
  33. [_aboutViewController release];
  34. [_movieViewController release];
  35. [_foundMedia release];
  36. [super dealloc];
  37. }
  38. - (void)viewDidLoad
  39. {
  40. self.tableView.rowHeight = [VLCPlaylistTableViewCell heightOfCell];
  41. self.tableView.separatorColor = [UIColor colorWithWhite:.2 alpha:1.];
  42. [super viewDidLoad];
  43. UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStyleBordered target:self action:@selector(showAboutView:)] autorelease];
  44. self.navigationItem.leftBarButtonItem = addButton;
  45. self.navigationItem.rightBarButtonItem = self.editButtonItem;
  46. [self updateViewContents];
  47. [[MLMediaLibrary sharedMediaLibrary] libraryDidAppear];
  48. }
  49. - (void)didReceiveMemoryWarning
  50. {
  51. [super didReceiveMemoryWarning];
  52. // Dispose of any resources that can be recreated.
  53. }
  54. #pragma mark - Table View
  55. - (void)updateViewContents
  56. {
  57. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  58. if (_foundMedia)
  59. [_foundMedia release];
  60. _foundMedia = [[NSMutableArray arrayWithArray:[MLFile allFiles]] retain];
  61. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
  62. [self.tableView reloadData];
  63. else
  64. [self.gridView reloadData];
  65. }
  66. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  67. {
  68. return 1;
  69. }
  70. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  71. {
  72. return _foundMedia.count;
  73. }
  74. // Customize the appearance of table view cells.
  75. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  76. {
  77. static NSString *CellIdentifier = @"Cell";
  78. VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  79. if (cell == nil)
  80. cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier];
  81. MLFile *object = _foundMedia[indexPath.row];
  82. cell.titleLabel.text = object.title;
  83. cell.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[object duration]], [object fileSizeInBytes] / 2e6];
  84. cell.thumbnailView.image = object.computedThumbnail;
  85. return cell;
  86. }
  87. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  88. {
  89. return YES;
  90. }
  91. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  92. {
  93. if (editingStyle == UITableViewCellEditingStyleDelete) {
  94. [_foundMedia removeObjectAtIndex:indexPath.row];
  95. [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  96. } else if (editingStyle == UITableViewCellEditingStyleInsert) {
  97. // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
  98. }
  99. }
  100. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  101. {
  102. MLFile *mediaObject = _foundMedia[indexPath.row];
  103. if (!self.movieViewController) {
  104. self.movieViewController = [[[VLCMovieViewController alloc] initWithNibName:@"VLCMovieViewController" bundle:nil] autorelease];
  105. }
  106. self.movieViewController.mediaItem = mediaObject;
  107. [self.navigationController pushViewController:self.movieViewController animated:YES];
  108. }
  109. #pragma mark - AQGridView
  110. - (NSUInteger)numberOfItemsInGridView:(AQGridView *)gridView
  111. {
  112. return _foundMedia.count;
  113. }
  114. - (AQGridViewCell *)gridView:(AQGridView *)gridView cellForItemAtIndex:(NSUInteger)index
  115. {
  116. static NSString *AQCellIdentifier = @"AQCell";
  117. VLCPlaylistGridViewCell *cell = (VLCPlaylistGridViewCell *)[gridView dequeueReusableCellWithIdentifier:AQCellIdentifier];
  118. if (cell == nil) {
  119. cell = [[VLCPlaylistGridViewCell alloc] initWithFrame:CGRectMake(0.0, 0.0, 384.,216.) reuseIdentifier:AQCellIdentifier];
  120. cell.selectionStyle = AQGridViewCellSelectionStyleBlueGray;
  121. }
  122. MLFile *object = _foundMedia[index];
  123. cell.title = object.title;
  124. cell.subtitle = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[object duration]], [object fileSizeInBytes] / 2e6];
  125. cell.thumbnail = object.computedThumbnail;
  126. return cell;
  127. }
  128. - (CGSize)portraitGridCellSizeForGridView:(AQGridView *)gridView
  129. {
  130. static CGSize cellSize = { 384., 216. };
  131. return cellSize;
  132. }
  133. - (void)gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index
  134. {
  135. MLFile *mediaObject = _foundMedia[index];
  136. if (!self.movieViewController) {
  137. self.movieViewController = [[[VLCMovieViewController alloc] initWithNibName:@"VLCMovieViewController" bundle:nil] autorelease];
  138. }
  139. self.movieViewController.mediaItem = mediaObject;
  140. [self.navigationController pushViewController:self.movieViewController animated:YES];
  141. }
  142. #pragma mark - UI implementation
  143. - (void)showAboutView:(id)sender
  144. {
  145. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  146. if (!self.aboutViewController) {
  147. self.aboutViewController = [[[VLCAboutViewController alloc] initWithNibName:@"VLCAboutViewController" bundle:nil] autorelease];
  148. }
  149. [self.navigationController pushViewController:self.aboutViewController animated:YES];
  150. } else
  151. APLog(@"about panel not supported on iPad");
  152. }
  153. @end