VLCNetworkListViewController.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*****************************************************************************
  2. * VLCLocalNetworkListViewController
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2015 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. @interface VLCNetworkListViewController () <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
  16. {
  17. NSMutableArray *_searchData;
  18. UISearchBar *_searchBar;
  19. UISearchDisplayController *_searchDisplayController;
  20. }
  21. @end
  22. @implementation VLCNetworkListViewController
  23. - (void)loadView
  24. {
  25. _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
  26. _tableView.backgroundColor = [UIColor VLCDarkBackgroundColor];
  27. _tableView.delegate = self;
  28. _tableView.dataSource = self;
  29. _tableView.rowHeight = [VLCNetworkListCell heightOfCell];
  30. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  31. _tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  32. self.view = _tableView;
  33. }
  34. - (void)viewDidLoad
  35. {
  36. [super viewDidLoad];
  37. self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
  38. self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
  39. _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
  40. UINavigationBar *navBar = self.navigationController.navigationBar;
  41. _searchBar.barTintColor = navBar.barTintColor;
  42. _searchBar.tintColor = navBar.tintColor;
  43. _searchBar.translucent = navBar.translucent;
  44. _searchBar.opaque = navBar.opaque;
  45. _searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
  46. _searchDisplayController.delegate = self;
  47. _searchDisplayController.searchResultsDataSource = self;
  48. _searchDisplayController.searchResultsDelegate = self;
  49. _searchDisplayController.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  50. _searchDisplayController.searchResultsTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  51. _searchDisplayController.searchBar.searchBarStyle = UIBarStyleBlack;
  52. _searchBar.delegate = self;
  53. _searchBar.hidden = YES;
  54. UITapGestureRecognizer *tapTwiceGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwiceGestureAction:)];
  55. [tapTwiceGesture setNumberOfTapsRequired:2];
  56. [self.navigationController.navigationBar addGestureRecognizer:tapTwiceGesture];
  57. self.navigationItem.rightBarButtonItem = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(menuButtonAction:)];
  58. _searchData = [[NSMutableArray alloc] init];
  59. [_searchData removeAllObjects];
  60. }
  61. - (BOOL)shouldAutorotate
  62. {
  63. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  64. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  65. return NO;
  66. return YES;
  67. }
  68. - (IBAction)menuButtonAction:(id)sender
  69. {
  70. [[VLCSidebarController sharedInstance] toggleSidebar];
  71. if (self.isEditing)
  72. [self setEditing:NO animated:YES];
  73. }
  74. #pragma mark - Table view data source
  75. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  76. {
  77. return 1;
  78. }
  79. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  80. {
  81. return 0;
  82. }
  83. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  84. {
  85. return nil;
  86. }
  87. #pragma mark - Table view delegate
  88. - (void)tableView:(UITableView *)tableView willDisplayCell:(VLCNetworkListCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  89. {
  90. UIColor *color = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
  91. cell.contentView.backgroundColor = cell.titleLabel.backgroundColor = cell.folderTitleLabel.backgroundColor = cell.subtitleLabel.backgroundColor = color;
  92. }
  93. #pragma mark - Search Display Controller Delegate
  94. - (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
  95. {
  96. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  97. tableView.rowHeight = 80.0f;
  98. else
  99. tableView.rowHeight = 68.0f;
  100. tableView.backgroundColor = [UIColor blackColor];
  101. }
  102. #pragma mark - Gesture Action
  103. - (void)tapTwiceGestureAction:(UIGestureRecognizer *)recognizer
  104. {
  105. _searchBar.hidden = !_searchBar.hidden;
  106. if (_searchBar.hidden)
  107. self.tableView.tableHeaderView = nil;
  108. else
  109. self.tableView.tableHeaderView = _searchBar;
  110. [self.tableView setContentOffset:CGPointMake(0.0f, -self.tableView.contentInset.top) animated:NO];
  111. }
  112. @end