Skip to content

Commit

Permalink
Network Tab: Add tap to copy on Sharing via Wi-Fi cell
Browse files Browse the repository at this point in the history
Partially answers to #1189
  • Loading branch information
edrflt committed Oct 22, 2021
1 parent 8f1151f commit 453b37f
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 8 deletions.
1 change: 1 addition & 0 deletions Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"WEBINTF_DROPFILES_LONG" = "Drop files in the window to add them to your %@.<br>Or click on the \"+\" button to use the file picker dialog.";
"WEBINTF_DOWNLOADFILES" = "Download Files";
"WEBINTF_DOWNLOADFILES_LONG" = "Just click the file you want to download from your %@.";
"WEBINTF_ADDRESS_COPIED" = "Address copied to clipboard";
"WEBINTF_TITLE_ATV" = "Remote Playback";
"WEBINTF_DROPFILES_LONG_ATV" = "Drop files in the window to play them on your %@.<br>Or click on the \"+\" button to use the file picker dialog.";
"WEBINTF_URL_SENT" = "URL sent successfully.";
Expand Down
14 changes: 8 additions & 6 deletions Sources/LocalNetworkConnectivity/RemoteNetworkDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
import Foundation

import UIKit

enum RemoteNetworkCellType: Int {
@available(iOS 11.0, *)
Expand Down Expand Up @@ -102,10 +103,6 @@ class RemoteNetworkDataSource: NSObject, UITableViewDataSource, UITableViewDeleg

// MARK: - Delegate

func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
return RemoteNetworkCellType(rawValue: indexPath.row + RemoteNetworkCellType.first) == .wifi ? nil : indexPath
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
if let vc = viewController(indexPath: indexPath) {
Expand All @@ -114,6 +111,12 @@ class RemoteNetworkDataSource: NSObject, UITableViewDataSource, UITableViewDeleg
} else {
delegate?.showViewController(vc)
}
} else if RemoteNetworkCellType(rawValue: indexPath.row + RemoteNetworkCellType.first) == .wifi {
if tableView.cellForRow(at: indexPath)?.selectionStyle == .default {
UIPasteboard.general.string = VLCHTTPUploaderController.sharedInstance().addressToCopy()
UIAlertController.autoDismissable(title: NSLocalizedString("WEBINTF_TITLE", comment: ""),
message: NSLocalizedString("WEBINTF_ADDRESS_COPIED", comment: ""))
}
}
}

Expand All @@ -132,7 +135,6 @@ class RemoteNetworkDataSource: NSObject, UITableViewDataSource, UITableViewDeleg
case .download:
return downloadVC
case .wifi:
assertionFailure("We shouldn't get in here since we return nil in willSelect")
return nil
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/VLCHTTPUploaderController.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

- (BOOL)changeHTTPServerState:(BOOL)state;
- (NSString *)httpStatus;
- (nonnull NSString *)addressToCopy;
- (BOOL)isServerRunning;
- (NSString *)hostname;
- (NSString *)hostnamePort;
Expand Down
13 changes: 13 additions & 0 deletions Sources/VLCHTTPUploaderController.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ - (NSString *)httpStatus
}
}

- (NSString *)addressToCopy
{
if (_httpServer.isRunning) {
if (_httpServer.listeningPort != 80) {
return [NSString stringWithFormat:@"http://%@:%i", [self currentIPAddress], _httpServer.listeningPort];
} else {
return [NSString stringWithFormat:@"http://%@", [self currentIPAddress]];
}
} else {
return NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", nil);
}
}

- (BOOL)isServerRunning
{
return _httpServer.isRunning;
Expand Down
3 changes: 1 addition & 2 deletions Sources/VLCWiFiUploadTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ - (void)setupReachability

- (void)setupCell
{
self.selectionStyle = UITableViewCellSelectionStyleNone;

self.textLabel.text = NSLocalizedString(@"WEBINTF_TITLE", nil);
self.detailTextLabel.text = NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", nil);
self.detailTextLabel.numberOfLines = 0;
Expand Down Expand Up @@ -91,6 +89,7 @@ - (void)updateHTTPServerAddress
NSString *uploadText = connectedViaWifi ? [[VLCHTTPUploaderController sharedInstance] httpStatus] : NSLocalizedString(@"HTTP_UPLOAD_NO_CONNECTIVITY", nil);
self.detailTextLabel.text = uploadText;
self.serverToggle.on = connectedViaWifi && [VLCHTTPUploaderController sharedInstance].isServerRunning;
self.selectionStyle = self.serverToggle.isOn ? UITableViewCellSelectionStyleDefault : UITableViewCellSelectionStyleNone;
}

- (void)toggleHTTPServer
Expand Down
29 changes: 29 additions & 0 deletions UIAlertController+autoDismissable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*****************************************************************************
* UIAlertController+autoDismissable.swift
* VLC for iOS
*****************************************************************************
* Copyright (c) 2021 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Edgar Fouillet <vlc # edgar.fouillet.eu>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/

import UIKit

extension UIAlertController {
static func autoDismissable(title: String, message: String, dismissDelay: Double = 3.0) {
if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_OK", comment:""),
style: .default,
handler: nil))

rootViewController.present(alert, animated: true)
DispatchQueue.main.asyncAfter(deadline: .now() + dismissDelay) {
alert.dismiss(animated: true, completion: nil)
}
}
}
}
4 changes: 4 additions & 0 deletions VLC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
6B4E33D21BF2A39400A35255 /* playerControl.js in Resources */ = {isa = PBXBuildFile; fileRef = 6B4E33D01BF2A39400A35255 /* playerControl.js */; };
6D0B038825E7CBF90013DEF4 /* PopupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D0B038725E7CBF90013DEF4 /* PopupView.swift */; };
6D0C20D4249EEDA300620DA1 /* URL+isHidden.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D0C20D3249EEDA300620DA1 /* URL+isHidden.swift */; };
6D0F71D92721B678002E0FAE /* UIAlertController+autoDismissable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D0F71D82721B678002E0FAE /* UIAlertController+autoDismissable.swift */; };
6D220D0D234B8E3700BD694F /* FileManager+DeleteMediaFolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D220D0C234B8E3700BD694F /* FileManager+DeleteMediaFolder.swift */; };
6D3C676C23CDF1FC0039ACFD /* public in Resources */ = {isa = PBXBuildFile; fileRef = 6D3C676B23CDF1FC0039ACFD /* public */; };
6D4756B123607D4A005F670E /* EditActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4756B023607D49005F670E /* EditActions.swift */; };
Expand Down Expand Up @@ -629,6 +630,7 @@
6B4E33D01BF2A39400A35255 /* playerControl.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = playerControl.js; path = Resources/web/playerControl.js; sourceTree = SOURCE_ROOT; };
6D0B038725E7CBF90013DEF4 /* PopupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PopupView.swift; path = Sources/PopupView.swift; sourceTree = "<group>"; };
6D0C20D3249EEDA300620DA1 /* URL+isHidden.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "URL+isHidden.swift"; path = "Sources/Extensions/URL+isHidden.swift"; sourceTree = "<group>"; };
6D0F71D82721B678002E0FAE /* UIAlertController+autoDismissable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIAlertController+autoDismissable.swift"; sourceTree = "<group>"; };
6D220D0C234B8E3700BD694F /* FileManager+DeleteMediaFolder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "FileManager+DeleteMediaFolder.swift"; path = "Sources/Extensions/FileManager+DeleteMediaFolder.swift"; sourceTree = "<group>"; };
6D3C676B23CDF1FC0039ACFD /* public */ = {isa = PBXFileReference; lastKnownFileType = folder; path = public; sourceTree = "<group>"; };
6D4756B023607D49005F670E /* EditActions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = EditActions.swift; path = Sources/EditActions.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2269,6 +2271,7 @@
6DDE230C239FE8C2003DE55A /* URL+isExcludedFromBackup.swift */,
6D0C20D3249EEDA300620DA1 /* URL+isHidden.swift */,
6DE9183C25F65C390039AFA7 /* UIScrollView+flashScrollIndicatorsIfNeeded.swift */,
6D0F71D82721B678002E0FAE /* UIAlertController+autoDismissable.swift */,
);
name = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -3367,6 +3370,7 @@
7D30F3C4183AB24C00FFC021 /* VLCHTTPUploaderController.m in Sources */,
7D30F3C7183AB26F00FFC021 /* VLCOpenNetworkStreamViewController.m in Sources */,
7DB66CF02520E3B90077481C /* VLCDownloadController.m in Sources */,
6D0F71D92721B678002E0FAE /* UIAlertController+autoDismissable.swift in Sources */,
41E6BECD207E64E900E158BA /* RemoteNetworkCell.swift in Sources */,
DD1CB05A1BBAC549006EDDE6 /* VLCVolumeView.m in Sources */,
7D5CAA8C1A4AD8E5003F2CBC /* VLCTrackSelectorHeaderView.m in Sources */,
Expand Down

0 comments on commit 453b37f

Please sign in to comment.