Explorar o código

Edit: Add sharesheet

Carola Nitz %!s(int64=6) %!d(string=hai) anos
pai
achega
1d669824e9

+ 1 - 1
SharedSources/VLCActivityViewControllerVendor.h

@@ -12,6 +12,6 @@
 
 @interface VLCActivityViewControllerVendor : NSObject
 
-+ (UIActivityViewController *)activityViewControllerForFiles:(NSArray *)files presentingButton:(UIBarButtonItem *)button presentingViewController:(UIViewController *)controller;
++ (UIActivityViewController *)activityViewControllerForFiles:(NSArray *)files presentingButton:(UIButton *)button presentingViewController:(UIViewController *)controller;
 
 @end

+ 2 - 2
SharedSources/VLCActivityViewControllerVendor.m

@@ -16,7 +16,7 @@
 
 @implementation VLCActivityViewControllerVendor
 
-+ (UIActivityViewController *)activityViewControllerForFiles:(NSArray *)files presentingButton:(UIBarButtonItem *)button presentingViewController:(UIViewController *)viewController;
++ (UIActivityViewController *)activityViewControllerForFiles:(NSArray *)files presentingButton:(UIButton *)button presentingViewController:(UIViewController *)viewController;
 {
     if (![files count]) {
         [viewController vlc_showAlertWithTitle:NSLocalizedString(@"SHARING_ERROR_NO_FILES", nil)
@@ -27,7 +27,7 @@
 
     VLCOpenInActivity *openInActivity = [[VLCOpenInActivity alloc] init];
     openInActivity.presentingViewController = viewController;
-    openInActivity.presentingBarButtonItem = button;
+    openInActivity.presentingButton = button;
 
     UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:files applicationActivities:@[openInActivity]];
 

+ 23 - 2
Sources/VLCEditController.swift

@@ -140,8 +140,29 @@ extension VLCEditController: VLCEditToolbarDelegate {
                                                                 deleteButton])
     }
 
-    func editToolbarDidShare(_ editToolbar: VLCEditToolbar) {
-        assertionFailure("Implement me")
+    func editToolbarDidShare(_ editToolbar: VLCEditToolbar, presentFrom button: UIButton) {
+        UIApplication.shared.beginIgnoringInteractionEvents()
+        let rootViewController = UIApplication.shared.keyWindow?.rootViewController
+        guard let controller = VLCActivityViewControllerVendor.activityViewController(forFiles: fileURLsFromSelection(), presenting: button, presenting: rootViewController) else {
+            UIApplication.shared.endIgnoringInteractionEvents()
+            return
+        }
+        controller.popoverPresentationController?.sourceView = editToolbar
+        rootViewController?.present(controller, animated: true) {
+            UIApplication.shared.endIgnoringInteractionEvents()
+        }
+    }
+
+    func fileURLsFromSelection() -> [URL] {
+        var fileURLS = [URL]()
+        for indexPath in selectedCellIndexPaths {
+            guard let file = model.anyfiles[indexPath.row] as? VLCMLMedia else {
+                assertionFailure("we're trying to share something that doesn't have an mrl")
+                return fileURLS
+            }
+            fileURLS.append(file.mainFile().mrl)
+        }
+        return fileURLS
     }
 
     func editToolbarDidRename(_ editToolbar: VLCEditToolbar) {

+ 2 - 3
Sources/VLCEditToolbar.swift

@@ -13,8 +13,7 @@ protocol VLCEditToolbarDelegate: class {
     func editToolbarDidDelete(_ editToolbar: VLCEditToolbar)
     func editToolbarDidAddToPlaylist(_ editToolbar: VLCEditToolbar)
     func editToolbarDidRename(_ editToolbar: VLCEditToolbar)
-    func editToolbarDidShare(_ editToolbar: VLCEditToolbar)
-
+    func editToolbarDidShare(_ editToolbar: VLCEditToolbar, presentFrom button: UIButton)
 }
 
 class VLCEditToolbar: UIView {
@@ -69,7 +68,7 @@ class VLCEditToolbar: UIView {
     }
 
     @objc func share() {
-        delegate?.editToolbarDidShare(self)
+        delegate?.editToolbarDidShare(self, presentFrom: shareButton)
     }
 
     private func setupStackView() {

+ 1 - 1
Sources/VLCOpenInActivity.h

@@ -15,6 +15,6 @@
 @interface VLCOpenInActivity : UIActivity
 
 @property (nonatomic, weak) UIViewController *presentingViewController;
-@property (nonatomic, weak) UIBarButtonItem *presentingBarButtonItem;
+@property (nonatomic, weak) UIButton *presentingButton;
 
 @end

+ 4 - 3
Sources/VLCOpenInActivity.m

@@ -73,7 +73,7 @@
 
 - (void)performActivity
 {
-    if (!self.presentingViewController || !self.presentingBarButtonItem) {
+    if (!self.presentingViewController || !self.presentingButton) {
         [self activityDidFinish:NO];
         return;
     }
@@ -109,7 +109,7 @@
         return;
     }
 
-    if (!self.presentingBarButtonItem) {
+    if (!self.presentingButton) {
         [self activityDidFinish:NO];
         return;
     }
@@ -121,7 +121,8 @@
     __block BOOL controllerWasPresentedSuccessfully = NO;
 
     dispatch_block_t controllerPresentationBlock = ^{
-        controllerWasPresentedSuccessfully = [self->_documentInteractionController presentOpenInMenuFromBarButtonItem:self.presentingBarButtonItem animated:YES];
+
+        controllerWasPresentedSuccessfully = [self->_documentInteractionController presentOpenInMenuFromRect:self.presentingButton.frame inView: self.presentingViewController.view animated:YES];
 
         if (!controllerWasPresentedSuccessfully) {
             [VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"SHARING_ERROR_NO_APPLICATIONS", nil)

+ 2 - 0
VLC.xcodeproj/project.pbxproj

@@ -14,6 +14,7 @@
 		2915544317490D4A00B86CAD /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2915544217490D4A00B86CAD /* Security.framework */; };
 		411453B9219C48DA002D94E1 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 411453B8219C48DA002D94E1 /* Launch Screen.storyboard */; };
 		411DC0FD20F650B10044305E /* VLCMediaSubcategory+VLCDragAndDrop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 412BE7521FC4947400ACCC42 /* VLCMediaSubcategory+VLCDragAndDrop.swift */; };
+		412086362231FE43006A6630 /* UIViewController+VLCAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = DD3EABFB1BE14C4B003668DA /* UIViewController+VLCAlert.m */; };
 		41251ED01FD0CF7900099110 /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41251ECE1FD0CF7900099110 /* AppCoordinator.swift */; };
 		41273A3C1A955C4100A2EF77 /* VLCMigrationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 41273A3A1A955C4100A2EF77 /* VLCMigrationViewController.m */; };
 		41273A3D1A955C4100A2EF77 /* VLCMigrationViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 41273A3B1A955C4100A2EF77 /* VLCMigrationViewController.xib */; };
@@ -2891,6 +2892,7 @@
 				8DF966EF211C643D00D0FCD6 /* PlaylistModel.swift in Sources */,
 				9BADAF45185FBD9D00108BD8 /* VLCFrostedGlasView.m in Sources */,
 				41EC28E32136D905004BCF0F /* BaseCollectionViewCell.swift in Sources */,
+				412086362231FE43006A6630 /* UIViewController+VLCAlert.m in Sources */,
 				DDC10BE41AEE8EA700890DC3 /* VLCTimeNavigationTitleView.m in Sources */,
 				DD870E9A1CEF929A00BBD4FE /* VLCNetworkLoginViewFieldCell.m in Sources */,
 				4195747D206A92ED00393A42 /* RemoteNetworkDataSource.swift in Sources */,

+ 1 - 0
vlc-ios/VLC-iOS-Bridging-Header.h

@@ -25,6 +25,7 @@
 #import "IASKSettingsReader.h"
 #import "IASKSwitch.h"
 #import "VLCHTTPUploaderController.h"
+#import "VLCActivityViewControllerVendor.h"
 #import "VLCMediaFileDiscoverer.h"
 #import "VLCMigrationViewController.h"
 #import "VLCCloudStorageTableViewController.h"