VLCLocalNetworkListViewController.m 5.3 KB

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