VLCNetworkListViewController.m 5.3 KB

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