123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- /*****************************************************************************
- * VLCLocalNetworkListViewController
- * VLC for iOS
- *****************************************************************************
- * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
- * $Id$
- *
- * Authors: Felix Paul Kühne <fkuehne # videolan.org>
- * Pierre SAGASPE <pierre.sagaspe # me.com>
- *
- * Refer to the COPYING file of the official project for license.
- *****************************************************************************/
- #import "VLCNetworkListViewController.h"
- #import "VLCNetworkListCell.h"
- NSString *VLCNetworkListCellIdentifier = @"VLCNetworkListCellIdentifier";
- @interface VLCNetworkListViewController () <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
- {
- NSMutableArray *_searchData;
- UISearchBar *_searchBar;
- UISearchDisplayController *_searchDisplayController;
- UITapGestureRecognizer *_tapTwiceGestureRecognizer;
- }
- @end
- @implementation VLCNetworkListViewController
- - (void)dealloc
- {
- [_tapTwiceGestureRecognizer removeTarget:self action:NULL];
- }
- - (void)loadView
- {
- _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
- _tableView.backgroundColor = [UIColor VLCDarkBackgroundColor];
- CGRect frame = _tableView.bounds;
- frame.origin.y = -frame.size.height;
- UIView *topView = [[UIView alloc] initWithFrame:frame];
- topView.backgroundColor = [UIColor VLCDarkBackgroundColor];
- [_tableView addSubview:topView];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.opaque = YES;
- _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;
- _tapTwiceGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwiceGestureAction:)];
- [_tapTwiceGestureRecognizer setNumberOfTapsRequired:2];
- [self.navigationController.navigationBar addGestureRecognizer:_tapTwiceGestureRecognizer];
- 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
|