Commit 6dfb787f authored by Tobias's avatar Tobias

replace server browsing table view with collection view

parent db409886
//
// VLCMaskView.h
// VLC for iOS
//
// Created by Tobias Conradi on 07.11.15.
// Copyright © 2015 VideoLAN. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface VLCMaskView : UIView
@property (nonatomic) CGFloat maskStart;
@property (nonatomic) CGFloat maskEnd;
@end
//
// VLCMaskView.m
// VLC for iOS
//
// Created by Tobias Conradi on 07.11.15.
// Copyright © 2015 VideoLAN. All rights reserved.
//
#import "VLCMaskView.h"
#import <QuartzCore/QuartzCore.h>
@interface VLCMaskView()
@property (nonatomic) CAGradientLayer *gradientLayer;
@end
@implementation VLCMaskView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self.layer addSublayer:self.gradientLayer];
[self updateGradientLayer];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self.layer addSublayer:self.gradientLayer];
[self updateGradientLayer];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
[self updateGradientLayer];
}
- (void)updateGradientLayer
{
CGSize size = self.bounds.size;
CGFloat height = size.height;
self.gradientLayer.frame = CGRectMake(0, 0, size.width, height);
self.gradientLayer.locations = @[@(self.maskEnd / height), @(self.maskStart / height)];
}
#pragma mark - Properties
- (CAGradientLayer *)gradientLayer
{
if (!_gradientLayer) {
_gradientLayer = [CAGradientLayer layer];
_gradientLayer.colors = @[(id)[UIColor colorWithWhite:0.0 alpha:0.0].CGColor, (id)[UIColor colorWithWhite:0.0 alpha:1.0].CGColor];
}
return _gradientLayer;
}
- (void)setMaskStart:(CGFloat)maskStart
{
_maskStart = maskStart;
[self updateGradientLayer];
}
- (void)setMaskEnd:(CGFloat)maskEnd
{
_maskEnd = maskEnd;
[self updateGradientLayer];
}
@end
......@@ -15,7 +15,7 @@
extern NSString *const VLCServerBrowsingTVCellIdentifier;
@interface VLCServerBrowsingTVCell : UITableViewCell <VLCServerBrowsingCell>
@interface VLCServerBrowsingTVCell : UICollectionViewCell <VLCServerBrowsingCell>
@property (nonatomic, weak) IBOutlet VLCNetworkImageView *thumbnailImageView;
@property (nonatomic, weak) IBOutlet UILabel *titleLabel;
......
......@@ -18,15 +18,13 @@ NSString *const VLCServerBrowsingTVCellIdentifier = @"VLCServerBrowsingTVCell";
{
MDFMovieDBFetcher *_metadataFetcher;
}
@property (nonatomic) IBOutlet NSLayoutConstraint *aspectRationConstraint;
@end
@implementation VLCServerBrowsingTVCell
@synthesize thumbnailURL = _thumbnailURL, isDirectory = _isDirectory;
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
return [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
}
- (void)awakeFromNib
......@@ -96,6 +94,15 @@ NSString *const VLCServerBrowsingTVCellIdentifier = @"VLCServerBrowsingTVCell";
return self.subtitleLabel.text;
}
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
{
[coordinator addCoordinatedAnimations:^{
self.transform = self.focused ? CGAffineTransformMakeScale(1.3, 1.3): CGAffineTransformIdentity;
} completion:nil];
}
#pragma mark - MDFMovieDB
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFindMovie:(MDFMovie *)details forSearchRequest:(NSString *)searchRequest
{
if (details == nil)
......
......@@ -11,7 +11,7 @@
#import <UIKit/UIKit.h>
#import "VLCNetworkServerBrowser-Protocol.h"
@interface VLCServerBrowsingTVTableViewController : UITableViewController <VLCNetworkServerBrowserDelegate>
@interface VLCServerBrowsingTVViewController : UICollectionViewController <VLCNetworkServerBrowserDelegate>
- (instancetype)initWithServerBrowser:(id<VLCNetworkServerBrowser>)serverBrowser;
@end
......@@ -9,23 +9,23 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCServerBrowsingTVTableViewController.h"
#import "VLCServerBrowsingTVViewController.h"
#import "VLCServerBrowsingTVCell.h"
#import "VLCPlayerDisplayController.h"
#import "VLCPlaybackController.h"
#import "VLCServerBrowsingController.h"
#import "VLCMaskView.h"
@interface VLCServerBrowsingTVTableViewController ()
@interface VLCServerBrowsingTVViewController ()
@property (nonatomic, readonly) id<VLCNetworkServerBrowser>serverBrowser;
@property (nonatomic) VLCServerBrowsingController *browsingController;
@end
@implementation VLCServerBrowsingTVTableViewController
@implementation VLCServerBrowsingTVViewController
- (instancetype)initWithServerBrowser:(id<VLCNetworkServerBrowser>)serverBrowser
{
self = [super init];
self = [super initWithNibName:@"VLCServerBrowsingTVViewController" bundle:nil];
if (self) {
_serverBrowser = serverBrowser;
serverBrowser.delegate = self;
......@@ -37,11 +37,17 @@
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.rowHeight = 150;
[self.tableView registerNib:[UINib nibWithNibName:@"VLCServerBrowsingTVCell" bundle:nil] forCellReuseIdentifier:VLCServerBrowsingTVCellIdentifier];
UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)self.collectionViewLayout;
const CGFloat inset = 50;
flowLayout.sectionInset = UIEdgeInsetsMake(inset, inset, inset, inset);
[self.collectionView registerNib:[UINib nibWithNibName:@"VLCServerBrowsingTVCell" bundle:nil] forCellWithReuseIdentifier:VLCServerBrowsingTVCellIdentifier];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(reloadData)];
self.collectionView.maskView = [[VLCMaskView alloc] initWithFrame:self.collectionView.bounds];
}
- (void)viewDidAppear:(BOOL)animated {
......@@ -49,6 +55,33 @@
[self.serverBrowser update];
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
UICollectionView *collectionView = self.collectionView;
VLCMaskView *maskView = (VLCMaskView *)collectionView.maskView;
maskView.maskEnd = self.topLayoutGuide.length * 0.8;
/*
Update the position from where the collection view's content should
start to fade out. The size of the fade increases as the collection
view scrolls to a maximum of half the navigation bar's height.
*/
CGFloat maximumMaskStart = maskView.maskEnd + (self.topLayoutGuide.length * 0.5);
CGFloat verticalScrollPosition = MAX(0, collectionView.contentOffset.y + collectionView.contentInset.top);
maskView.maskStart = MIN(maximumMaskStart, maskView.maskEnd + verticalScrollPosition);
/*
Position the mask view so that it is always fills the visible area of
the collection view.
*/
CGSize collectionViewSize = self.collectionView.bounds.size;
maskView.frame = CGRectMake(0, collectionView.contentOffset.y, collectionViewSize.width, collectionViewSize.height);
}
#pragma mark -
- (void)reloadData {
......@@ -59,7 +92,7 @@
- (void)networkServerBrowserDidUpdate:(id<VLCNetworkServerBrowser>)networkBrowser {
self.title = networkBrowser.title;
[self.tableView reloadData];
[self.collectionView reloadData];
}
- (void)networkServerBrowser:(id<VLCNetworkServerBrowser>)networkBrowser requestDidFailWithError:(NSError *)error {
......@@ -74,7 +107,7 @@
- (void)didSelectItem:(id<VLCNetworkServerBrowserItem>)item index:(NSUInteger)index singlePlayback:(BOOL)singlePlayback
{
if (item.isContainer) {
VLCServerBrowsingTVTableViewController *targetViewController = [[VLCServerBrowsingTVTableViewController alloc] initWithServerBrowser:item.containerBrowser];
VLCServerBrowsingTVViewController *targetViewController = [[VLCServerBrowsingTVViewController alloc] initWithServerBrowser:item.containerBrowser];
[self.navigationController pushViewController:targetViewController animated:YES];
} else {
if (singlePlayback) {
......@@ -87,25 +120,31 @@
}
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#pragma mark - collection view data source
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [self.serverBrowser items].count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
VLCServerBrowsingTVCell *cell = (VLCServerBrowsingTVCell *)[tableView dequeueReusableCellWithIdentifier:VLCServerBrowsingTVCellIdentifier];
if (!cell) {
cell = [[VLCServerBrowsingTVCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:VLCServerBrowsingTVCellIdentifier];
}
id<VLCNetworkServerBrowserItem> item = self.serverBrowser.items[indexPath.row];
[self.browsingController configureCell:cell withItem:item];
VLCServerBrowsingTVCell *cell = (VLCServerBrowsingTVCell *)[collectionView dequeueReusableCellWithReuseIdentifier:VLCServerBrowsingTVCellIdentifier forIndexPath:indexPath];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
id<VLCNetworkServerBrowserItem> item = self.serverBrowser.items[indexPath.row];
if ([cell conformsToProtocol:@protocol(VLCServerBrowsingCell)]) {
[self.browsingController configureCell:(id<VLCServerBrowsingCell>)cell withItem:item];
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = indexPath.row;
id<VLCNetworkServerBrowserItem> item = self.serverBrowser.items[row];
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder.AppleTV.XIB" version="3.0" toolsVersion="9059" systemVersion="15B42" targetRuntime="AppleTV" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="VLCServerBrowsingTVViewController">
<connections>
<outlet property="collectionView" destination="NUi-8f-W1D" id="iDT-ID-8jS"/>
<outlet property="preferredFocusedView" destination="NUi-8f-W1D" id="mXv-Wn-Sh7"/>
<outlet property="view" destination="NUi-8f-W1D" id="oDs-Vy-NyX"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="none" id="NUi-8f-W1D">
<rect key="frame" x="0.0" y="0.0" width="1920" height="1080"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="50" minimumInteritemSpacing="50" id="o9k-mG-llf">
<size key="itemSize" width="300" height="300"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
<connections>
<outlet property="dataSource" destination="-1" id="Jwj-RD-1Py"/>
<outlet property="delegate" destination="-1" id="Ng7-Ok-jZx"/>
</connections>
</collectionView>
</objects>
</document>
......@@ -11,7 +11,7 @@
#import "VLCServerListTVTableViewController.h"
#import "VLCLocalNetworkServerTVCell.h"
#import "VLCServerBrowsingTVTableViewController.h"
#import "VLCServerBrowsingTVViewController.h"
#import "VLCNetworkServerLoginInformation.h"
#import "VLCNetworkServerBrowserPlex.h"
......@@ -124,7 +124,7 @@
if ([service respondsToSelector:@selector(serverBrowser)]) {
id <VLCNetworkServerBrowser> browser = [service serverBrowser];
if (browser) {
VLCServerBrowsingTVTableViewController *browsingViewController = [[VLCServerBrowsingTVTableViewController alloc] initWithServerBrowser:browser];
VLCServerBrowsingTVViewController *browsingViewController = [[VLCServerBrowsingTVViewController alloc] initWithServerBrowser:browser];
[self presentViewController:[[UINavigationController alloc] initWithRootViewController:browsingViewController]
animated:YES
completion:nil];
......@@ -229,7 +229,7 @@
}
if (serverBrowser) {
VLCServerBrowsingTVTableViewController *targetViewController = [[VLCServerBrowsingTVTableViewController alloc] initWithServerBrowser:serverBrowser];
VLCServerBrowsingTVViewController *targetViewController = [[VLCServerBrowsingTVViewController alloc] initWithServerBrowser:serverBrowser];
[self presentViewController:[[UINavigationController alloc] initWithRootViewController:targetViewController]
animated:YES
completion:nil];
......
This diff is collapsed.
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