VLCNetworkListViewController.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*****************************************************************************
  2. * VLCLocalNetworkListViewController
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2018 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Pierre SAGASPE <pierre.sagaspe # me.com>
  10. *
  11. * Refer to the COPYING file of the official project for license.
  12. *****************************************************************************/
  13. #import "VLCNetworkListViewController.h"
  14. #import "VLCNetworkListCell.h"
  15. NSString *VLCNetworkListCellIdentifier = @"VLCNetworkListCellIdentifier";
  16. @interface VLCNetworkListViewController () <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchControllerDelegate, UISearchResultsUpdating>
  17. {
  18. NSMutableArray *_searchData;
  19. UITapGestureRecognizer *_tapTwiceGestureRecognizer;
  20. UIActivityIndicatorView *_activityIndicator;
  21. }
  22. @end
  23. @implementation VLCNetworkListViewController
  24. - (void)dealloc
  25. {
  26. }
  27. - (void)loadView
  28. {
  29. _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
  30. _tableView.backgroundColor = [UIColor VLCDarkBackgroundColor];
  31. CGRect frame = _tableView.bounds;
  32. frame.origin.y = -frame.size.height;
  33. UIView *topView = [[UIView alloc] initWithFrame:frame];
  34. topView.backgroundColor = [UIColor VLCDarkBackgroundColor];
  35. [_tableView addSubview:topView];
  36. _tableView.delegate = self;
  37. _tableView.dataSource = self;
  38. _tableView.opaque = YES;
  39. _tableView.rowHeight = [VLCNetworkListCell heightOfCell];
  40. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  41. _tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  42. self.view = _tableView;
  43. _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
  44. _activityIndicator.center = _tableView.center;
  45. _activityIndicator.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
  46. _activityIndicator.hidesWhenStopped = YES;
  47. [_activityIndicator startAnimating];
  48. [self.view addSubview:_activityIndicator];
  49. }
  50. - (void)viewDidLoad
  51. {
  52. [super viewDidLoad];
  53. self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
  54. self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
  55. UINavigationBar *navBar = self.navigationController.navigationBar;
  56. _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
  57. _searchController.searchResultsUpdater = self;
  58. _searchController.delegate = self;
  59. _searchController.dimsBackgroundDuringPresentation = NO;
  60. _searchController.searchBar.delegate = self;
  61. _searchController.searchBar.barTintColor = navBar.barTintColor;
  62. _searchController.searchBar.tintColor = navBar.tintColor;
  63. _searchController.searchBar.translucent = navBar.translucent;
  64. _searchController.searchBar.opaque = navBar.opaque;
  65. [_searchController.searchBar sizeToFit];
  66. if (@available(iOS 11.0, *)) {
  67. // search bar text field background color
  68. UITextField *searchTextField = [_searchController.searchBar valueForKey:@"searchField"];
  69. UIView *backgroundView = searchTextField.subviews.firstObject;
  70. backgroundView.backgroundColor = UIColor.whiteColor;
  71. backgroundView.layer.cornerRadius = 10;
  72. backgroundView.clipsToBounds = YES;
  73. //_searchController.hidesNavigationBarDuringPresentation = NO;
  74. _searchController.obscuresBackgroundDuringPresentation = NO;
  75. self.navigationItem.hidesSearchBarWhenScrolling = YES;
  76. self.navigationItem.searchController = _searchController;
  77. } else {
  78. _tableView.tableHeaderView = _searchController.searchBar;
  79. }
  80. self.definesPresentationContext = YES;
  81. self.navigationItem.rightBarButtonItems = @[[UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(menuButtonAction:)],
  82. [UIBarButtonItem themedPlayAllButtonWithTarget:self andSelector:@selector(playAllAction:)]];
  83. _searchData = [[NSMutableArray alloc] init];
  84. [_searchData removeAllObjects];
  85. }
  86. - (void)viewWillAppear:(BOOL)animated
  87. {
  88. [super viewWillAppear:animated];
  89. if (@available(iOS 11.0, *)) {
  90. //iOS 11
  91. } else {
  92. CGPoint contentOffset = CGPointMake(0, _tableView.tableHeaderView.bounds.size.height);
  93. [self.tableView setContentOffset:contentOffset animated:NO];
  94. }
  95. }
  96. - (void)viewDidAppear:(BOOL)animated
  97. {
  98. [super viewDidAppear:animated];
  99. }
  100. - (void)viewWillDisappear:(BOOL)animated
  101. {
  102. [super viewWillDisappear:animated];
  103. }
  104. - (BOOL)shouldAutorotate
  105. {
  106. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  107. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  108. return NO;
  109. return YES;
  110. }
  111. - (IBAction)menuButtonAction:(id)sender
  112. {
  113. [[VLCSidebarController sharedInstance] toggleSidebar];
  114. if (self.isEditing)
  115. [self setEditing:NO animated:YES];
  116. }
  117. - (IBAction)playAllAction:(id)sender
  118. {
  119. // to be implemented by subclass
  120. }
  121. #pragma mark - Table view data source
  122. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  123. {
  124. return 1;
  125. }
  126. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  127. {
  128. return 0;
  129. }
  130. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  131. {
  132. return nil;
  133. }
  134. #pragma mark - Table view delegate
  135. - (void)tableView:(UITableView *)tableView willDisplayCell:(VLCNetworkListCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  136. {
  137. UIColor *color = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
  138. cell.backgroundColor = cell.titleLabel.backgroundColor = cell.folderTitleLabel.backgroundColor = cell.subtitleLabel.backgroundColor = color;
  139. if ([indexPath row] == ((NSIndexPath *)[[tableView indexPathsForVisibleRows] lastObject]).row)
  140. [_activityIndicator stopAnimating];
  141. }
  142. #pragma mark - Search Controller Delegate
  143. - (void)willPresentSearchController:(UISearchController *)searchController
  144. {
  145. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  146. _tableView.rowHeight = 80.0f;
  147. else
  148. _tableView.rowHeight = 68.0f;
  149. _tableView.backgroundColor = [UIColor blackColor];
  150. }
  151. #pragma mark - Search Research Updater
  152. - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
  153. {
  154. }
  155. @end