Commit adaee1a3 authored by Felix Paul Kühne's avatar Felix Paul Kühne

Server browsing collection view code: prepare for re-use

parent 2b4bf107
/*****************************************************************************
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
* Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import <UIKit/UIKit.h>
@interface VLCRemoteBrowsingCollectionViewController : UICollectionViewController
@end
/*****************************************************************************
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCRemoteBrowsingCollectionViewController.h"
#import "VLCRemoteBrowsingTVCell.h"
#import "VLCPlayerDisplayController.h"
#import "VLCPlaybackController.h"
#import "VLCServerBrowsingController.h"
#import "VLCMaskView.h"
@implementation VLCRemoteBrowsingCollectionViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)self.collectionViewLayout;
const CGFloat inset = 50;
flowLayout.sectionInset = UIEdgeInsetsMake(inset, inset, inset, inset);
[self.collectionView registerNib:[UINib nibWithNibName:@"VLCRemoteBrowsingTVCell" bundle:nil]
forCellWithReuseIdentifier:VLCRemoteBrowsingTVCellIdentifier];
self.collectionView.maskView = [[VLCMaskView alloc] initWithFrame:self.collectionView.bounds];
}
- (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 - collection view data source
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
VLCRemoteBrowsingTVCell *cell = (VLCRemoteBrowsingTVCell *)[collectionView dequeueReusableCellWithReuseIdentifier:VLCRemoteBrowsingTVCellIdentifier forIndexPath:indexPath];
return cell;
}
@end
<?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">
<document type="com.apple.InterfaceBuilder.AppleTV.XIB" version="3.0" toolsVersion="9527.1" systemVersion="15B42" targetRuntime="AppleTV" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9525.1"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="VLCServerBrowsingTVViewController">
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="VLCRemoteBrowsingCollectionViewController">
<connections>
<outlet property="collectionView" destination="NUi-8f-W1D" id="iDT-ID-8jS"/>
<outlet property="preferredFocusedView" destination="NUi-8f-W1D" id="mXv-Wn-Sh7"/>
......@@ -15,7 +15,6 @@
<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"/>
......
......@@ -13,9 +13,9 @@
#import "VLCServerBrowsingController.h"
#import "VLCNetworkImageView.h"
extern NSString *const VLCServerBrowsingTVCellIdentifier;
extern NSString *const VLCRemoteBrowsingTVCellIdentifier;
@interface VLCServerBrowsingTVCell : UICollectionViewCell <VLCServerBrowsingCell>
@interface VLCRemoteBrowsingTVCell : UICollectionViewCell <VLCRemoteBrowsingCell>
@property (nonatomic, weak) IBOutlet VLCNetworkImageView *thumbnailImageView;
@property (nonatomic, weak) IBOutlet UILabel *titleLabel;
......
......@@ -5,16 +5,17 @@
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
* Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCServerBrowsingTVCell.h"
#import "VLCRemoteBrowsingTVCell.h"
#import "MetaDataFetcherKit.h"
NSString *const VLCServerBrowsingTVCellIdentifier = @"VLCServerBrowsingTVCell";
NSString *const VLCRemoteBrowsingTVCellIdentifier = @"VLCRemoteBrowsingTVCell";
@interface VLCServerBrowsingTVCell () <MDFMovieDBFetcherDataRecipient>
@interface VLCRemoteBrowsingTVCell () <MDFMovieDBFetcherDataRecipient>
{
MDFMovieDBFetcher *_metadataFetcher;
}
......@@ -22,10 +23,9 @@ NSString *const VLCServerBrowsingTVCellIdentifier = @"VLCServerBrowsingTVCell";
@end
@implementation VLCServerBrowsingTVCell
@synthesize thumbnailURL = _thumbnailURL, isDirectory = _isDirectory;
@implementation VLCRemoteBrowsingTVCell
@synthesize thumbnailURL = _thumbnailURL, isDirectory = _isDirectory;
- (void)awakeFromNib
{
......@@ -145,7 +145,7 @@ NSString *const VLCServerBrowsingTVCellIdentifier = @"VLCServerBrowsingTVCell";
APLog(@"Failed to find a movie for '%@'", searchRequest);
}
-(void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFindTVShow:(MDFTVShow *)details forSearchRequest:(NSString *)searchRequest
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFindTVShow:(MDFTVShow *)details forSearchRequest:(NSString *)searchRequest
{
if (details == nil)
return;
......
<?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">
<document type="com.apple.InterfaceBuilder.AppleTV.XIB" version="3.0" toolsVersion="9527.1" systemVersion="15B42" targetRuntime="AppleTV" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9525.1"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" multipleTouchEnabled="YES" contentMode="center" id="Q7n-Zw-Frg" customClass="VLCServerBrowsingTVCell">
<collectionViewCell opaque="NO" multipleTouchEnabled="YES" contentMode="center" id="Q7n-Zw-Frg" customClass="VLCRemoteBrowsingTVCell">
<rect key="frame" x="0.0" y="0.0" width="300" height="300"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
......@@ -15,27 +15,22 @@
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h3U-B3-AOa">
<rect key="frame" x="8" y="202" width="284" height="30"/>
<animations/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="751" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="I51-60-pwl">
<rect key="frame" x="8" y="240" width="284" height="35"/>
<animations/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" placeholderIntrinsicWidth="300" placeholderIntrinsicHeight="169" adjustsImageWhenAncestorFocused="YES" translatesAutoresizingMaskIntoConstraints="NO" id="tHQ-sR-zn4" customClass="VLCNetworkImageView">
<rect key="frame" x="0.0" y="13" width="300" height="169"/>
<animations/>
</imageView>
</subviews>
<animations/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<animations/>
<constraints>
<constraint firstAttribute="trailing" secondItem="h3U-B3-AOa" secondAttribute="trailing" constant="8" id="Ge1-kn-QhB"/>
<constraint firstItem="I51-60-pwl" firstAttribute="leading" secondItem="Q7n-Zw-Frg" secondAttribute="leading" constant="8" id="H8p-nC-etm"/>
......
......@@ -10,8 +10,12 @@
*****************************************************************************/
#import <UIKit/UIKit.h>
#import "VLCRemoteBrowsingCollectionViewController.h"
#import "VLCNetworkServerBrowser-Protocol.h"
@interface VLCServerBrowsingTVViewController : UICollectionViewController <VLCNetworkServerBrowserDelegate>
@interface VLCServerBrowsingTVViewController : VLCRemoteBrowsingCollectionViewController <VLCNetworkServerBrowserDelegate>
- (instancetype)initWithServerBrowser:(id<VLCNetworkServerBrowser>)serverBrowser;
@end
......@@ -10,7 +10,7 @@
*****************************************************************************/
#import "VLCServerBrowsingTVViewController.h"
#import "VLCServerBrowsingTVCell.h"
#import "VLCRemoteBrowsingTVCell.h"
#import "VLCPlayerDisplayController.h"
#import "VLCPlaybackController.h"
#import "VLCServerBrowsingController.h"
......@@ -25,7 +25,7 @@
- (instancetype)initWithServerBrowser:(id<VLCNetworkServerBrowser>)serverBrowser
{
self = [super initWithNibName:@"VLCServerBrowsingTVViewController" bundle:nil];
self = [super initWithNibName:@"VLCRemoteBrowsingCollectionViewController" bundle:nil];
if (self) {
_serverBrowser = serverBrowser;
serverBrowser.delegate = self;
......@@ -37,60 +37,23 @@
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
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 {
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[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 {
- (void)reloadData
{
[self.serverBrowser update];
}
#pragma mark -
- (void)networkServerBrowserDidUpdate:(id<VLCNetworkServerBrowser>)networkBrowser {
- (void)networkServerBrowserDidUpdate:(id<VLCNetworkServerBrowser>)networkBrowser
{
self.title = networkBrowser.title;
[self.collectionView reloadData];
}
......@@ -128,18 +91,12 @@
return [self.serverBrowser items].count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
VLCServerBrowsingTVCell *cell = (VLCServerBrowsingTVCell *)[collectionView dequeueReusableCellWithReuseIdentifier:VLCServerBrowsingTVCellIdentifier forIndexPath:indexPath];
return cell;
}
- (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];
if ([cell conformsToProtocol:@protocol(VLCRemoteBrowsingCell)]) {
[self.browsingController configureCell:(id<VLCRemoteBrowsingCell>)cell withItem:item];
}
}
......
......@@ -15,7 +15,7 @@
#define DOWNLOAD_SUPPORTED TARGET_OS_IOS
NS_ASSUME_NONNULL_BEGIN
@protocol VLCServerBrowsingCell <NSObject>
@protocol VLCRemoteBrowsingCell <NSObject>
@property (nonatomic, nullable) NSString *title;
@property (nonatomic, nullable) NSString *subtitle;
......@@ -43,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithViewController:(UIViewController *)viewController serverBrowser:(id<VLCNetworkServerBrowser>)browser;
- (void)configureCell:(id<VLCServerBrowsingCell>)cell withItem:(id<VLCNetworkServerBrowserItem>)item;
- (void)configureCell:(id<VLCRemoteBrowsingCell>)cell withItem:(id<VLCNetworkServerBrowserItem>)item;
#pragma mark - Subtitles
- (void)configureSubtitlesInMediaList:(VLCMediaList *)mediaList;
......
......@@ -71,7 +71,7 @@
#pragma mark - cell configuration
- (void)configureCell:(id<VLCServerBrowsingCell>)cell withItem:(id<VLCNetworkServerBrowserItem>)item
- (void)configureCell:(id<VLCRemoteBrowsingCell>)cell withItem:(id<VLCNetworkServerBrowserItem>)item
{
if (item.isContainer) {
cell.isDirectory = YES;
......
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