Przeglądaj źródła

VLCPlaybackController: Don't show errorDialogs from VLCKit anymore

(closes #184)

(cherry picked from commit af54bff0b05dd4b2e8405aaa7ed3d6b2c0f737c5)
Carola Nitz 7 lat temu
rodzic
commit
c58e5c1dc5

+ 93 - 0
SharedSources/VLCPlaybackController+VLCDialogProvider.swift

@@ -0,0 +1,93 @@
+/*****************************************************************************
+ * VLCPlaybackController+VLCDialogProvider.swift
+ * VLC for iOS
+ *****************************************************************************
+ * Copyright (c) 2018 VideoLAN. All rights reserved.
+ * $Id$
+ *
+ * Authors: Carola Nitz <caro # videolan.org>
+ *
+ * Refer to the COPYING file of the official project for license.
+ *****************************************************************************/
+
+import Foundation
+
+extension VLCPlaybackController: VLCCustomDialogRendererProtocol {
+    public func showError(withTitle error: String, message: String) {
+        //noop
+    }
+
+    public func showLogin(withTitle title: String, message: String, defaultUsername username: String?, askingForStorage: Bool, withReference reference: NSValue) {
+        let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
+        var usernameField: UITextField?
+        var passwordField: UITextField?
+        alertController.addTextField { textField in
+            usernameField = textField
+            textField.placeholder = NSLocalizedString("USER_LABEL", comment:"")
+            if username != "" {
+                textField.text = username
+            }
+        }
+        alertController.addTextField { textField in
+            passwordField = textField
+            textField.isSecureTextEntry = true
+            textField.placeholder = NSLocalizedString("PASSWORD_LABEL", comment:"")
+        }
+        let loginAction = UIAlertAction(title: NSLocalizedString("LOGIN", comment:""), style: .default) {[weak self] action in
+            let username = usernameField?.text ?? ""
+            let password = passwordField?.text ?? ""
+            self?.dialogProvider.postUsername(username, andPassword: password, forDialogReference: reference, store: false)
+        }
+        alertController.addAction(loginAction)
+        alertController.preferredAction = loginAction
+
+        alertController.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_CANCEL", comment:""), style: .cancel, handler: { [weak self] action in
+            self?.dialogProvider.dismissDialog(withReference: reference)
+        }))
+        if askingForStorage {
+            alertController.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_SAVE", comment:""), style: .default, handler: {[weak self] action in
+                let username = usernameField?.text ?? ""
+                let password = passwordField?.text ?? ""
+                self?.dialogProvider.postUsername(username, andPassword: password, forDialogReference: reference, store: true)
+            }))
+        }
+
+        UIApplication.shared.delegate?.window??.rootViewController?.presentedViewController?.present(alertController, animated: true, completion: nil)
+    }
+
+    public func showQuestion(withTitle title: String, message: String, type questionType: VLCDialogQuestionType, cancel cancelString: String?, action1String: String?, action2String: String?, withReference reference: NSValue) {
+        let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
+
+        if let cancelTitle = cancelString {
+            alertController.addAction(UIAlertAction(title: cancelTitle, style: .cancel, handler: { [weak self] action in
+                self?.dialogProvider.postAction(3, forDialogReference: reference)
+            }))
+        }
+        if let action1Ttile = action1String {
+            let confirmAction = UIAlertAction(title: action1Ttile, style: .default, handler: { [weak self] action in
+                self?.dialogProvider.postAction(1, forDialogReference: reference)
+            })
+            alertController.addAction(confirmAction)
+            alertController.preferredAction = confirmAction
+        }
+
+        if let action2Title = action2String {
+            alertController.addAction(UIAlertAction(title: action2Title, style: .default, handler: {[weak self] action in
+                self?.dialogProvider.postAction(2, forDialogReference: reference)
+            }))
+        }
+        UIApplication.shared.delegate?.window??.rootViewController?.presentedViewController?.present(alertController, animated: true, completion: nil)
+    }
+
+    public func showProgress(withTitle title: String, message: String, isIndeterminate: Bool, position: Float, cancel cancelString: String?, withReference reference: NSValue) {
+        print("title: \(title), message: \(message), isIndeterminate: \(isIndeterminate), position: \(position), cancel: \(cancelString ?? ""), reference: \(reference)")
+    }
+
+    public func updateProgress(withReference reference: NSValue, message: String?, postion position: Float) {
+        print("reference: \(reference) message: \(message ?? "") position: \(position)")
+    }
+
+    public func cancelDialog(withReference reference: NSValue) {
+        UIApplication.shared.delegate?.window??.rootViewController?.presentedViewController?.dismiss(animated: true, completion: nil)
+    }
+}

+ 2 - 0
Sources/VLCPlaybackController.h

@@ -24,6 +24,7 @@ extern NSString *const VLCPlaybackControllerPlaybackPositionUpdated;
 
 @class VLCPlaybackController;
 @class VLCMetaData;
+@class VLCDialogProvider;
 
 @protocol VLCPlaybackControllerDelegate <NSObject>
 @optional
@@ -90,6 +91,7 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
 @property (readonly) NSNumber *playbackTime;
 @property (nonatomic, readonly) NSDictionary *mediaOptionsDictionary;
 @property (nonatomic, readonly) NSTimer *sleepTimer;
+@property (nonatomic, readonly) VLCDialogProvider *dialogProvider;
 
 @property (nonatomic) VLCRendererItem * _Nullable renderer;
 

+ 2 - 4
Sources/VLCPlaybackController.m

@@ -70,8 +70,6 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
 
     NSLock *_playbackSessionManagementLock;
 
-    VLCDialogProvider *_dialogProvider;
-
     NSMutableArray *_shuffleStack;
     void (^_playbackCompletion)(BOOL success);
 }
@@ -121,7 +119,8 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
                               name:UIApplicationDidEnterBackgroundNotification object:nil];
 
         _metadata = [VLCMetaData new];
-        _dialogProvider = [[VLCDialogProvider alloc] initWithLibrary:[VLCLibrary sharedLibrary] customUI:NO];
+        _dialogProvider = [[VLCDialogProvider alloc] initWithLibrary:[VLCLibrary sharedLibrary] customUI:YES];
+        _dialogProvider.customRenderer = self;
 
         _playbackSessionManagementLock = [[NSLock alloc] init];
         _shuffleMode = NO;
@@ -1350,5 +1349,4 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
     _renderer = renderer;
     [_mediaPlayer setRendererItem:_renderer];
 }
-
 @end

+ 4 - 0
VLC.xcodeproj/project.pbxproj

@@ -42,6 +42,7 @@
 		418B145920179E50000447AA /* VLCDragAndDropManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 418B145820179E50000447AA /* VLCDragAndDropManager.swift */; };
 		418E88412110E51B00DDA6A7 /* URLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 418E88402110E51B00DDA6A7 /* URLHandler.swift */; };
 		4195747D206A92ED00393A42 /* RemoteNetworkDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4195747C206A92ED00393A42 /* RemoteNetworkDataSource.swift */; };
+		418DFE9F211C93C6005D3652 /* VLCPlaybackController+VLCDialogProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 418DFE9E211C93C6005D3652 /* VLCPlaybackController+VLCDialogProvider.swift */; };
 		419A2C661F37A4B70069D224 /* VLCStringsForLocalization.m in Sources */ = {isa = PBXBuildFile; fileRef = 419A2C651F37A4B70069D224 /* VLCStringsForLocalization.m */; };
 		419A2C681F37A4B70069D224 /* VLCStringsForLocalization.m in Sources */ = {isa = PBXBuildFile; fileRef = 419A2C651F37A4B70069D224 /* VLCStringsForLocalization.m */; };
 		419D7F051F54176900AF69A2 /* VLCTimeNavigationTitleView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 419D7F041F54176900AF69A2 /* VLCTimeNavigationTitleView.xib */; };
@@ -589,6 +590,7 @@
 		418B145820179E50000447AA /* VLCDragAndDropManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = VLCDragAndDropManager.swift; path = Sources/VLCDragAndDropManager.swift; sourceTree = "<group>"; };
 		418E88402110E51B00DDA6A7 /* URLHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = URLHandler.swift; path = Sources/URLHandler.swift; sourceTree = "<group>"; };
 		4195747C206A92ED00393A42 /* RemoteNetworkDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteNetworkDataSource.swift; sourceTree = "<group>"; };
+		418DFE9E211C93C6005D3652 /* VLCPlaybackController+VLCDialogProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "VLCPlaybackController+VLCDialogProvider.swift"; sourceTree = "<group>"; };
 		419A2C651F37A4B70069D224 /* VLCStringsForLocalization.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCStringsForLocalization.m; sourceTree = "<group>"; };
 		419D7F041F54176900AF69A2 /* VLCTimeNavigationTitleView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = VLCTimeNavigationTitleView.xib; path = Resources/VLCTimeNavigationTitleView.xib; sourceTree = SOURCE_ROOT; };
 		41B0948420E6851200DE38AD /* VLCMediaSubcategory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VLCMediaSubcategory.swift; sourceTree = "<group>"; };
@@ -1993,6 +1995,7 @@
 				DD510B6F1B14E564003BA71C /* VLCPlayerDisplayController.m */,
 				417D7F5E1F7BA26200DDF36A /* VLCRemoteControlService.h */,
 				417D7F5F1F7BA26200DDF36A /* VLCRemoteControlService.m */,
+				418DFE9E211C93C6005D3652 /* VLCPlaybackController+VLCDialogProvider.swift */,
 			);
 			name = Playback;
 			sourceTree = "<group>";
@@ -3380,6 +3383,7 @@
 				DDF908D01CF4CCAA00108B70 /* VLCNetworkLoginViewButtonCell.m in Sources */,
 				DD3EFF3D1BDEBCE500B68579 /* VLCLocalNetworkServiceBrowserHTTP.m in Sources */,
 				DDEAECBE1BDEBF6700756C83 /* VLCNetworkServerLoginInformation.m in Sources */,
+				418DFE9F211C93C6005D3652 /* VLCPlaybackController+VLCDialogProvider.swift in Sources */,
 				7D92897A1877467E009108FD /* VLCFirstStepsFourthPageViewController.m in Sources */,
 				DD3EFF391BDEBCE500B68579 /* VLCLocalNetworkServiceVLCMedia.m in Sources */,
 				DD3EFF5D1BDEBCE500B68579 /* VLCLocalServerDiscoveryController.m in Sources */,