VLCNetworkListViewController.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 themedPlayAllButtonWithTarget:self andSelector:@selector(playAllAction:)]];
  82. _searchData = [[NSMutableArray alloc] init];
  83. [_searchData removeAllObjects];
  84. }
  85. - (void)viewWillAppear:(BOOL)animated
  86. {
  87. [super viewWillAppear:animated];
  88. if (@available(iOS 11.0, *)) {
  89. //iOS 11
  90. } else {
  91. CGPoint contentOffset = CGPointMake(0, _tableView.tableHeaderView.bounds.size.height);
  92. [self.tableView setContentOffset:contentOffset animated:NO];
  93. }
  94. }
  95. - (void)viewDidAppear:(BOOL)animated
  96. {
  97. [super viewDidAppear:animated];
  98. }
  99. - (void)viewWillDisappear:(BOOL)animated
  100. {
  101. [super viewWillDisappear:animated];
  102. if (self.isEditing)
  103. [self setEditing:NO animated:YES];
  104. }
  105. - (BOOL)shouldAutorotate
  106. {
  107. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  108. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  109. return NO;
  110. return YES;
  111. }
  112. - (IBAction)playAllAction:(id)sender
  113. {
  114. // to be implemented by subclass
  115. }
  116. #pragma mark - Table view data source
  117. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  118. {
  119. return 1;
  120. }
  121. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  122. {
  123. return 0;
  124. }
  125. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  126. {
  127. return nil;
  128. }
  129. #pragma mark - Table view delegate
  130. - (void)tableView:(UITableView *)tableView willDisplayCell:(VLCNetworkListCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  131. {
  132. UIColor *color = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
  133. cell.backgroundColor = cell.titleLabel.backgroundColor = cell.folderTitleLabel.backgroundColor = cell.subtitleLabel.backgroundColor = color;
  134. if ([indexPath row] == ((NSIndexPath *)[[tableView indexPathsForVisibleRows] lastObject]).row)
  135. [_activityIndicator stopAnimating];
  136. }
  137. #pragma mark - Search Controller Delegate
  138. - (void)willPresentSearchController:(UISearchController *)searchController
  139. {
  140. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  141. _tableView.rowHeight = 80.0f;
  142. else
  143. _tableView.rowHeight = 68.0f;
  144. _tableView.backgroundColor = [UIColor blackColor];
  145. }
  146. #pragma mark - Search Research Updater
  147. - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
  148. {
  149. }
  150. @end