/***************************************************************************** * VLCLocalNetworkListViewController * VLC for iOS ***************************************************************************** * Copyright (c) 2013-2015 VideoLAN. All rights reserved. * $Id$ * * Authors: Felix Paul Kühne * Pierre SAGASPE * * Refer to the COPYING file of the official project for license. *****************************************************************************/ #import "VLCNetworkListViewController.h" #import "VLCNetworkListCell.h" @interface VLCNetworkListViewController () { NSMutableArray *_searchData; UISearchBar *_searchBar; UISearchDisplayController *_searchDisplayController; } @end @implementation VLCNetworkListViewController - (void)loadView { _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain]; _tableView.backgroundColor = [UIColor VLCDarkBackgroundColor]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.rowHeight = [VLCNetworkListCell heightOfCell]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite; self.view = _tableView; } - (void)viewDidLoad { [super viewDidLoad]; self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor]; self.view.backgroundColor = [UIColor VLCDarkBackgroundColor]; _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; UINavigationBar *navBar = self.navigationController.navigationBar; _searchBar.barTintColor = navBar.barTintColor; _searchBar.tintColor = navBar.tintColor; _searchBar.translucent = navBar.translucent; _searchBar.opaque = navBar.opaque; _searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self]; _searchDisplayController.delegate = self; _searchDisplayController.searchResultsDataSource = self; _searchDisplayController.searchResultsDelegate = self; _searchDisplayController.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone; _searchDisplayController.searchResultsTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite; _searchDisplayController.searchBar.searchBarStyle = UIBarStyleBlack; _searchBar.delegate = self; _searchBar.hidden = YES; UITapGestureRecognizer *tapTwiceGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwiceGestureAction:)]; [tapTwiceGesture setNumberOfTapsRequired:2]; [self.navigationController.navigationBar addGestureRecognizer:tapTwiceGesture]; self.navigationItem.rightBarButtonItem = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(menuButtonAction:)]; _searchData = [[NSMutableArray alloc] init]; [_searchData removeAllObjects]; } - (BOOL)shouldAutorotate { UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) return NO; return YES; } - (IBAction)menuButtonAction:(id)sender { [[VLCSidebarController sharedInstance] toggleSidebar]; if (self.isEditing) [self setEditing:NO animated:YES]; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { return nil; } #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView willDisplayCell:(VLCNetworkListCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { UIColor *color = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor]; cell.contentView.backgroundColor = cell.titleLabel.backgroundColor = cell.folderTitleLabel.backgroundColor = cell.subtitleLabel.backgroundColor = color; } #pragma mark - Search Display Controller Delegate - (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) tableView.rowHeight = 80.0f; else tableView.rowHeight = 68.0f; tableView.backgroundColor = [UIColor blackColor]; } #pragma mark - Gesture Action - (void)tapTwiceGestureAction:(UIGestureRecognizer *)recognizer { _searchBar.hidden = !_searchBar.hidden; if (_searchBar.hidden) self.tableView.tableHeaderView = nil; else self.tableView.tableHeaderView = _searchBar; [self.tableView setContentOffset:CGPointMake(0.0f, -self.tableView.contentInset.top) animated:NO]; } @end