VLCNetworkListViewController.m 6.2 KB

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