VLCNetworkListViewController.m 5.7 KB

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