VLCNetworkListViewController.m 5.9 KB

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