VLCNetworkListViewController.m 6.5 KB

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