VLCNetworkListViewController.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.navigationController.navigationBar addGestureRecognizer:_tapTwiceGestureRecognizer];
  69. self.navigationItem.rightBarButtonItem = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(menuButtonAction:)];
  70. _searchData = [[NSMutableArray alloc] init];
  71. [_searchData removeAllObjects];
  72. }
  73. - (BOOL)shouldAutorotate
  74. {
  75. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  76. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  77. return NO;
  78. return YES;
  79. }
  80. - (IBAction)menuButtonAction:(id)sender
  81. {
  82. [[VLCSidebarController sharedInstance] toggleSidebar];
  83. if (self.isEditing)
  84. [self setEditing:NO animated:YES];
  85. }
  86. #pragma mark - Table view data source
  87. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  88. {
  89. return 1;
  90. }
  91. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  92. {
  93. return 0;
  94. }
  95. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  96. {
  97. return nil;
  98. }
  99. #pragma mark - Table view delegate
  100. - (void)tableView:(UITableView *)tableView willDisplayCell:(VLCNetworkListCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  101. {
  102. UIColor *color = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
  103. cell.contentView.backgroundColor = cell.titleLabel.backgroundColor = cell.folderTitleLabel.backgroundColor = cell.subtitleLabel.backgroundColor = color;
  104. }
  105. #pragma mark - Search Display Controller Delegate
  106. - (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
  107. {
  108. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  109. tableView.rowHeight = 80.0f;
  110. else
  111. tableView.rowHeight = 68.0f;
  112. tableView.backgroundColor = [UIColor blackColor];
  113. }
  114. #pragma mark - Gesture Action
  115. - (void)tapTwiceGestureAction:(UIGestureRecognizer *)recognizer
  116. {
  117. _searchBar.hidden = !_searchBar.hidden;
  118. if (_searchBar.hidden)
  119. self.tableView.tableHeaderView = nil;
  120. else
  121. self.tableView.tableHeaderView = _searchBar;
  122. [self.tableView setContentOffset:CGPointMake(0.0f, -self.tableView.contentInset.top) animated:NO];
  123. }
  124. @end