Sfoglia il codice sorgente

ServerListViewController: Replace sectionheaderview with view

The sectionheader would disappear if fileservers were not discovered
Carola Nitz 6 anni fa
parent
commit
c06fbb1f42

+ 10 - 24
Sources/LocalNetworkConnectivity/VLCServerListViewController.m

@@ -41,7 +41,7 @@
 
 #import "VLC-Swift.h"
 
-@interface VLCServerListViewController () <UITableViewDataSource, UITableViewDelegate, VLCLocalServerDiscoveryControllerDelegate, VLCNetworkLoginViewControllerDelegate, VLCRemoteNetworkDataSourceDelegate, VLCFileServerSectionTableHeaderViewDelegate>
+@interface VLCServerListViewController () <UITableViewDataSource, UITableViewDelegate, VLCLocalServerDiscoveryControllerDelegate, VLCNetworkLoginViewControllerDelegate, VLCRemoteNetworkDataSourceDelegate, VLCFileServerViewDelegate>
 {
     VLCLocalServerDiscoveryController *_discoveryController;
 
@@ -99,8 +99,6 @@
 
     [self.navigationController.navigationBar setTranslucent:NO];
 
-    [_localNetworkTableView registerClass:[VLCFileServerSectionTableHeaderView class] forHeaderFooterViewReuseIdentifier:VLCFileServerSectionTableHeaderView.identifier];
-
     _remoteNetworkTableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
     _remoteNetworkTableView.translatesAutoresizingMaskIntoConstraints = NO;
     _remoteNetworkTableView.backgroundColor = PresentationTheme.current.colors.background;
@@ -110,6 +108,10 @@
     _remoteNetworkTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
     _remoteNetworkTableView.bounces = NO;
 
+    VLCFileServerView *fileServerView = [VLCFileServerView new];
+    fileServerView.translatesAutoresizingMaskIntoConstraints = NO;
+    fileServerView.delegate = self;
+
     [_remoteNetworkTableView registerClass:[VLCWiFiUploadTableViewCell class] forCellReuseIdentifier:[VLCWiFiUploadTableViewCell cellIdentifier]];
     [_remoteNetworkTableView registerClass:[VLCRemoteNetworkCell class] forCellReuseIdentifier:VLCRemoteNetworkCell.cellIdentifier];
 
@@ -126,6 +128,7 @@
     [_localNetworkTableView addSubview:_activityIndicator];
 
     [_scrollView addSubview:_localNetworkTableView];
+    [_scrollView addSubview:fileServerView];
     [_scrollView addSubview:_remoteNetworkTableView];
 
     [_remoteNetworkTableView layoutIfNeeded];
@@ -136,7 +139,10 @@
                                               [_remoteNetworkTableView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor],
                                               [_remoteNetworkTableView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor],
                                               [_remoteNetworkTableView.topAnchor constraintEqualToAnchor:_scrollView.topAnchor],
-                                              [_localNetworkTableView.topAnchor constraintEqualToAnchor:_remoteNetworkTableView.bottomAnchor],
+                                              [fileServerView.topAnchor constraintEqualToAnchor:_remoteNetworkTableView.bottomAnchor],
+                                              [fileServerView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor],
+                                              [fileServerView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor],
+                                              [_localNetworkTableView.topAnchor constraintEqualToAnchor:fileServerView.bottomAnchor],
                                               [_localNetworkTableView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor],
                                               [_localNetworkTableView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor],
                                               [_localNetworkTableView.bottomAnchor constraintEqualToAnchor:_scrollView.bottomAnchor],
@@ -235,16 +241,6 @@
     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 = PresentationTheme.current.colors.cellBackgroundA;
@@ -404,14 +400,4 @@
     _localNetworkHeight.constant = _localNetworkTableView.contentSize.height;
 }
 
-#pragma mark - custom table view appearance
-
-- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
-{
-    if (section == 0)
-        return 56.;
-
-    return 0.;
-}
-
 @end

+ 0 - 61
Sources/VLCFileServerSectionTableHeaderView.swift

@@ -1,61 +0,0 @@
-/*****************************************************************************
- * VLCFileServerSectionTableHeaderView.swift
- * 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: "")
-    }
-}

+ 85 - 0
Sources/VLCFileServerView.swift

@@ -0,0 +1,85 @@
+/*****************************************************************************
+ * VLCFileServerView.swift
+ * 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 VLCFileServerViewDelegate: NSObjectProtocol {
+
+    func connectToServer()
+}
+
+class VLCFileServerView: UIView {
+
+    @objc weak var delegate: VLCFileServerViewDelegate?
+    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.setTitleColor(PresentationTheme.current.colors.orangeUI, for: .normal)
+        connectButton.translatesAutoresizingMaskIntoConstraints = false
+        connectButton.addTarget(self, action: #selector(connectButtonDidPress), for: .touchUpInside)
+        addSubview(connectButton)
+        return connectButton
+    }()
+
+    lazy var textLabel: UILabel = {
+        let textLabel = UILabel(frame: .zero)
+        textLabel.text = NSLocalizedString("FILE_SERVER", comment: "")
+        textLabel.font = PresentationTheme.current.font.tableHeaderFont
+        textLabel.translatesAutoresizingMaskIntoConstraints = false
+        addSubview(textLabel)
+        return textLabel
+    }()
+
+    lazy var separator: UIView = {
+        let separator = UIView(frame: .zero)
+        separator.translatesAutoresizingMaskIntoConstraints = false
+        addSubview(separator)
+        return separator
+    }()
+
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+        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")
+    }
+
+    @objc func updateTheme() {
+        backgroundColor = PresentationTheme.current.colors.background
+        separator.backgroundColor = PresentationTheme.current.colors.separatorColor
+        textLabel.textColor = PresentationTheme.current.colors.cellTextColor
+    }
+
+    func setupUI() {
+        NSLayoutConstraint.activate([
+            separator.leadingAnchor.constraint(equalTo: leadingAnchor),
+            separator.trailingAnchor.constraint(equalTo: trailingAnchor),
+            separator.topAnchor.constraint(equalTo: topAnchor),
+            textLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 15),
+            textLabel.trailingAnchor.constraint(lessThanOrEqualTo: connectButton.leadingAnchor),
+            connectButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20),
+            textLabel.topAnchor.constraint(equalTo: separator.bottomAnchor, constant: 15),
+            textLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -9),
+            connectButton.firstBaselineAnchor.constraint(equalTo: textLabel.firstBaselineAnchor),
+            separator.heightAnchor.constraint(equalToConstant: 1)
+            ])
+    }
+
+    @objc func connectButtonDidPress() {
+        delegate?.connectToServer()
+    }
+}

+ 4 - 4
VLC.xcodeproj/project.pbxproj

@@ -28,7 +28,7 @@
 		414327A721B6E66E00B061F6 /* PlaybackSpeedView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 414327A621B6E66E00B061F6 /* PlaybackSpeedView.xib */; };
 		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 */; };
+		4144156C20ECE6330078EC37 /* VLCFileServerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4144156B20ECE6330078EC37 /* VLCFileServerView.swift */; };
 		4144C4661A0ED6C700918C89 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D3784E6183A99E1009EE944 /* Reachability.m */; };
 		4152F1621FEF19BD00F1908B /* KeychainCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4152F1611FEF19BD00F1908B /* KeychainCoordinator.swift */; };
 		41533C9E2113392F00EC3ABA /* URLHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41533C9D2113392F00EC3ABA /* URLHandlerTests.swift */; };
@@ -440,7 +440,7 @@
 		414327A621B6E66E00B061F6 /* PlaybackSpeedView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = PlaybackSpeedView.xib; path = Resources/PlaybackSpeedView.xib; 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>"; };
+		4144156B20ECE6330078EC37 /* VLCFileServerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = VLCFileServerView.swift; path = Sources/VLCFileServerView.swift; sourceTree = "<group>"; };
 		4152F1611FEF19BD00F1908B /* KeychainCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = KeychainCoordinator.swift; path = Sources/KeychainCoordinator.swift; sourceTree = "<group>"; };
 		41533C91211338D500EC3ABA /* VLC-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "VLC-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
 		41533C9D2113392F00EC3ABA /* URLHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLHandlerTests.swift; sourceTree = "<group>"; };
@@ -1292,7 +1292,7 @@
 				DD1CB0591BBAC549006EDDE6 /* VLCVolumeView.m */,
 				8DD651B0208F62B70052EE68 /* VLCActionSheet */,
 				4144156920ECD2620078EC37 /* VLCSectionTableHeaderView.swift */,
-				4144156B20ECE6330078EC37 /* VLCFileServerSectionTableHeaderView.swift */,
+				4144156B20ECE6330078EC37 /* VLCFileServerView.swift */,
 				8D222DC120F779F1009C0D34 /* MediaEditCell.swift */,
 				8DF9669C2113317100D0FCD6 /* VLCEditToolbar.swift */,
 				8DF966B021188BDB00D0FCD6 /* VLCEditController.swift */,
@@ -2974,7 +2974,7 @@
 				41CD695C1A29D72600E60BCE /* VLCBoxController.m in Sources */,
 				7D3784C2183A9938009EE944 /* VLCSlider.m in Sources */,
 				7D3784C3183A9938009EE944 /* VLCStatusLabel.m in Sources */,
-				4144156C20ECE6330078EC37 /* VLCFileServerSectionTableHeaderView.swift in Sources */,
+				4144156C20ECE6330078EC37 /* VLCFileServerView.swift in Sources */,
 				7D1276621AADA0E600F0260C /* VLCMultiSelectionMenuView.m in Sources */,
 				416DACB720B6DB9A001BC75D /* PlayingExternallyView.swift in Sources */,
 				41EC28E52136DD41004BCF0F /* MovieCollectionViewCell.swift in Sources */,