Commit 7ec325ca authored by Felix Paul Kühne's avatar Felix Paul Kühne

remote playback: use collection view to show cache media

parent 891baf23
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder.AppleTV.XIB" version="3.0" toolsVersion="9527.1" systemVersion="15B42" targetRuntime="AppleTV" propertyAccessControl="none" useAutolayout="YES">
<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="9525.1"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="VLCRemoteBrowsingCollectionViewController">
......
......@@ -10,6 +10,7 @@
*****************************************************************************/
#import <UIKit/UIKit.h>
#import "VLCRemoteBrowsingCollectionViewController.h"
@interface VLCRemotePlaybackViewController : UIViewController
......@@ -17,7 +18,7 @@
@property (readwrite, nonatomic, weak) IBOutlet UIButton *toggleHTTPServerButton;
@property (readwrite, nonatomic, weak) IBOutlet UILabel *cachedMediaLabel;
@property (readwrite, nonatomic, weak) IBOutlet UITableView *cachedMediaTableView;
@property (readwrite, nonatomic, weak) IBOutlet UICollectionView *cachedMediaCollectionView;
- (IBAction)toggleHTTPServer:(id)sender;
......
......@@ -13,10 +13,12 @@
#import "Reachability.h"
#import "VLCHTTPUploaderController.h"
#import "VLCMediaFileDiscoverer.h"
#import "VLCRemoteBrowsingTVCell.h"
#import "VLCMaskView.h"
#define remotePlaybackReuseIdentifer @"remotePlaybackReuseIdentifer"
@interface VLCRemotePlaybackViewController () <UITableViewDataSource, UITableViewDelegate, VLCMediaFileDiscovererDelegate>
@interface VLCRemotePlaybackViewController () <UICollectionViewDataSource, UICollectionViewDelegate, VLCMediaFileDiscovererDelegate>
{
Reachability *_reachability;
NSMutableArray *_discoveredFiles;
......@@ -34,6 +36,15 @@
{
[super viewDidLoad];
UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)self.cachedMediaCollectionView.collectionViewLayout;
const CGFloat inset = 50.;
flowLayout.sectionInset = UIEdgeInsetsMake(inset, inset, inset, inset);
flowLayout.itemSize = CGSizeMake(250.0, 300.0);
flowLayout.minimumInteritemSpacing = 48.0;
flowLayout.minimumLineSpacing = 100.0;
[self.cachedMediaCollectionView registerNib:[UINib nibWithNibName:@"VLCRemoteBrowsingTVCell" bundle:nil]
forCellWithReuseIdentifier:VLCRemoteBrowsingTVCellIdentifier];
_reachability = [Reachability reachabilityForLocalWiFi];
self.httpServerLabel.textColor = [UIColor VLCDarkBackgroundColor];
......@@ -53,6 +64,31 @@
[discoverer startDiscovering];
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
UICollectionView *collectionView = self.cachedMediaCollectionView;
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 = collectionView.bounds.size;
maskView.frame = CGRectMake(0, collectionView.contentOffset.y, collectionViewSize.width, collectionViewSize.height);
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
......@@ -96,20 +132,21 @@
[[NSUserDefaults standardUserDefaults] synchronize];
}
#pragma mark - table view data source
#pragma mark - collection view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
return 1;
VLCRemoteBrowsingTVCell *cell = (VLCRemoteBrowsingTVCell *)[collectionView dequeueReusableCellWithReuseIdentifier:VLCRemoteBrowsingTVCellIdentifier forIndexPath:indexPath];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:remotePlaybackReuseIdentifer];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:remotePlaybackReuseIdentifer];
}
return 1;
}
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(VLCRemoteBrowsingTVCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellTitle;
NSUInteger row = indexPath.row;
@synchronized(_discoveredFiles) {
......@@ -118,12 +155,13 @@
}
}
cell.textLabel.text = cellTitle;
cell.imageView.image = [UIImage imageNamed:@"blank"];
return cell;
[cell prepareForReuse];
[cell setIsDirectory:NO];
[cell setThumbnailImage:[UIImage imageNamed:@"blank"]];
[cell setTitle:cellTitle];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSUInteger ret;
......@@ -134,12 +172,10 @@
return ret;
}
#pragma mark - table view delegate
#pragma mark - collection view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
NSURL *url;
@synchronized(_discoveredFiles) {
......@@ -154,31 +190,28 @@
#pragma mark - media file discovery
- (void)mediaFilesFoundRequiringAdditionToStorageBackend:(NSArray<NSString *> *)foundFiles
{
NSLog(@"Found files %@", foundFiles);
@synchronized(_discoveredFiles) {
_discoveredFiles = [NSMutableArray arrayWithArray:foundFiles];
}
[self.cachedMediaTableView reloadData];
[self.cachedMediaCollectionView reloadData];
}
- (void)mediaFileAdded:(NSString *)filePath loading:(BOOL)isLoading
{
@synchronized(_discoveredFiles) {
if ([_discoveredFiles indexOfObjectIdenticalTo:filePath] == NSNotFound) {
if (![_discoveredFiles containsObject:filePath]) {
[_discoveredFiles addObject:filePath];
}
}
[self.cachedMediaTableView reloadData];
[self.cachedMediaCollectionView reloadData];
}
- (void)mediaFileDeleted:(NSString *)filePath
{
NSLog(@"removed file %@", filePath);
@synchronized(_discoveredFiles) {
[_discoveredFiles removeObjectIdenticalTo:filePath];
[_discoveredFiles removeObject:filePath];
}
[self.cachedMediaTableView reloadData];
[self.cachedMediaCollectionView reloadData];
}
@end
......@@ -6,8 +6,8 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="VLCRemotePlaybackViewController">
<connections>
<outlet property="cachedMediaCollectionView" destination="VjG-Gw-i36" id="ATe-7D-fDz"/>
<outlet property="cachedMediaLabel" destination="77q-qM-GSv" id="gs2-sW-Z17"/>
<outlet property="cachedMediaTableView" destination="WfO-PV-wWU" id="eAC-TD-XyD"/>
<outlet property="httpServerLabel" destination="mOM-K1-6hX" id="PvM-0r-xq1"/>
<outlet property="toggleHTTPServerButton" destination="N4Q-4c-bh0" id="5Je-Lj-ba0"/>
<outlet property="view" destination="iN0-l3-epB" id="Eym-vH-oyN"/>
......@@ -37,37 +37,41 @@ http://192.168.1.1</string>
<action selector="toggleHTTPServer:" destination="-1" eventType="primaryActionTriggered" id="65K-IM-LdJ"/>
</connections>
</button>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="66" sectionHeaderHeight="40" sectionFooterHeight="40" translatesAutoresizingMaskIntoConstraints="NO" id="WfO-PV-wWU">
<rect key="frame" x="183" y="660" width="1555" height="350"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" constant="1555" id="7ob-FN-Pyb"/>
<constraint firstAttribute="height" constant="350" id="NRR-JN-TcZ"/>
</constraints>
<connections>
<outlet property="dataSource" destination="-1" id="f0f-ZE-xAG"/>
<outlet property="delegate" destination="-1" id="KRu-Hq-2VH"/>
</connections>
</tableView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Cached Media" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="77q-qM-GSv">
<rect key="frame" x="837" y="544" width="246" height="46"/>
<rect key="frame" x="837" y="514" width="246" height="46"/>
<animations/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="VjG-Gw-i36">
<rect key="frame" x="0.0" y="630" width="1920" height="450"/>
<animations/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="pP2-ie-8Sr">
<size key="itemSize" width="50" height="50"/>
<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="5CW-nY-7m4"/>
<outlet property="delegate" destination="-1" id="hUM-OV-Y9o"/>
</connections>
</collectionView>
</subviews>
<animations/>
<constraints>
<constraint firstItem="WfO-PV-wWU" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="CNP-DM-grr"/>
<constraint firstItem="N4Q-4c-bh0" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="193" id="Dsp-yk-pru"/>
<constraint firstItem="77q-qM-GSv" firstAttribute="top" secondItem="mOM-K1-6hX" secondAttribute="bottom" constant="86" id="PQh-oO-VDm"/>
<constraint firstItem="mOM-K1-6hX" firstAttribute="centerX" secondItem="N4Q-4c-bh0" secondAttribute="centerX" id="ScU-iV-uMa"/>
<constraint firstItem="mOM-K1-6hX" firstAttribute="top" secondItem="N4Q-4c-bh0" secondAttribute="bottom" constant="36" id="Szw-br-TIc"/>
<constraint firstItem="77q-qM-GSv" firstAttribute="centerX" secondItem="VjG-Gw-i36" secondAttribute="centerX" id="Tcb-Jy-an4"/>
<constraint firstItem="N4Q-4c-bh0" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="VFF-HR-rhV"/>
<constraint firstAttribute="bottom" secondItem="WfO-PV-wWU" secondAttribute="bottom" constant="70" id="f6B-oF-hIP"/>
<constraint firstItem="WfO-PV-wWU" firstAttribute="top" secondItem="77q-qM-GSv" secondAttribute="bottom" constant="70" id="uW6-vD-T7X"/>
<constraint firstItem="77q-qM-GSv" firstAttribute="centerX" secondItem="WfO-PV-wWU" secondAttribute="centerX" id="xSw-ba-1ov"/>
<constraint firstItem="VjG-Gw-i36" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="hSa-3P-bGw"/>
<constraint firstItem="VjG-Gw-i36" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="l72-n9-cwb"/>
<constraint firstAttribute="trailing" secondItem="VjG-Gw-i36" secondAttribute="trailing" id="lJF-jb-gaz"/>
<constraint firstItem="VjG-Gw-i36" firstAttribute="top" secondItem="77q-qM-GSv" secondAttribute="bottom" constant="70" id="nNF-vd-238"/>
<constraint firstAttribute="bottom" secondItem="VjG-Gw-i36" secondAttribute="bottom" id="v0P-HU-3wm"/>
</constraints>
</view>
</objects>
......
......@@ -144,7 +144,6 @@
[self didSelectService:service];
}
#pragma mark - Service specific stuff
- (void)didSelectService:(id<VLCLocalNetworkService>)service
......
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