Browse Source

VLCServerListViewController: Move connect to server cell into sectionHeader

Carola Nitz 7 years ago
parent
commit
1b2fe4bcff

+ 1 - 0
Resources/en.lproj/Localizable.strings

@@ -125,6 +125,7 @@
 
 "LOCAL_NETWORK" = "Local Network";
 "CONNECT_TO_SERVER" = "Connect to Server";
+"FILE_SERVER" = "File Servers";
 "USER_LABEL" = "User";
 "PASSWORD_LABEL" = "Password";
 "DISABLE_LABEL" = "Disable";

+ 5 - 5
SharedSources/PresentationTheme.swift

@@ -33,7 +33,7 @@ extension Notification.Name {
     let sectionHeaderTintColor: UIColor
     let settingsBackground: UIColor
     let settingsCellBackground: UIColor
-    let settingsSeparatorColor: UIColor
+    let separatorColor: UIColor
     let mediaCategorySeparatorColor: UIColor
     let tabBarColor: UIColor
     let orangeUI: UIColor
@@ -53,7 +53,7 @@ extension Notification.Name {
                 sectionHeaderTintColor: UIColor,
                 settingsBackground: UIColor,
                 settingsCellBackground: UIColor,
-                settingsSeparatorColor: UIColor,
+                separatorColor: UIColor,
                 mediaCategorySeparatorColor: UIColor,
                 tabBarColor: UIColor,
                 orangeUI: UIColor) {
@@ -72,7 +72,7 @@ extension Notification.Name {
         self.sectionHeaderTintColor = sectionHeaderTintColor
         self.settingsBackground = settingsBackground
         self.settingsCellBackground = settingsCellBackground
-        self.settingsSeparatorColor = settingsSeparatorColor
+        self.separatorColor = separatorColor
         self.mediaCategorySeparatorColor = mediaCategorySeparatorColor
         self.tabBarColor = tabBarColor
         self.orangeUI = orangeUI
@@ -152,7 +152,7 @@ let brightPalette = ColorPalette(isDark: false,
                                  sectionHeaderTintColor: UIColor(0xE5EFE3),
                                  settingsBackground: UIColor(0xDCDCDC),
                                  settingsCellBackground: UIColor(0xF9F9F7),
-                                 settingsSeparatorColor: UIColor(0xD3D3D3),
+                                 separatorColor: UIColor(0xD3D3D3),
                                  mediaCategorySeparatorColor: UIColor(0xECF2F6),
                                  tabBarColor: UIColor(0xFFFFFF),
                                  orangeUI: UIColor(0xFF8800))
@@ -172,7 +172,7 @@ let darkPalette = ColorPalette(isDark: true,
                                sectionHeaderTintColor: UIColor(0x3C3C3C),
                                settingsBackground: UIColor(0x292B36),
                                settingsCellBackground: UIColor(0x3D3F40),
-                               settingsSeparatorColor: UIColor(0xA9A9A9),
+                               separatorColor: UIColor(0x25292C),
                                mediaCategorySeparatorColor: UIColor(0x25292C),
                                tabBarColor: UIColor(0x292B36),
                                orangeUI: UIColor(0xFF8800))

+ 0 - 1
SharedSources/ServerBrowsing/VLCLocalServerDiscoveryController.h

@@ -25,7 +25,6 @@
 - (instancetype)initWithServiceBrowserClasses:(NSArray<Class> *)serviceBrowserClasses;
 
 - (NSUInteger)numberOfSections;
-- (NSString *)titleForSection:(NSUInteger)section;
 - (NSUInteger)numberOfItemsInSection:(NSUInteger)section;
 - (BOOL)foundAnythingAtAll;
 

+ 0 - 6
SharedSources/ServerBrowsing/VLCLocalServerDiscoveryController.m

@@ -114,12 +114,6 @@
     return _serviceBrowsers.count;
 }
 
-- (NSString *)titleForSection:(NSUInteger)section
-{
-    id<VLCLocalNetworkServiceBrowser> browser = _serviceBrowsers[section];
-    return browser.name;
-}
-
 - (NSUInteger)numberOfItemsInSection:(NSUInteger)section
 {
     id<VLCLocalNetworkServiceBrowser> browser = _serviceBrowsers[section];

+ 35 - 28
Sources/LocalNetworkConnectivity/VLCServerListViewController.m

@@ -29,7 +29,6 @@
 #import "VLCNetworkServerBrowserVLCMedia.h"
 #import "VLCNetworkServerBrowserPlex.h"
 
-#import "VLCLocalNetworkServiceBrowserManualConnect.h"
 #import "VLCLocalNetworkServiceBrowserPlex.h"
 #import "VLCLocalNetworkServiceBrowserFTP.h"
 #import "VLCLocalNetworkServiceBrowserUPnP.h"
@@ -42,7 +41,7 @@
 
 #import "VLC_iOS-Swift.h"
 
-@interface VLCServerListViewController () <UITableViewDataSource, UITableViewDelegate, VLCLocalServerDiscoveryControllerDelegate, VLCNetworkLoginViewControllerDelegate, VLCRemoteNetworkDataSourceDelegate>
+@interface VLCServerListViewController () <UITableViewDataSource, UITableViewDelegate, VLCLocalServerDiscoveryControllerDelegate, VLCNetworkLoginViewControllerDelegate, VLCRemoteNetworkDataSourceDelegate, VLCFileServerSectionTableHeaderViewDelegate>
 {
     VLCLocalServerDiscoveryController *_discoveryController;
 
@@ -86,7 +85,9 @@
     _localNetworkTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
     _localNetworkTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
     _localNetworkTableView.rowHeight = [VLCNetworkListCell heightOfCell];
-    _localNetworkTableView.separatorColor = PresentationTheme.current.colors.background;
+    _localNetworkTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
+
+    [_localNetworkTableView registerClass:[VLCFileServerSectionTableHeaderView class] forHeaderFooterViewReuseIdentifier:VLCFileServerSectionTableHeaderView.identifier];
 
     _remoteNetworkTableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
     _remoteNetworkTableView.translatesAutoresizingMaskIntoConstraints = NO;
@@ -141,7 +142,6 @@
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentSizeDidChange) name:UIContentSizeCategoryDidChangeNotification object:nil];
 
     NSArray *browserClasses = @[
-                                [VLCLocalNetworkServiceBrowserManualConnect class],
                                 [VLCLocalNetworkServiceBrowserUPnP class],
                                 [VLCLocalNetworkServiceBrowserPlex class],
                                 [VLCLocalNetworkServiceBrowserFTP class],
@@ -186,6 +186,21 @@
     [_remoteNetworkTableView layoutIfNeeded];
     _remoteNetworkHeight.constant = _remoteNetworkTableView.contentSize.height;
 }
+
+- (void)connectToServer
+{
+    VLCNetworkLoginViewController *loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:@"VLCNetworkLoginViewController" bundle:nil];
+
+    loginViewController.loginInformation = [[VLCNetworkServerLoginInformation alloc] init];;
+    loginViewController.delegate = self;
+    UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:loginViewController];
+    navCon.modalPresentationStyle = UIModalPresentationFormSheet;
+    [self presentViewController:navCon animated:YES completion:nil];
+
+    if (loginViewController.navigationItem.leftBarButtonItem == nil)
+        loginViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_DONE", nil) style:UIBarButtonItemStyleDone target:self action:@selector(_dismissLogin)];
+}
+
 #pragma mark - table view handling
 
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
@@ -198,6 +213,16 @@
     return [_discoveryController numberOfItemsInSection:section];
 }
 
+- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
+{
+    if (section == 0) {
+        VLCFileServerSectionTableHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:VLCFileServerSectionTableHeaderView.identifier];
+        headerView.delegate = self;
+        return headerView;
+    }
+    return nil;
+}
+
 - (void)tableView:(UITableView *)tableView willDisplayCell:(VLCNetworkListCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
 {
     UIColor *color = (indexPath.row % 2 == 0)? PresentationTheme.current.colors.cellBackgroundB : PresentationTheme.current.colors.cellBackgroundA;
@@ -205,16 +230,6 @@
     cell.titleLabel.textColor = cell.folderTitleLabel.textColor = cell.subtitleLabel.textColor = cell.thumbnailView.tintColor = PresentationTheme.current.colors.cellTextColor;
 }
 
-- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
-{
-    // Text Color
-    UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
-    header.textLabel.textColor = PresentationTheme.current.colors.sectionHeaderTextColor;
-    header.textLabel.font = [UIFont boldSystemFontOfSize:([UIFont systemFontSize] * 0.8f)];
-
-    header.tintColor = PresentationTheme.current.colors.sectionHeaderTintColor;
-}
-
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
     static NSString *CellIdentifier = @"LocalNetworkCell";
@@ -300,10 +315,11 @@
 
 - (void)_dismissLogin
 {
-    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
-        [self.navigationController popViewControllerAnimated:YES];
-    else
+    if ([self.navigationController presentedViewController]) {
         [self dismissViewControllerAnimated:YES completion:nil];
+    } else {
+        [self.navigationController popViewControllerAnimated:YES];
+    }
 }
 
 - (UIStatusBarStyle)preferredStatusBarStyle
@@ -367,19 +383,10 @@
 
 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
 {
-    // always hide the header of the first section
     if (section == 0)
-        return 0.;
-
-    if ([_discoveryController numberOfItemsInSection:section] == 0)
-        return 0.;
+        return 56.;
 
-    return 21.f;
-}
-
-- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
-{
-    return [_discoveryController titleForSection:section];
+    return 0.;
 }
 
 @end

+ 61 - 0
Sources/VLCFileServerSectionTableHeaderView.swift

@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * VLCFileServerSectionTableHeaderView.m
+ * VLC for iOS
+ *****************************************************************************
+ * Copyright (c) 2018 VideoLAN. All rights reserved.
+ * $Id$
+ *
+ * Author: Carola Nitz <caro # videolan.org>
+ *
+ * Refer to the COPYING file of the official project for license.
+ *****************************************************************************/
+
+import Foundation
+
+@objc protocol VLCFileServerSectionTableHeaderViewDelegate: NSObjectProtocol {
+
+    func connectToServer()
+}
+
+class VLCFileServerSectionTableHeaderView: VLCSectionTableHeaderView {
+
+    @objc static let identifier = "VLCFileServerSectionTableHeaderView"
+    @objc weak var delegate: VLCFileServerSectionTableHeaderViewDelegate?
+    var layoutConstraints: [NSLayoutConstraint]?
+    lazy var connectButton: UIButton = {
+        let connectButton = UIButton(type: .system)
+        connectButton.setTitle(NSLocalizedString("BUTTON_CONNECT", comment: ""), for: .normal)
+        connectButton.titleLabel?.font = UIFont.systemFont(ofSize: 17)
+        connectButton.titleLabel?.textColor = PresentationTheme.current.colors.orangeUI
+        connectButton.translatesAutoresizingMaskIntoConstraints = false
+        connectButton.addTarget(self, action: #selector(connectButtonDidPress), for: .touchUpInside)
+        contentView.addSubview(connectButton)
+        return connectButton
+    }()
+
+    override func setupUI() {
+        super.setupUI()
+        textLabel?.text = NSLocalizedString("FILE_SERVER", comment: "")
+    }
+
+    //Before layoutSubviews textlabel doesn't have a superview
+    override func layoutSubviews() {
+        super.layoutSubviews()
+        if layoutConstraints == nil {
+            layoutConstraints = [
+                connectButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20),
+                connectButton.firstBaselineAnchor.constraint(equalTo: textLabel!.firstBaselineAnchor)
+                ]
+            NSLayoutConstraint.activate(layoutConstraints!)
+        }
+    }
+    @objc func connectButtonDidPress() {
+        delegate?.connectToServer()
+    }
+
+    override func prepareForReuse() {
+        super.prepareForReuse()
+        //Text gets set to nil in prepareForReuse so we set it again
+        textLabel?.text = NSLocalizedString("FILE_SERVER", comment: "")
+    }
+}

+ 53 - 0
Sources/VLCSectionTableHeaderView.swift

@@ -0,0 +1,53 @@
+/*****************************************************************************
+ * VLCSectionTableHeaderView.m
+ * VLC for iOS
+ *****************************************************************************
+ * Copyright (c) 2018 VideoLAN. All rights reserved.
+ * $Id$
+ *
+ * Author: Carola Nitz <caro # videolan.org>
+ *
+ * Refer to the COPYING file of the official project for license.
+ *****************************************************************************/
+
+import Foundation
+
+class VLCSectionTableHeaderView: UITableViewHeaderFooterView {
+
+    let separator = UIView()
+
+    override init(reuseIdentifier: String?) {
+        super.init(reuseIdentifier: reuseIdentifier)
+        NotificationCenter.default.addObserver(self, selector: #selector(updateTheme), name: .VLCThemeDidChangeNotification, object: nil)
+        setupUI()
+        updateTheme()
+    }
+
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    func setupUI() {
+        separator.translatesAutoresizingMaskIntoConstraints = false
+        contentView.addSubview(separator)
+
+        NSLayoutConstraint.activate([
+            separator.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 20),
+            separator.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -20),
+            separator.heightAnchor.constraint(equalToConstant: 1),
+            separator.topAnchor.constraint(equalTo: contentView.topAnchor)
+            ])
+    }
+
+    @objc func updateTheme() {
+        contentView.backgroundColor = PresentationTheme.current.colors.background
+        separator.backgroundColor = PresentationTheme.current.colors.separatorColor
+        textLabel?.textColor = PresentationTheme.current.colors.cellTextColor
+    }
+
+    override func layoutSubviews() {
+        super.layoutSubviews()
+        textLabel?.font = UIFont.systemFont(ofSize: 24, weight: .semibold)
+        textLabel?.textColor = PresentationTheme.current.colors.cellTextColor
+    }
+}

+ 1 - 1
Sources/VLCSettingsController.m

@@ -51,7 +51,7 @@
 - (void)themeDidChange
 {
     self.view.backgroundColor = PresentationTheme.current.colors.settingsBackground;
-    self.tableView.separatorColor = PresentationTheme.current.colors.settingsSeparatorColor;
+    self.tableView.separatorColor = PresentationTheme.current.colors.separatorColor;
     [self.tableView reloadData];
     [self setNeedsStatusBarAppearanceUpdate];
 }

+ 8 - 0
VLC.xcodeproj/project.pbxproj

@@ -18,6 +18,8 @@
 		413EC98B201B4F2C00BF412F /* PresentationTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 413EC98A201B4F2B00BF412F /* PresentationTheme.swift */; };
 		4142AB4520A31EC500039380 /* VLCMediaDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4142AB4420A31EC500039380 /* VLCMediaDataSource.swift */; };
 		414396C22023316C005E3FAF /* AppearanceManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 414396C12023316C005E3FAF /* AppearanceManager.swift */; };
+		4144156A20ECD2620078EC37 /* VLCSectionTableHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4144156920ECD2620078EC37 /* VLCSectionTableHeaderView.swift */; };
+		4144156C20ECE6330078EC37 /* VLCFileServerSectionTableHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4144156B20ECE6330078EC37 /* VLCFileServerSectionTableHeaderView.swift */; };
 		4144C4661A0ED6C700918C89 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D3784E6183A99E1009EE944 /* Reachability.m */; };
 		4152F1621FEF19BD00F1908B /* KeychainCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4152F1611FEF19BD00F1908B /* KeychainCoordinator.swift */; };
 		416443862048419E00CAC646 /* DeviceMotion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 416443852048419E00CAC646 /* DeviceMotion.swift */; };
@@ -498,6 +500,8 @@
 		413EC98A201B4F2B00BF412F /* PresentationTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationTheme.swift; sourceTree = "<group>"; };
 		4142AB4420A31EC500039380 /* VLCMediaDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = VLCMediaDataSource.swift; path = Sources/VLCMediaDataSource.swift; sourceTree = "<group>"; };
 		414396C12023316C005E3FAF /* AppearanceManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppearanceManager.swift; path = Sources/AppearanceManager.swift; sourceTree = SOURCE_ROOT; };
+		4144156920ECD2620078EC37 /* VLCSectionTableHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = VLCSectionTableHeaderView.swift; path = Sources/VLCSectionTableHeaderView.swift; sourceTree = "<group>"; };
+		4144156B20ECE6330078EC37 /* VLCFileServerSectionTableHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = VLCFileServerSectionTableHeaderView.swift; path = Sources/VLCFileServerSectionTableHeaderView.swift; sourceTree = "<group>"; };
 		4152F1611FEF19BD00F1908B /* KeychainCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = KeychainCoordinator.swift; path = Sources/KeychainCoordinator.swift; sourceTree = "<group>"; };
 		416443852048419E00CAC646 /* DeviceMotion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DeviceMotion.swift; path = Sources/DeviceMotion.swift; sourceTree = "<group>"; };
 		416DACB620B6DB9A001BC75D /* VLCPlayingExternallyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VLCPlayingExternallyView.swift; sourceTree = "<group>"; };
@@ -1449,6 +1453,8 @@
 				DD1CB0581BBAC549006EDDE6 /* VLCVolumeView.h */,
 				DD1CB0591BBAC549006EDDE6 /* VLCVolumeView.m */,
 				8DD651B0208F62B70052EE68 /* VLCActionSheet */,
+				4144156920ECD2620078EC37 /* VLCSectionTableHeaderView.swift */,
+				4144156B20ECE6330078EC37 /* VLCFileServerSectionTableHeaderView.swift */,
 			);
 			name = "UI Elements";
 			sourceTree = "<group>";
@@ -3245,6 +3251,7 @@
 				41CD695C1A29D72600E60BCE /* VLCBoxController.m in Sources */,
 				7D3784C2183A9938009EE944 /* VLCSlider.m in Sources */,
 				7D3784C3183A9938009EE944 /* VLCStatusLabel.m in Sources */,
+				4144156C20ECE6330078EC37 /* VLCFileServerSectionTableHeaderView.swift in Sources */,
 				7D1276621AADA0E600F0260C /* VLCMultiSelectionMenuView.m in Sources */,
 				416DACB720B6DB9A001BC75D /* VLCPlayingExternallyView.swift in Sources */,
 				7D3784C8183A9972009EE944 /* NSString+SupportedMedia.m in Sources */,
@@ -3264,6 +3271,7 @@
 				DD3EFF2D1BDEBCE500B68579 /* VLCLocalNetworkServiceBrowserFTP.m in Sources */,
 				7D30F3C3183AB24C00FFC021 /* VLCHTTPFileDownloader.m in Sources */,
 				41273A3C1A955C4100A2EF77 /* VLCMigrationViewController.m in Sources */,
+				4144156A20ECD2620078EC37 /* VLCSectionTableHeaderView.swift in Sources */,
 				7D30F3C4183AB24C00FFC021 /* VLCHTTPUploaderController.m in Sources */,
 				7D30F3C7183AB26F00FFC021 /* VLCOpenNetworkStreamViewController.m in Sources */,
 				41E6BECD207E64E900E158BA /* RemoteNetworkCell.swift in Sources */,