VLCNetworkListViewController.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. }
  28. - (void)loadView
  29. {
  30. _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
  31. _tableView.backgroundColor = [UIColor VLCDarkBackgroundColor];
  32. CGRect frame = _tableView.bounds;
  33. frame.origin.y = -frame.size.height;
  34. UIView *topView = [[UIView alloc] initWithFrame:frame];
  35. topView.backgroundColor = [UIColor VLCDarkBackgroundColor];
  36. [_tableView addSubview:topView];
  37. _tableView.delegate = self;
  38. _tableView.dataSource = self;
  39. _tableView.opaque = YES;
  40. _tableView.rowHeight = [VLCNetworkListCell heightOfCell];
  41. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  42. _tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  43. self.view = _tableView;
  44. }
  45. - (void)viewDidLoad
  46. {
  47. [super viewDidLoad];
  48. self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
  49. self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
  50. _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
  51. UINavigationBar *navBar = self.navigationController.navigationBar;
  52. _searchBar.barTintColor = navBar.barTintColor;
  53. _searchBar.tintColor = navBar.tintColor;
  54. _searchBar.translucent = navBar.translucent;
  55. _searchBar.opaque = navBar.opaque;
  56. _searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
  57. _searchDisplayController.delegate = self;
  58. _searchDisplayController.searchResultsDataSource = self;
  59. _searchDisplayController.searchResultsDelegate = self;
  60. _searchDisplayController.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  61. _searchDisplayController.searchResultsTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  62. _searchDisplayController.searchBar.searchBarStyle = UIBarStyleBlack;
  63. _searchBar.delegate = self;
  64. self.tableView.tableHeaderView = _searchBar;
  65. self.navigationItem.rightBarButtonItems = @[[UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(menuButtonAction:)],
  66. [UIBarButtonItem themedPlayAllButtonWithTarget:self andSelector:@selector(playAllAction:)]];
  67. _searchData = [[NSMutableArray alloc] init];
  68. [_searchData removeAllObjects];
  69. }
  70. - (void)viewWillAppear:(BOOL)animated
  71. {
  72. [super viewWillAppear:animated];
  73. CGPoint contentOffset = CGPointMake(0, _searchBar.bounds.size.height);
  74. [self.tableView setContentOffset:contentOffset animated:NO];
  75. }
  76. - (void)viewDidAppear:(BOOL)animated
  77. {
  78. [super viewDidAppear:animated];
  79. }
  80. - (void)viewWillDisappear:(BOOL)animated
  81. {
  82. [super viewWillDisappear:animated];
  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. @end