Commit 6d1280b1 authored by Tobias's avatar Tobias

use ServerBrowsingController in ServerBrowsingTVTableViewController

add new ServerBrowsingTVCell with NetworkImageView
parent 00ac52e7
......@@ -40,6 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) id<VLCNetworkServerBrowser> serverBrowser;
@property (nonatomic, weak, nullable, readonly) UIViewController *viewController;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithViewController:(UIViewController *)viewController serverBrowser:(id<VLCNetworkServerBrowser>)browser;
- (void)configureCell:(id<VLCServerBrowsingCell>)cell withItem:(id<VLCNetworkServerBrowserItem>)item;
......
......@@ -40,7 +40,7 @@
if (self) {
_serverBrowser = browser;
browser.delegate = self;
_browsingController = [[VLCServerBrowsingController alloc] init];
_browsingController = [[VLCServerBrowsingController alloc] initWithViewController:self serverBrowser:browser];
_browsingController.allowsFileDownload = YES;
}
return self;
......
......@@ -10,9 +10,13 @@
*****************************************************************************/
#import <UIKit/UIKit.h>
#import "VLCServerBrowsingController.h"
#import "VLCNetworkImageView.h"
extern NSString *const VLCServerBrowsingTVCellIdentifier;
@interface VLCServerBrowsingTVCell : UITableViewCell
@interface VLCServerBrowsingTVCell : UITableViewCell <VLCServerBrowsingCell>
@property (nonatomic, weak) IBOutlet VLCNetworkImageView *thumbnailImageView;
@property (nonatomic, weak) IBOutlet UILabel *titleLabel;
@property (nonatomic, weak) IBOutlet UILabel *subtitleLabel;
@end
......@@ -14,7 +14,34 @@
NSString *const VLCServerBrowsingTVCellIdentifier = @"VLCServerBrowsingTVCell";
@implementation VLCServerBrowsingTVCell
@synthesize thumbnailURL = _thumbnailURL, isDirectory = _isDirectory;
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
return [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
}
- (void)setThumbnailURL:(NSURL *)thumbnailURL {
_thumbnailURL = thumbnailURL;
[self.thumbnailImageView setImageWithURL:thumbnailURL];
}
- (void)setThumbnailImage:(UIImage *)thumbnailImage {
[self.thumbnailImageView setImage:thumbnailImage];
}
-(UIImage *)thumbnailImage {
return self.thumbnailImageView.image;
}
- (void)setTitle:(NSString *)title {
self.titleLabel.text = title;
}
- (NSString *)title {
return self.titleLabel.text;
}
- (void)setSubtitle:(NSString *)subtitle {
self.subtitleLabel.text = subtitle;
}
- (NSString *)subtitle {
return self.subtitleLabel.text;
}
@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">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="150" id="Tcc-PQ-zMX" customClass="VLCServerBrowsingTVCell">
<rect key="frame" x="0.0" y="0.0" width="1920" height="150"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Tcc-PQ-zMX" id="Ygk-DT-1Ta">
<rect key="frame" x="0.0" y="0.0" width="1920" height="150"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Diw-kq-1Zk" customClass="VLCNetworkImageView">
<rect key="frame" x="8" y="8" width="238" height="134"/>
<animations/>
<constraints>
<constraint firstAttribute="width" secondItem="Diw-kq-1Zk" secondAttribute="height" multiplier="16:9" id="y1w-5g-IDp"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TIO-jK-60o" userLabel="TitleLabel">
<rect key="frame" x="254" y="8" width="1658" height="46"/>
<animations/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<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="300" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4q6-BG-uo0" userLabel="SubtitleLabel">
<rect key="frame" x="254" y="112" width="1658" 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>
</subviews>
<animations/>
<constraints>
<constraint firstItem="4q6-BG-uo0" firstAttribute="top" relation="greaterThanOrEqual" secondItem="TIO-jK-60o" secondAttribute="bottom" id="0Cw-Zg-YdT"/>
<constraint firstItem="4q6-BG-uo0" firstAttribute="leading" secondItem="Diw-kq-1Zk" secondAttribute="trailing" constant="8" symbolic="YES" id="4JT-bL-xgJ"/>
<constraint firstAttribute="trailingMargin" secondItem="4q6-BG-uo0" secondAttribute="trailing" id="D8M-Ob-ojk"/>
<constraint firstItem="TIO-jK-60o" firstAttribute="top" secondItem="Ygk-DT-1Ta" secondAttribute="topMargin" id="PdB-cs-3vU"/>
<constraint firstItem="TIO-jK-60o" firstAttribute="leading" secondItem="Diw-kq-1Zk" secondAttribute="trailing" constant="8" symbolic="YES" id="Tbh-RC-OQm"/>
<constraint firstAttribute="bottomMargin" secondItem="Diw-kq-1Zk" secondAttribute="bottom" id="VIf-rD-KS8"/>
<constraint firstItem="Diw-kq-1Zk" firstAttribute="leading" secondItem="Ygk-DT-1Ta" secondAttribute="leadingMargin" id="Z1h-4m-nw8"/>
<constraint firstAttribute="trailingMargin" secondItem="TIO-jK-60o" secondAttribute="trailing" id="dcO-hV-zoC"/>
<constraint firstItem="4q6-BG-uo0" firstAttribute="bottom" secondItem="Ygk-DT-1Ta" secondAttribute="bottomMargin" id="fxP-Kg-4vy"/>
<constraint firstItem="Diw-kq-1Zk" firstAttribute="top" secondItem="Ygk-DT-1Ta" secondAttribute="topMargin" id="mfh-x3-2Cc"/>
</constraints>
</tableViewCellContentView>
<animations/>
<connections>
<outlet property="subtitleLabel" destination="4q6-BG-uo0" id="ST7-jm-Fva"/>
<outlet property="thumbnailImageView" destination="Diw-kq-1Zk" id="kfh-1g-s9S"/>
<outlet property="titleLabel" destination="TIO-jK-60o" id="ZV5-Ww-sG3"/>
</connections>
<point key="canvasLocation" x="152" y="-196.5"/>
</tableViewCell>
</objects>
</document>
......@@ -13,10 +13,11 @@
#import "VLCServerBrowsingTVCell.h"
#import "VLCPlayerDisplayController.h"
#import "VLCPlaybackController.h"
#import "VLCServerBrowsingController.h"
@interface VLCServerBrowsingTVTableViewController ()
@property (nonatomic, readonly) id<VLCNetworkServerBrowser>serverBrowser;
@property (nonatomic) NSByteCountFormatter *byteCounterFormatter;
@property (nonatomic) VLCServerBrowsingController *browsingController;
@end
......@@ -28,6 +29,9 @@
if (self) {
_serverBrowser = serverBrowser;
serverBrowser.delegate = self;
_browsingController = [[VLCServerBrowsingController alloc] initWithViewController:self serverBrowser:serverBrowser];
self.title = serverBrowser.title;
}
return self;
......@@ -35,8 +39,8 @@
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[VLCServerBrowsingTVCell class] forCellReuseIdentifier:VLCServerBrowsingTVCellIdentifier];
self.tableView.rowHeight = 150;
[self.tableView registerNib:[UINib nibWithNibName:@"VLCServerBrowsingTVCell" bundle:nil] forCellReuseIdentifier:VLCServerBrowsingTVCellIdentifier];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(reloadData)];
}
......@@ -60,89 +64,44 @@
- (void)networkServerBrowser:(id<VLCNetworkServerBrowser>)networkBrowser requestDidFailWithError:(NSError *)error {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"LOCAL_SERVER_CONNECTION_FAILED_TITLE", nil)
message:NSLocalizedString(@"LOCAL_SERVER_CONNECTION_FAILED_MESSAGE", nil)
preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
style:UIAlertActionStyleCancel
handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
[self vlc_showAlertWithTitle:NSLocalizedString(@"LOCAL_SERVER_CONNECTION_FAILED_TITLE", nil)
message:NSLocalizedString(@"LOCAL_SERVER_CONNECTION_FAILED_MESSAGE", nil)
buttonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)];
}
#pragma mark -
- (NSByteCountFormatter *)byteCounterFormatter {
if (!_byteCounterFormatter) {
_byteCounterFormatter = [[NSByteCountFormatter alloc] init];
- (void)didSelectItem:(id<VLCNetworkServerBrowserItem>)item index:(NSUInteger)index singlePlayback:(BOOL)singlePlayback
{
if (item.isContainer) {
VLCServerBrowsingTVTableViewController *targetViewController = [[VLCServerBrowsingTVTableViewController alloc] initWithServerBrowser:item.containerBrowser];
[self.navigationController pushViewController:targetViewController animated:YES];
} else {
if (singlePlayback) {
[self.browsingController streamFileForItem:item];
} else {
VLCMediaList *mediaList = self.serverBrowser.mediaList;
[self.browsingController configureSubtitlesInMediaList:mediaList];
[self.browsingController streamMediaList:mediaList startingAtIndex:index];
}
}
return _byteCounterFormatter;
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.serverBrowser items].count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
VLCServerBrowsingTVCell *cell = [tableView dequeueReusableCellWithIdentifier:VLCServerBrowsingTVCellIdentifier forIndexPath:indexPath];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(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];
cell.textLabel.text = item.name;
if (item.isContainer) {
// cell.isDirectory = YES;
cell.imageView.image = [UIImage imageNamed:@"folder"];
} else {
// cell.isDirectory = NO;
cell.imageView.image = [UIImage imageNamed:@"blank"];
NSString *sizeString = item.fileSizeBytes ? [self.byteCounterFormatter stringFromByteCount:item.fileSizeBytes.longLongValue] : nil;
NSString *duration = nil;
if ([item respondsToSelector:@selector(duration)]) {
duration = item.duration;
}
NSString *subtitle = nil;
if (sizeString && duration) {
subtitle = [NSString stringWithFormat:@"%@ (%@)",sizeString, duration];
} else if (sizeString) {
subtitle = sizeString;
} else if (duration) {
subtitle = duration;
}
cell.detailTextLabel.text = sizeString;
// cell.isDownloadable = YES;
// cell.delegate = self;
NSURL *thumbnailURL = nil;
if ([item respondsToSelector:@selector(thumbnailURL)]) {
thumbnailURL = item.thumbnailURL;
}
// if (thumbnailURL) {
// dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
// dispatch_async(queue, ^{
// UIImage *img = [self getCachedImage:thumbnailURL];
// dispatch_async(dispatch_get_main_queue(), ^{
// if (img) {
// [cell setIcon:img];
// }
// });
// });
// }
}
[self.browsingController configureCell:cell withItem:item];
return cell;
}
......@@ -150,16 +109,12 @@
NSInteger row = indexPath.row;
id<VLCNetworkServerBrowserItem> item = self.serverBrowser.items[row];
if (item.isContainer) {
VLCServerBrowsingTVTableViewController *browsingViewController = [[VLCServerBrowsingTVTableViewController alloc] initWithServerBrowser:[item containerBrowser]];
[self showViewController:browsingViewController sender:nil];
} else {
[VLCPlayerDisplayController sharedInstance].displayMode = VLCPlayerDisplayControllerDisplayModeFullscreen;
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
// would make sence if item came from search which isn't
// currently the case on the TV
const BOOL singlePlayback = NO;
[self didSelectItem:item index:row singlePlayback:singlePlayback];
VLCMediaList *mediaList = self.serverBrowser.mediaList;
[vpc playMediaList:mediaList firstIndex:row];
}
}
@end
......@@ -283,6 +283,7 @@
DD3EAC051BE153B4003668DA /* VLCNetworkImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD3EAC031BE153B4003668DA /* VLCNetworkImageView.m */; };
DD3EAC091BE2192A003668DA /* VLCServerBrowsingController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD3EAC081BE2192A003668DA /* VLCServerBrowsingController.m */; };
DD3EAC0A1BE2192A003668DA /* VLCServerBrowsingController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD3EAC081BE2192A003668DA /* VLCServerBrowsingController.m */; };
DD3EAC131BE26166003668DA /* VLCServerBrowsingTVCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DD3EAC121BE26166003668DA /* VLCServerBrowsingTVCell.xib */; };
DD3EFEED1BDEBA3800B68579 /* VLCNetworkServerBrowserViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD3EFEEA1BDEBA3800B68579 /* VLCNetworkServerBrowserViewController.m */; };
DD3EFEEE1BDEBA3800B68579 /* VLCServerListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD3EFEEC1BDEBA3800B68579 /* VLCServerListViewController.m */; };
DD3EFF2D1BDEBCE500B68579 /* VLCLocalNetworkServiceBrowserFTP.m in Sources */ = {isa = PBXBuildFile; fileRef = DD3EFEF21BDEBCE500B68579 /* VLCLocalNetworkServiceBrowserFTP.m */; };
......@@ -928,6 +929,7 @@
DD3EAC031BE153B4003668DA /* VLCNetworkImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCNetworkImageView.m; path = "UI Elements/VLCNetworkImageView.m"; sourceTree = "<group>"; };
DD3EAC071BE2192A003668DA /* VLCServerBrowsingController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCServerBrowsingController.h; sourceTree = "<group>"; };
DD3EAC081BE2192A003668DA /* VLCServerBrowsingController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCServerBrowsingController.m; sourceTree = "<group>"; };
DD3EAC121BE26166003668DA /* VLCServerBrowsingTVCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = VLCServerBrowsingTVCell.xib; sourceTree = "<group>"; };
DD3EFEE91BDEBA3800B68579 /* VLCNetworkServerBrowserViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCNetworkServerBrowserViewController.h; path = Sources/LocalNetworkConnectivity/VLCNetworkServerBrowserViewController.h; sourceTree = SOURCE_ROOT; };
DD3EFEEA1BDEBA3800B68579 /* VLCNetworkServerBrowserViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCNetworkServerBrowserViewController.m; path = Sources/LocalNetworkConnectivity/VLCNetworkServerBrowserViewController.m; sourceTree = SOURCE_ROOT; };
DD3EFEEB1BDEBA3800B68579 /* VLCServerListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCServerListViewController.h; path = Sources/LocalNetworkConnectivity/VLCServerListViewController.h; sourceTree = SOURCE_ROOT; };
......@@ -1769,6 +1771,7 @@
isa = PBXGroup;
children = (
7D6069711BD94AD600AB765C /* VLCCloudStorageTableViewCell.xib */,
DD3EAC121BE26166003668DA /* VLCServerBrowsingTVCell.xib */,
7D3E528A1BD7B5E100309D15 /* VLCCloudServicesTVViewController.xib */,
7DEC8BDD1BD67899006E1093 /* VLCFullscreenMovieTVViewController.xib */,
7DC71D201BC83058001FACAA /* VLCAppSharesTVViewController.xib */,
......@@ -2188,9 +2191,9 @@
7DEC8BE01BD686D3006E1093 /* Playback */,
7DEC8BE11BD686FA006E1093 /* Library */,
DD3EFEEF1BDEBCE500B68579 /* ServerBrowsing */,
DD3EA62F1AF50CFE007FF096 /* VLCWatchMessage.h */,
DD3EABFA1BE14C4B003668DA /* UIViewController+VLCAlert.h */,
DD3EABFB1BE14C4B003668DA /* UIViewController+VLCAlert.m */,
DD3EA62F1AF50CFE007FF096 /* VLCWatchMessage.h */,
DD3EA6301AF50CFE007FF096 /* VLCWatchMessage.m */,
);
path = SharedSources;
......@@ -2467,6 +2470,7 @@
DDEAECF61BDFEAFA00756C83 /* VLCLocalNetworkServerTVCell.xib in Resources */,
7D13294F1BA1F10100BE647E /* Assets.xcassets in Resources */,
7DEC8BE91BD68BC9006E1093 /* Settings.bundle in Resources */,
DD3EAC131BE26166003668DA /* VLCServerBrowsingTVCell.xib in Resources */,
7D3E528C1BD7B5E100309D15 /* VLCCloudServicesTVViewController.xib in Resources */,
7D7EF3DB1BD56B5900CD4CEE /* VLCOpenNetworkStreamTVViewController.xib in Resources */,
);
......
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