Explorar o código

server list as collection view instead of table view

Tobias Conradi %!s(int64=9) %!d(string=hai) anos
pai
achega
7cfe86c602

+ 5 - 5
Apple-TV/AppleTVAppDelegate.m

@@ -10,7 +10,7 @@
  *****************************************************************************/
 
 #import "AppleTVAppDelegate.h"
-#import "VLCServerListTVTableViewController.h"
+#import "VLCServerListTVViewController.h"
 #import "VLCOpenNetworkStreamTVViewController.h"
 #import "VLCSettingsTableViewController.h"
 #import "VLCCloudServicesTVViewController.h"
@@ -20,7 +20,7 @@
 {
     UITabBarController *_mainViewController;
 
-    VLCServerListTVTableViewController *_localNetworkVC;
+    VLCServerListTVViewController *_localNetworkVC;
     VLCCloudServicesTVViewController *_cloudServicesVC;
     VLCOpenNetworkStreamTVViewController *_openNetworkVC;
     VLCSettingsTableViewController *_settingsTableVC;
@@ -52,10 +52,10 @@
     [defaults registerDefaults:appDefaults];
 }
 
-- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
-
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
-    _localNetworkVC = [[VLCServerListTVTableViewController alloc] initWithNibName:nil bundle:nil];
+    _localNetworkVC = [[VLCServerListTVViewController alloc] initWithNibName:nil bundle:nil];
     _cloudServicesVC = [[VLCCloudServicesTVViewController alloc] initWithNibName:nil bundle:nil];
     _openNetworkVC = [[VLCOpenNetworkStreamTVViewController alloc] initWithNibName:nil bundle:nil];
     _settingsTableVC = [[VLCSettingsTableViewController alloc] initWithNibName:nil bundle:nil];

+ 2 - 1
Apple-TV/VLCServerListTVTableViewController.h

@@ -10,9 +10,10 @@
  *****************************************************************************/
 
 #import <UIKit/UIKit.h>
+#import "VLCRemoteBrowsingCollectionViewController.h"
 #import "VLCLocalServerDiscoveryController.h"
 
-@interface VLCServerListTVTableViewController : UITableViewController <VLCLocalServerDiscoveryControllerDelegate>
+@interface VLCServerListTVViewController : VLCRemoteBrowsingCollectionViewController <VLCLocalServerDiscoveryControllerDelegate>
 
 @property (nonatomic) VLCLocalServerDiscoveryController *discoveryController;
 

+ 53 - 41
Apple-TV/VLCServerListTVTableViewController.m

@@ -9,7 +9,7 @@
  * Refer to the COPYING file of the official project for license.
  *****************************************************************************/
 
-#import "VLCServerListTVTableViewController.h"
+#import "VLCServerListTVViewController.h"
 #import "VLCLocalNetworkServerTVCell.h"
 #import "VLCServerBrowsingTVViewController.h"
 #import "VLCNetworkServerLoginInformation.h"
@@ -29,22 +29,30 @@
 #import "VLCLocalNetworkServiceBrowserDSM.h"
 #import "VLCLocalNetworkServiceBrowserHTTP.h"
 
-@interface VLCServerListTVTableViewController ()
+#import "VLCRemoteBrowsingTVCell.h"
+
+@interface VLCServerListTVViewController ()
 {
     UILabel *_nothingFoundLabel;
 }
+@property (nonatomic) NSArray <NSIndexPath *> *indexPaths;
 @end
 
-@implementation VLCServerListTVTableViewController
+@implementation VLCServerListTVViewController
+
+- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+    return [super initWithNibName:@"VLCRemoteBrowsingCollectionViewController" bundle:nil];
+}
 
 - (void)viewDidLoad {
     [super viewDidLoad];
     self.automaticallyAdjustsScrollViewInsets = NO;
     self.edgesForExtendedLayout = UIRectEdgeAll ^ UIRectEdgeTop;
-    
-    UINib *nib = [UINib nibWithNibName:@"VLCLocalNetworkServerTVCell" bundle:nil];
-    [self.tableView registerNib:nib forCellReuseIdentifier:VLCLocalServerTVCell];
-    self.tableView.rowHeight = 150;
+
+    UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)self.collectionViewLayout;
+    flowLayout.itemSize = CGSizeMake(200, 300);
+
 
     _nothingFoundLabel = [[UILabel alloc] init];
     _nothingFoundLabel.text = NSLocalizedString(@"NO_SERVER_FOUND", nil);
@@ -103,49 +111,41 @@
     [self.discoveryController stopDiscovery];
 }
 
-#pragma mark - Table view data source
-- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-    return self.discoveryController.numberOfSections;
-}
+#pragma mark - Collection view data source
 
-- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
-    VLCLocalServerDiscoveryController *discoverer = self.discoveryController;
-    if (discoverer.numberOfSections > 1 && [discoverer numberOfItemsInSection:section] > 0) {
-        return [self.discoveryController titleForSection:section];
-    }
-    return nil;
+- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
+{
+    return self.indexPaths.count;
 }
 
-- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-    return [self.discoveryController numberOfItemsInSection:section];
-}
+- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath
+{
+    VLCRemoteBrowsingTVCell *browsingCell = (VLCRemoteBrowsingTVCell *) [collectionView dequeueReusableCellWithReuseIdentifier:VLCRemoteBrowsingTVCellIdentifier forIndexPath:indexPath];
 
-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:VLCLocalServerTVCell forIndexPath:indexPath];
-    id<VLCLocalNetworkService> service = [self.discoveryController networkServiceForIndexPath:indexPath];
-    cell.textLabel.text = service.title;
-    cell.imageView.image = service.icon ? service.icon : [UIImage imageNamed:@"serverIcon"];
-    return cell;
-}
+    NSIndexPath *discoveryIndexPath = self.indexPaths[indexPath.row];
+    id<VLCLocalNetworkService> service = [self.discoveryController networkServiceForIndexPath:discoveryIndexPath];
 
-- (void)showWIP:(NSString *)todo {
-    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Work in Progress\nFeature not (yet) implemented."
-                                                                             message:todo
-                                                                      preferredStyle:UIAlertControllerStyleAlert];
+    browsingCell.isDirectory = YES;
+    browsingCell.title = service.title;
+    browsingCell.subtitle = [self.discoveryController titleForSection:discoveryIndexPath.section];
+    browsingCell.subtitleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
+    browsingCell.thumbnailImage = service.icon ? service.icon : [UIImage imageNamed:@"serverIcon"];
 
-    [alertController addAction:[UIAlertAction actionWithTitle:@"Please fix this!"
-                                                        style:UIAlertActionStyleDefault
-                                                      handler:nil]];
+    return browsingCell;
+}
 
-    [alertController addAction:[UIAlertAction actionWithTitle:@"Nevermind"
-                                                        style:UIAlertActionStyleCancel
-                                                      handler:nil]];
-    [self presentViewController:alertController animated:YES completion:nil];
+- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
+{
+    NSIndexPath *discoveryIndexPath = self.indexPaths[indexPath.row];
+    id<VLCLocalNetworkService> service = [self.discoveryController networkServiceForIndexPath:discoveryIndexPath];
+    [self didSelectService:service];
 }
 
-- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 
-    id<VLCLocalNetworkService> service = [self.discoveryController networkServiceForIndexPath:indexPath];
+#pragma mark - Service specific stuff
+
+- (void)didSelectService:(id<VLCLocalNetworkService>)service
+{
     if ([service respondsToSelector:@selector(serverBrowser)]) {
         id <VLCNetworkServerBrowser> browser = [service serverBrowser];
         if (browser) {
@@ -264,7 +264,19 @@
 #pragma mark - VLCLocalServerDiscoveryController
 - (void)discoveryFoundSomethingNew
 {
-    [self.tableView reloadData];
+    NSMutableArray<NSIndexPath *> *indexPaths = [NSMutableArray array];
+    VLCLocalServerDiscoveryController *discoveryController = self.discoveryController;
+    NSUInteger sectionCount = [discoveryController numberOfSections];
+    for (NSUInteger section = 0; section < sectionCount; ++section) {
+        NSUInteger itemsCount = [discoveryController numberOfItemsInSection:section];
+        for (NSUInteger index = 0; index < itemsCount; ++index) {
+            NSIndexPath *indexPath = [NSIndexPath indexPathForItem:index inSection:section];
+            [indexPaths addObject:indexPath];
+        }
+    }
+    self.indexPaths = [indexPaths copy];
+
+    [self.collectionView reloadData];
 
     _nothingFoundLabel.hidden = self.discoveryController.foundAnythingAtAll;
 }

+ 6 - 6
VLC for iOS.xcodeproj/project.pbxproj

@@ -339,7 +339,7 @@
 		DDEAECC61BDEC79D00756C83 /* VLCLocalNetworkServiceBrowserSAP.m in Sources */ = {isa = PBXBuildFile; fileRef = DDEAECC51BDEC79D00756C83 /* VLCLocalNetworkServiceBrowserSAP.m */; };
 		DDEAECC71BDEC79D00756C83 /* VLCLocalNetworkServiceBrowserSAP.m in Sources */ = {isa = PBXBuildFile; fileRef = DDEAECC51BDEC79D00756C83 /* VLCLocalNetworkServiceBrowserSAP.m */; };
 		DDEAECCD1BDECCB800756C83 /* VLCNetworkListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DDEAECCC1BDECCB800756C83 /* VLCNetworkListViewController.m */; };
-		DDEAECF11BDFE9E800756C83 /* VLCServerListTVTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DDEAECEC1BDFE99200756C83 /* VLCServerListTVTableViewController.m */; };
+		DDEAECF11BDFE9E800756C83 /* VLCServerListTVViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DDEAECEC1BDFE99200756C83 /* VLCServerListTVViewController.m */; };
 		DDEAECF61BDFEAFA00756C83 /* VLCLocalNetworkServerTVCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DDEAECF51BDFEAFA00756C83 /* VLCLocalNetworkServerTVCell.xib */; };
 		DDEAECF71BDFEB0200756C83 /* VLCLocalNetworkServerTVCell.m in Sources */ = {isa = PBXBuildFile; fileRef = DDEAECF31BDFEAE300756C83 /* VLCLocalNetworkServerTVCell.m */; };
 		DDEAECFE1BDFFAEE00756C83 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D3784E6183A99E1009EE944 /* Reachability.m */; };
@@ -1004,8 +1004,8 @@
 		DDEAECC51BDEC79D00756C83 /* VLCLocalNetworkServiceBrowserSAP.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCLocalNetworkServiceBrowserSAP.m; sourceTree = "<group>"; };
 		DDEAECCB1BDECCB800756C83 /* VLCNetworkListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCNetworkListViewController.h; path = Sources/LocalNetworkConnectivity/VLCNetworkListViewController.h; sourceTree = SOURCE_ROOT; };
 		DDEAECCC1BDECCB800756C83 /* VLCNetworkListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCNetworkListViewController.m; path = Sources/LocalNetworkConnectivity/VLCNetworkListViewController.m; sourceTree = SOURCE_ROOT; };
-		DDEAECEB1BDFE99200756C83 /* VLCServerListTVTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCServerListTVTableViewController.h; sourceTree = "<group>"; };
-		DDEAECEC1BDFE99200756C83 /* VLCServerListTVTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCServerListTVTableViewController.m; sourceTree = "<group>"; };
+		DDEAECEB1BDFE99200756C83 /* VLCServerListTVViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCServerListTVViewController.h; sourceTree = "<group>"; };
+		DDEAECEC1BDFE99200756C83 /* VLCServerListTVViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCServerListTVViewController.m; sourceTree = "<group>"; };
 		DDEAECF21BDFEAE300756C83 /* VLCLocalNetworkServerTVCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCLocalNetworkServerTVCell.h; sourceTree = "<group>"; };
 		DDEAECF31BDFEAE300756C83 /* VLCLocalNetworkServerTVCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCLocalNetworkServerTVCell.m; sourceTree = "<group>"; };
 		DDEAECF51BDFEAFA00756C83 /* VLCLocalNetworkServerTVCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = VLCLocalNetworkServerTVCell.xib; sourceTree = "<group>"; };
@@ -1721,8 +1721,8 @@
 		7DEC8BE31BD68882006E1093 /* Network UI */ = {
 			isa = PBXGroup;
 			children = (
-				DDEAECEB1BDFE99200756C83 /* VLCServerListTVTableViewController.h */,
-				DDEAECEC1BDFE99200756C83 /* VLCServerListTVTableViewController.m */,
+				DDEAECEB1BDFE99200756C83 /* VLCServerListTVViewController.h */,
+				DDEAECEC1BDFE99200756C83 /* VLCServerListTVViewController.m */,
 				DDDEA6AD1BE027FA000BB7A2 /* VLCServerBrowsingTVViewController.h */,
 				DDDEA6AE1BE027FA000BB7A2 /* VLCServerBrowsingTVViewController.m */,
 				DDEAECF21BDFEAE300756C83 /* VLCLocalNetworkServerTVCell.h */,
@@ -2647,7 +2647,7 @@
 				DD3EFF361BDEBCE500B68579 /* VLCLocalNetworkServiceBrowserNetService.m in Sources */,
 				7D51B3B01BF0EEF4005AF4D5 /* VLCPlaybackInfoMediaInfoTVViewController.m in Sources */,
 				7D13347C1BE132EA0012E919 /* VLCLocalNetworkServiceBrowserUPnP.m in Sources */,
-				DDEAECF11BDFE9E800756C83 /* VLCServerListTVTableViewController.m in Sources */,
+				DDEAECF11BDFE9E800756C83 /* VLCServerListTVViewController.m in Sources */,
 				7DEC8BDE1BD67899006E1093 /* VLCFullscreenMovieTVViewController.m in Sources */,
 				DD3EFF501BDEBCE500B68579 /* VLCPlexParser.m in Sources */,
 				7D405ED31BEA11CD006ED886 /* VLCHTTPUploaderController.m in Sources */,