Commit 43224b48 authored by Felix Paul Kühne's avatar Felix Paul Kühne

implement library search field for iPad (close #11303)

parent 0cf439d7
/*****************************************************************************
* VLCLibraryHeaderView.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import <UIKit/UIKit.h>
@interface VLCLibraryHeaderView : UICollectionReusableView
+ (CGFloat)headerHeight;
- (id)initWithPredefinedFrame;
@property (strong, nonatomic, readwrite) UISearchBar *searchBar;
@end
/*****************************************************************************
* VLCLibraryHeaderView.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCLibraryHeaderView.h"
@interface VLCLibraryHeaderView ()
{
UISearchBar *_searchbar;
}
@end
@implementation VLCLibraryHeaderView
+ (CGFloat)headerHeight
{
return 40.;
}
- (id)initWithFrame:(CGRect)frame
{
return [self initWithPredefinedFrame];
}
- (id)initWithPredefinedFrame
{
self = [super initWithFrame:CGRectMake(0., 0., 320., [VLCLibraryHeaderView headerHeight])];
if (self)
self.backgroundColor = [UIColor VLCDarkBackgroundColor];
return self;
}
- (void)setSearchBar:(UISearchBar *)searchBar
{
if (searchBar == nil) {
if (_searchbar)
[_searchbar removeFromSuperview];
_searchbar = nil;
return;
}
_searchbar = searchBar;
CGRect contentFrame = self.frame;
_searchbar.frame = contentFrame;
[self addSubview:_searchbar];
}
- (UISearchBar *)searchBar
{
return _searchbar;
}
@end
......@@ -27,6 +27,7 @@
#import "LXReorderableCollectionViewFlowLayout.h"
#import "VLCAlertView.h"
#import "VLCOpenInActivity.h"
#import "VLCLibraryHeaderView.h"
#import <AssetsLibrary/AssetsLibrary.h>
......@@ -115,6 +116,7 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
} else {
if (!_collectionView) {
_folderLayout = [[VLCFolderCollectionViewFlowLayout alloc] init];
_folderLayout.headerReferenceSize = CGSizeMake(640., [VLCLibraryHeaderView headerHeight]);
_collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:_folderLayout];
_collectionView.alwaysBounceVertical = YES;
_collectionView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
......@@ -128,6 +130,7 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
[_collectionView registerNib:[UINib nibWithNibName:@"VLCFuturePlaylistCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"PlaylistCell"];
else
[_collectionView registerNib:[UINib nibWithNibName:@"VLCPlaylistCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"PlaylistCell"];
[_collectionView registerClass:[VLCLibraryHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderCell"];
self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
}
self.view = _collectionView;
......@@ -142,8 +145,14 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
if (_usingTableViewToShowData)
_tableView.contentInset = UIEdgeInsetsMake(originY, 0, 0, 0);
else
_collectionView.contentInset = UIEdgeInsetsMake(originY, 0, 0, 0);
else {
if (_searchBar.hidden)
_collectionView.contentInset = UIEdgeInsetsMake(originY - [VLCLibraryHeaderView headerHeight], 0, 0, 0);
else {
_collectionView.contentInset = UIEdgeInsetsMake(originY, 0, 0, 0);
[_collectionView scrollRectToVisible:CGRectMake(0., 0., 640., 200.) animated:NO];
}
}
}
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
......@@ -200,27 +209,25 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
} else
[self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@"bottomBlackBar"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
if (_usingTableViewToShowData) {
_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UINavigationBar *navBar = self.navigationController.navigationBar;
if (SYSTEM_RUNS_IOS7_OR_LATER) {
_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;
_searchBar.delegate = self;
UITapGestureRecognizer *tapTwiceGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwiceGestureAction:)];
[tapTwiceGesture setNumberOfTapsRequired:2];
[self.navigationController.navigationBar addGestureRecognizer:tapTwiceGesture];
_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UINavigationBar *navBar = self.navigationController.navigationBar;
if (SYSTEM_RUNS_IOS7_OR_LATER) {
_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;
_searchBar.delegate = self;
UITapGestureRecognizer *tapTwiceGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwiceGestureAction:)];
[tapTwiceGesture setNumberOfTapsRequired:2];
[self.navigationController.navigationBar addGestureRecognizer:tapTwiceGesture];
_searchData = [[NSMutableArray alloc] init];
}
......@@ -544,10 +551,10 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView)
return _searchData.count;
if (tableView == self.tableView)
return _foundMedia.count;
return _foundMedia.count;
return _searchData.count;
}
// Customize the appearance of table view cells.
......@@ -565,10 +572,10 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
NSInteger row = indexPath.row;
if (tableView == self.searchDisplayController.searchResultsTableView)
cell.mediaObject = _searchData[row];
else
if (tableView == self.tableView)
cell.mediaObject = _foundMedia[row];
else
cell.mediaObject = _searchData[row];
return cell;
}
......@@ -629,10 +636,10 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSManagedObject *selectedObject;
if (tableView == self.searchDisplayController.searchResultsTableView)
selectedObject = _searchData[indexPath.row];
else
if (tableView == self.tableView)
selectedObject = _foundMedia[indexPath.row];
else
selectedObject = _searchData[indexPath.row];
if ([selectedObject isKindOfClass:[MLAlbumTrack class]]) {
_tracks = [[(MLAlbumTrack*)selectedObject album] sortedTracks];
......@@ -694,10 +701,14 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
- (void)tapTwiceGestureAction:(UIGestureRecognizer *)recognizer
{
_searchBar.hidden = !_searchBar.hidden;
if (_searchBar.hidden)
self.tableView.tableHeaderView = nil;
else
self.tableView.tableHeaderView = _searchBar;
if (_usingTableViewToShowData) {
if (_searchBar.hidden)
self.tableView.tableHeaderView = nil;
else
self.tableView.tableHeaderView = _searchBar;
} else
[self setupContentViewWithContentInset:YES];
}
#pragma mark - Collection View
......@@ -853,6 +864,19 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
}
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
VLCLibraryHeaderView *reuseableView;
reuseableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderCell" forIndexPath:indexPath];
if (!reuseableView)
reuseableView = [[VLCLibraryHeaderView alloc] initWithPredefinedFrame];
reuseableView.searchBar = _searchBar;
return reuseableView;
}
#pragma mark - Folder implementation
- (void)rearrangeFolderTrackNumbersForRemovedItem:(MLFile *) mediaObject
......@@ -1126,6 +1150,7 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
[self.collectionView removeGestureRecognizer:recognizer];
}
_folderLayout = [[VLCFolderCollectionViewFlowLayout alloc] init];
_folderLayout.headerReferenceSize = CGSizeMake(640., [VLCLibraryHeaderView headerHeight]);
[self.collectionView setCollectionViewLayout:_folderLayout animated:NO];
[_collectionView addGestureRecognizer:_longPressGestureRecognizer];
}
......
......@@ -264,6 +264,7 @@
7D63C1D0187767AF00BD5256 /* fsarrow-time@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D63C1BE187767AF00BD5256 /* fsarrow-time@2x.png */; };
7D63C1D1187767AF00BD5256 /* fsarrow-volume.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D63C1BF187767AF00BD5256 /* fsarrow-volume.png */; };
7D63C1D2187767AF00BD5256 /* fsarrow-volume@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D63C1C0187767AF00BD5256 /* fsarrow-volume@2x.png */; };
7D65C7D219A15CEA00FA8819 /* VLCLibraryHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D65C7D119A15CEA00FA8819 /* VLCLibraryHeaderView.m */; };
7D66225E1871F29000CA9496 /* checkbox-legacy.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D66225A1871F29000CA9496 /* checkbox-legacy.png */; };
7D66225F1871F29000CA9496 /* checkbox-legacy@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D66225B1871F29000CA9496 /* checkbox-legacy@2x.png */; };
7D6622601871F29000CA9496 /* checkbox-legacy-empty.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D66225C1871F29000CA9496 /* checkbox-legacy-empty.png */; };
......@@ -844,6 +845,8 @@
7D63C1BE187767AF00BD5256 /* fsarrow-time@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "fsarrow-time@2x.png"; path = "arrows/fsarrow-time@2x.png"; sourceTree = "<group>"; };
7D63C1BF187767AF00BD5256 /* fsarrow-volume.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "fsarrow-volume.png"; path = "arrows/fsarrow-volume.png"; sourceTree = "<group>"; };
7D63C1C0187767AF00BD5256 /* fsarrow-volume@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "fsarrow-volume@2x.png"; path = "arrows/fsarrow-volume@2x.png"; sourceTree = "<group>"; };
7D65C7D019A15CEA00FA8819 /* VLCLibraryHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCLibraryHeaderView.h; path = Sources/VLCLibraryHeaderView.h; sourceTree = SOURCE_ROOT; };
7D65C7D119A15CEA00FA8819 /* VLCLibraryHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCLibraryHeaderView.m; path = Sources/VLCLibraryHeaderView.m; sourceTree = SOURCE_ROOT; };
7D66225A1871F29000CA9496 /* checkbox-legacy.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "checkbox-legacy.png"; sourceTree = "<group>"; };
7D66225B1871F29000CA9496 /* checkbox-legacy@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "checkbox-legacy@2x.png"; sourceTree = "<group>"; };
7D66225C1871F29000CA9496 /* checkbox-legacy-empty.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "checkbox-legacy-empty.png"; sourceTree = "<group>"; };
......@@ -1689,6 +1692,8 @@
8F91EC78195CEC7900F5BCBA /* VLCOpenInActivity.m */,
7D37849C183A98DD009EE944 /* VLCThumbnailsCache.h */,
7D37849D183A98DD009EE944 /* VLCThumbnailsCache.m */,
7D65C7D019A15CEA00FA8819 /* VLCLibraryHeaderView.h */,
7D65C7D119A15CEA00FA8819 /* VLCLibraryHeaderView.m */,
);
name = "Everything Playlist";
sourceTree = "<group>";
......@@ -2743,6 +2748,7 @@
7D6B08F2174D65B500A05173 /* IASKSpecifier.m in Sources */,
7D6B08F3174D65B500A05173 /* IASKPSSliderSpecifierViewCell.m in Sources */,
7D168F7418D4A33F003FAF59 /* UIImage+Blur.m in Sources */,
7D65C7D219A15CEA00FA8819 /* VLCLibraryHeaderView.m in Sources */,
7D6B08F4174D65B500A05173 /* IASKPSTextFieldSpecifierViewCell.m in Sources */,
7D6B08F5174D65B500A05173 /* IASKPSTitleValueSpecifierViewCell.m in Sources */,
9B5BEF2917FBAEA50016F9CB /* GTLDrive_Sources.m in Sources */,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment