VLCNetworkListViewController.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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.color = [UIColor VLCOrangeTintColor];
  46. _activityIndicator.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
  47. _activityIndicator.hidesWhenStopped = YES;
  48. [_activityIndicator startAnimating];
  49. [self.view addSubview:_activityIndicator];
  50. }
  51. - (void)viewDidLoad
  52. {
  53. [super viewDidLoad];
  54. self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
  55. self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
  56. UINavigationBar *navBar = self.navigationController.navigationBar;
  57. _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
  58. _searchController.searchResultsUpdater = self;
  59. _searchController.delegate = self;
  60. _searchController.dimsBackgroundDuringPresentation = NO;
  61. _searchController.searchBar.delegate = self;
  62. _searchController.searchBar.barTintColor = navBar.barTintColor;
  63. _searchController.searchBar.tintColor = navBar.tintColor;
  64. _searchController.searchBar.translucent = navBar.translucent;
  65. _searchController.searchBar.opaque = navBar.opaque;
  66. [_searchController.searchBar sizeToFit];
  67. if (@available(iOS 11.0, *)) {
  68. // search bar text field background color
  69. UITextField *searchTextField = [_searchController.searchBar valueForKey:@"searchField"];
  70. UIView *backgroundView = searchTextField.subviews.firstObject;
  71. backgroundView.backgroundColor = UIColor.whiteColor;
  72. backgroundView.layer.cornerRadius = 10;
  73. backgroundView.clipsToBounds = YES;
  74. //_searchController.hidesNavigationBarDuringPresentation = NO;
  75. _searchController.obscuresBackgroundDuringPresentation = NO;
  76. self.navigationItem.hidesSearchBarWhenScrolling = YES;
  77. self.navigationItem.searchController = _searchController;
  78. } else {
  79. _tableView.tableHeaderView = _searchController.searchBar;
  80. }
  81. self.definesPresentationContext = YES;
  82. self.navigationItem.rightBarButtonItems = @[[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. if (self.isEditing)
  104. [self setEditing:NO animated:YES];
  105. }
  106. - (BOOL)shouldAutorotate
  107. {
  108. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  109. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  110. return NO;
  111. return YES;
  112. }
  113. - (IBAction)playAllAction:(id)sender
  114. {
  115. // to be implemented by subclass
  116. }
  117. #pragma mark - Table view data source
  118. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  119. {
  120. return 1;
  121. }
  122. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  123. {
  124. return 0;
  125. }
  126. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  127. {
  128. return nil;
  129. }
  130. #pragma mark - Table view delegate
  131. - (void)tableView:(UITableView *)tableView willDisplayCell:(VLCNetworkListCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  132. {
  133. UIColor *color = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
  134. cell.backgroundColor = cell.titleLabel.backgroundColor = cell.folderTitleLabel.backgroundColor = cell.subtitleLabel.backgroundColor = color;
  135. if ([indexPath row] == ((NSIndexPath *)[[tableView indexPathsForVisibleRows] lastObject]).row)
  136. [_activityIndicator stopAnimating];
  137. }
  138. #pragma mark - Search Controller Delegate
  139. - (void)willPresentSearchController:(UISearchController *)searchController
  140. {
  141. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  142. _tableView.rowHeight = 80.0f;
  143. else
  144. _tableView.rowHeight = 68.0f;
  145. _tableView.backgroundColor = [UIColor blackColor];
  146. }
  147. #pragma mark - Search Research Updater
  148. - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
  149. {
  150. }
  151. @end