VLCServerListTVTableViewController.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // VLCServerListTableViewController.m
  3. // VLC for iOS
  4. //
  5. // Created by Tobias Conradi on 27.10.15.
  6. // Copyright © 2015 VideoLAN. All rights reserved.
  7. //
  8. #import "VLCServerListTVTableViewController.h"
  9. #import "VLCLocalNetworkServerTVCell.h"
  10. #import "VLCServerBrowsingTVTableViewController.h"
  11. @interface VLCServerListTVTableViewController ()
  12. @end
  13. @implementation VLCServerListTVTableViewController
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. self.clearsSelectionOnViewWillAppear = NO;
  17. UINib *nib = [UINib nibWithNibName:@"VLCLocalNetworkServerTVCell" bundle:nil];
  18. [self.tableView registerNib:nib forCellReuseIdentifier:VLCLocalServerTVCell];
  19. self.tableView.rowHeight = 150;
  20. }
  21. - (void)viewDidAppear:(BOOL)animated
  22. {
  23. [super viewDidAppear:animated];
  24. [self.discoveryController startDiscovery];
  25. }
  26. - (void)viewDidDisappear:(BOOL)animated
  27. {
  28. [super viewDidDisappear:animated];
  29. [self.discoveryController stopDiscovery];
  30. }
  31. #pragma mark - Table view data source
  32. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  33. return self.discoveryController.numberOfSections;
  34. }
  35. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  36. VLCLocalServerDiscoveryController *discoverer = self.discoveryController;
  37. if (discoverer.numberOfSections > 1 && [discoverer numberOfItemsInSection:section] > 0) {
  38. return [self.discoveryController titleForSection:section];
  39. }
  40. return nil;
  41. }
  42. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  43. return [self.discoveryController numberOfItemsInSection:section];
  44. }
  45. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  46. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:VLCLocalServerTVCell forIndexPath:indexPath];
  47. id<VLCLocalNetworkService> service = [self.discoveryController networkServiceForIndexPath:indexPath];
  48. cell.textLabel.text = service.title;
  49. cell.imageView.image = service.icon;
  50. return cell;
  51. }
  52. - (void)showWIP:(NSString *)todo {
  53. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Work in Progress\nFeature not (yet) implemented."
  54. message:todo
  55. preferredStyle:UIAlertControllerStyleAlert];
  56. [alertController addAction:[UIAlertAction actionWithTitle:@"Please fix this!"
  57. style:UIAlertActionStyleDefault
  58. handler:nil]];
  59. [alertController addAction:[UIAlertAction actionWithTitle:@"Nevermind"
  60. style:UIAlertActionStyleCancel
  61. handler:nil]];
  62. [self presentViewController:alertController animated:YES completion:nil];
  63. }
  64. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  65. id<VLCLocalNetworkService> service = [self.discoveryController networkServiceForIndexPath:indexPath];
  66. if ([service respondsToSelector:@selector(serverBrowser)]) {
  67. id <VLCNetworkServerBrowser> browser = [service serverBrowser];
  68. if (browser) {
  69. VLCServerBrowsingTVTableViewController *browsingViewController = [[VLCServerBrowsingTVTableViewController alloc] initWithServerBrowser:browser];
  70. [self showViewController:browsingViewController sender:nil];
  71. return;
  72. }
  73. }
  74. if ([service respondsToSelector:@selector(loginInformation)]) {
  75. [self showWIP:@"Login"];
  76. return;
  77. }
  78. if ([service respondsToSelector:@selector(directPlaybackURL)]) {
  79. [self showWIP:@"Direct playback form URL"];
  80. return;
  81. }
  82. }
  83. #pragma mark - VLCLocalServerDiscoveryController
  84. - (void)discoveryFoundSomethingNew {
  85. [self.tableView reloadData];
  86. NSLog(@"%s",__PRETTY_FUNCTION__);
  87. }
  88. /*
  89. #pragma mark - Navigation
  90. // In a storyboard-based application, you will often want to do a little preparation before navigation
  91. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  92. // Get the new view controller using [segue destinationViewController].
  93. // Pass the selected object to the new view controller.
  94. }
  95. */
  96. @end