VLCNetworkListViewController.m 5.1 KB

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