VLCDiscoveryListViewController.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*****************************************************************************
  2. * VLCDiscoveryListViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Author: Felix Paul Kühne <fkuehne # videolan.org>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCDiscoveryListViewController.h"
  13. #import "VLCNetworkListCell.h"
  14. @interface VLCDiscoveryListViewController () <VLCNetworkListCellDelegate, UITableViewDataSource, UITableViewDelegate, VLCMediaDelegate>
  15. {
  16. VLCMediaList *_mediaList;
  17. VLCMedia *rootMedia;
  18. }
  19. @end
  20. @implementation VLCDiscoveryListViewController
  21. - (instancetype)initWithMedia:(VLCMedia *)media
  22. {
  23. self = [super init];
  24. if (!self)
  25. return self;
  26. _mediaList = [media subitems];
  27. self.title = [media metadataForKey:VLCMetaInformationTitle];
  28. NSLog(@"media meta %@", media.metaDictionary);
  29. NSLog(@"count %lu", _mediaList.count);
  30. rootMedia = media;
  31. return self;
  32. }
  33. - (void)viewWillAppear:(BOOL)animated
  34. {
  35. [self.tableView reloadData];
  36. [rootMedia setDelegate:self];
  37. [rootMedia parseWithOptions:VLCMediaParseNetwork | VLCMediaFetchNetwork];
  38. }
  39. #pragma mark - media delegate
  40. - (void)mediaDidFinishParsing:(VLCMedia *)aMedia
  41. {
  42. NSLog(@"finished parsing %@, sub items %@", aMedia, [aMedia subitems]);
  43. }
  44. - (void)mediaMetaDataDidChange:(VLCMedia *)aMedia
  45. {
  46. NSLog(@"metadata changed %@, meta %@", aMedia, [aMedia metaDictionary]);
  47. }
  48. #pragma mark - table view data source, for more see super
  49. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  50. {
  51. return _mediaList.count;
  52. }
  53. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  54. {
  55. static NSString *CellIdentifier = @"DiscoveryCell";
  56. VLCNetworkListCell *cell = (VLCNetworkListCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier
  57. forIndexPath:indexPath];
  58. if (cell == nil)
  59. cell = [VLCNetworkListCell cellWithReuseIdentifier:CellIdentifier];
  60. VLCMedia *cellObject = [_mediaList mediaAtIndex:indexPath.row];
  61. cell.isDirectory = cellObject.mediaType == VLCMediaTypeDirectory;
  62. cell.isDownloadable = NO;
  63. cell.title = [cellObject metadataForKey:VLCMetaInformationTitle];
  64. cell.subtitle = cellObject.url.absoluteString;
  65. return cell;
  66. }
  67. - (void)triggerDownloadForCell:(VLCNetworkListCell *)cell
  68. {
  69. NSLog(@"downloads not implemented");
  70. }
  71. @end