Commit e09a2706 authored by Soomin Lee's avatar Soomin Lee Committed by Jean-Baptiste Kempf

iOS: Add collectionView landscape orientation for phones

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 7e4ae0fa
......@@ -97,6 +97,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
- (void)loadView
{
[self setupContentViewWithContentInset:NO];
[self setViewFromDeviceOrientation];
[self updateViewsForCurrentDisplayMode];
_libraryMode = VLCLibraryModeAllFiles;
......@@ -152,21 +153,18 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
[contentView addSubview:_collectionView];
[_collectionView reloadData];
}
if (setInset) {
CGSize statusBarSize = [UIApplication sharedApplication].statusBarFrame.size;
// Status bar frame doesn't change correctly on rotation
CGFloat statusBarHeight = MIN(statusBarSize.height, statusBarSize.width);
CGFloat originY = self.navigationController.navigationBar.frame.size.height + statusBarHeight;
UIScrollView *playlistView = self.usingTableViewToShowData ? _tableView : _collectionView;
playlistView.contentInset = UIEdgeInsetsMake(originY, 0, 0, 0);
}
self.view = contentView;
}
#pragma mark -
- (void)viewWillLayoutSubviews {
UIScrollView *dataView = self.usingTableViewToShowData ? _tableView : _collectionView;
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[dataView setContentInset:UIEdgeInsetsZero];
}
- (void)viewDidLoad
{
[super viewDidLoad];
......@@ -243,6 +241,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
_searchBar.delegate = self;
[self setSearchBar:YES resetContent:YES];
self.edgesForExtendedLayout = UIRectEdgeNone;
@synchronized (self) {
_searchData = [[NSMutableArray alloc] init];
......@@ -488,10 +487,22 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
[self updateViewsForCurrentDisplayMode];
}
- (void)setSearchBar:(BOOL)enable resetContent:(BOOL)resetContent
- (void)setViewFromDeviceOrientation
{
self.tableView.tableHeaderView = enable ? _searchBar : nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
UIDevice *currentDevice = [UIDevice currentDevice];
BOOL isPortrait = UIDeviceOrientationIsPortrait(currentDevice.orientation);
[self setUsingTableViewToShowData:isPortrait];
}
}
- (void)setSearchBar:(BOOL)enable resetContent:(BOOL)resetContent
{
if (enable)
self.tableView.tableHeaderView = _searchBar;
else
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, CGFLOAT_MIN)];
if (resetContent) {
CGPoint contentOffset = self.tableView.contentOffset;
contentOffset.y += CGRectGetHeight(self.tableView.tableHeaderView.frame);
......@@ -846,7 +857,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
const CGFloat maxCellWidth = 300.0;
const CGFloat maxCellWidth = [UIScreen mainScreen].bounds.size.width / 3;
const CGFloat aspectRatio = 9.0/16.0;
CGRect windowFrame = [UIApplication sharedApplication].keyWindow.frame;
......@@ -854,19 +865,19 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
int numberOfCellsPerRow = ceil(windowWidth/maxCellWidth);
CGFloat cellWidth = windowWidth/numberOfCellsPerRow;
cellWidth -= 5;
return CGSizeMake(cellWidth, cellWidth * aspectRatio);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsZero;
return UIEdgeInsetsMake(5, 5, 5, 5);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 0.;
return 2.5;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
......@@ -1662,6 +1673,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
[self setViewFromDeviceOrientation];
if (self.usingTableViewToShowData) {
NSArray *visibleCells = [self.tableView visibleCells];
NSUInteger cellCount = visibleCells.count;
......
......@@ -34,6 +34,7 @@
#import "VLCStatusLabel.h"
#import "VLCMovieViewControlPanelViewController.h"
#import "VLCSlider.h"
#import "VLCLibraryViewController.h"
#define FORWARD_SWIPE_DURATION 30
#define BACKWARD_SWIPE_DURATION 10
......@@ -1592,6 +1593,8 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[[(VLCAppDelegate *)[UIApplication sharedApplication].delegate libraryViewController] willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (self.artworkImageView.image)
self.trackNameLabel.hidden = UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
......
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