marinofaggiana 6 лет назад
Родитель
Сommit
48f198cc68

+ 1 - 2
iOSClient/Favorites/CCFavorites.h

@@ -35,7 +35,7 @@
 
 
 @class tableMetadata;
 @class tableMetadata;
 
 
-@interface CCFavorites : UIViewController <UITableViewDataSource, UITableViewDelegate, UIDocumentInteractionControllerDelegate, UIActionSheetDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate, MGSwipeTableCellDelegate>
+@interface CCFavorites : UIViewController <UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate, MGSwipeTableCellDelegate>
 
 
 @property (nonatomic, weak) IBOutlet UITableView *tableView;
 @property (nonatomic, weak) IBOutlet UITableView *tableView;
 
 
@@ -47,7 +47,6 @@
 @property (nonatomic, weak) CCDetail *detailViewController;
 @property (nonatomic, weak) CCDetail *detailViewController;
 
 
 - (void)shouldPerformSegue:(tableMetadata *)metadata;
 - (void)shouldPerformSegue:(tableMetadata *)metadata;
-- (void)openIn:(tableMetadata *)metadata;
 - (void)reloadDatasource:(NSString *)fileID action:(NSInteger)action;
 - (void)reloadDatasource:(NSString *)fileID action:(NSInteger)action;
 - (void)listingFavorites;
 - (void)listingFavorites;
 
 

+ 1 - 36
iOSClient/Favorites/CCFavorites.m

@@ -252,27 +252,6 @@
     }];
     }];
 }
 }
 
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ==== Open in... ====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)openIn:(tableMetadata *)metadata
-{
-    NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]];
-        
-    docController = [UIDocumentInteractionController interactionControllerWithURL:url];
-    docController.delegate = self;
-        
-    NSIndexPath *indexPath = [sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
-    CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
-
-    if (cell) {
-        [docController presentOptionsMenuFromRect:cell.frame inView:self.tableView animated:YES];
-    } else {
-        [docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
-    }
-}
-
 - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
 - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
 {
 {
     CGPoint location = [tapGesture locationInView:self.tableView];
     CGPoint location = [tapGesture locationInView:self.tableView];
@@ -473,21 +452,7 @@
         [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil) image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"openFile"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement] backgroundColor:[NCBrandColor sharedInstance].backgroundView height: 50.0 type:AHKActionSheetButtonTypeDefault handler:^(AHKActionSheet *as) {
         [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil) image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"openFile"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement] backgroundColor:[NCBrandColor sharedInstance].backgroundView height: 50.0 type:AHKActionSheetButtonTypeDefault handler:^(AHKActionSheet *as) {
             [self.tableView setEditing:NO animated:YES];
             [self.tableView setEditing:NO animated:YES];
             
             
-            if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView]) {
-                [self openIn:metadata];
-            } else {
-                
-                metadata.session = k_download_session;
-                metadata.sessionError = @"";
-                metadata.sessionSelector = selectorOpenIn;
-                metadata.status = k_metadataStatusWaitDownload;
-                
-                // Add Metadata for Download
-                tableMetadata *metadataForDownload = [[NCManageDatabase sharedInstance] addMetadata:metadata];
-                [[CCNetworking sharedNetworking] downloadFile:metadataForDownload taskStatus:k_taskStatusResume];
-                
-                [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl fileID:metadataForDownload.fileID action:k_action_MOD];
-            }
+            [[NCMainCommon sharedInstance] downloadOpenInMetadata:metadata];
         }];
         }];
     }
     }
     
     

+ 1 - 3
iOSClient/Main/CCMain.h

@@ -47,7 +47,7 @@
 
 
 @class tableMetadata;
 @class tableMetadata;
 
 
-@interface CCMain : UIViewController <UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, UIDocumentInteractionControllerDelegate, UIViewControllerPreviewingDelegate, BKPasscodeViewControllerDelegate, UISplitViewControllerDelegate, UIPopoverControllerDelegate, CCShareOCDelegate, UIDocumentMenuDelegate, UIDocumentPickerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, UIScrollViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
+@interface CCMain : UIViewController <UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, UIViewControllerPreviewingDelegate, BKPasscodeViewControllerDelegate, UISplitViewControllerDelegate, UIPopoverControllerDelegate, CCShareOCDelegate, UIDocumentMenuDelegate, UIDocumentPickerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, UIScrollViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
 
 
 @property (nonatomic, weak) IBOutlet UITableView *tableView;
 @property (nonatomic, weak) IBOutlet UITableView *tableView;
 @property (nonatomic, strong) tableMetadata *metadata;
 @property (nonatomic, strong) tableMetadata *metadata;
@@ -61,8 +61,6 @@
 @property (nonatomic, strong) UITapGestureRecognizer *singleFingerTap;
 @property (nonatomic, strong) UITapGestureRecognizer *singleFingerTap;
 @property BOOL isSelectedMode;
 @property BOOL isSelectedMode;
 
 
-- (void)openIn:(tableMetadata *)metadata;
-
 - (void)shouldPerformSegue:(tableMetadata *)metadata;
 - (void)shouldPerformSegue:(tableMetadata *)metadata;
 
 
 - (void)saveToPhotoAlbum:(tableMetadata *)metadata;
 - (void)saveToPhotoAlbum:(tableMetadata *)metadata;

+ 2 - 38
iOSClient/Main/CCMain.m

@@ -52,7 +52,6 @@
     NSDate *_lockUntilDate;
     NSDate *_lockUntilDate;
 
 
     UIRefreshControl *refreshControl;
     UIRefreshControl *refreshControl;
-    UIDocumentInteractionController *docController;
 
 
     CCHud *_hud;
     CCHud *_hud;
     
     
@@ -2175,41 +2174,6 @@
     }];
     }];
 }
 }
 
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Open in... =====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)DownloadOpenIn:(tableMetadata *)metadata
-{
-    metadata.session = k_download_session;
-    metadata.sessionError = @"";
-    metadata.sessionSelector = selectorOpenIn;
-    metadata.status = k_metadataStatusWaitDownload;
-    
-    // Add Metadata for Download
-    (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
-    [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:metadata.fileID action:k_action_MOD];
-    
-    [appDelegate startLoadAutoDownloadUpload];
-}
-
-- (void)openIn:(tableMetadata *)metadata
-{
-    NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]];
-    
-    docController = [UIDocumentInteractionController interactionControllerWithURL:url];
-    docController.delegate = self;
-    
-    NSIndexPath *indexPath = [sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
-    CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
-    
-    if (cell) {
-        [docController presentOptionsMenuFromRect:cell.frame inView:self.tableView animated:YES];
-    } else {
-        [docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
-    }
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ==== Menu LOGO ====
 #pragma mark ==== Menu LOGO ====
 #pragma --------------------------------------------------------------------------------------------
 #pragma --------------------------------------------------------------------------------------------
@@ -2905,7 +2869,7 @@
 
 
 - (void)openinFile:(id)sender
 - (void)openinFile:(id)sender
 {
 {
-    [self DownloadOpenIn:self.metadata];
+    [[NCMainCommon sharedInstance] downloadOpenInMetadata:self.metadata];
 }
 }
 
 
 /************************************ PASTE ************************************/
 /************************************ PASTE ************************************/
@@ -3478,7 +3442,7 @@
                                      height: 50.0
                                      height: 50.0
                                        type:AHKActionSheetButtonTypeDefault
                                        type:AHKActionSheetButtonTypeDefault
                                     handler:^(AHKActionSheet *as) {
                                     handler:^(AHKActionSheet *as) {
-                                        [self performSelector:@selector(DownloadOpenIn:) withObject:self.metadata];
+                                        [self performSelector:@selector(openinFile:) withObject:nil];
                                     }];
                                     }];
         }
         }
         
         

+ 48 - 16
iOSClient/Main/NCMainCommon.swift

@@ -24,7 +24,7 @@
 import Foundation
 import Foundation
 import TLPhotoPicker
 import TLPhotoPicker
 
 
-class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewControllerDelegate {
+class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewControllerDelegate, UIDocumentInteractionControllerDelegate {
     
     
     @objc static let sharedInstance: NCMainCommon = {
     @objc static let sharedInstance: NCMainCommon = {
         let instance = NCMainCommon()
         let instance = NCMainCommon()
@@ -32,7 +32,9 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
     }()
     }()
     
     
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
-    var metadata: tableMetadata?
+    var metadataEditPhoto: tableMetadata?
+    var docController: UIDocumentInteractionController?
+
     lazy var operationQueueReloadDatasource: OperationQueue = {
     lazy var operationQueueReloadDatasource: OperationQueue = {
         let queue = OperationQueue()
         let queue = OperationQueue()
         queue.name = "Reload main datasource queue"
         queue.name = "Reload main datasource queue"
@@ -955,7 +957,7 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
             return
             return
         }
         }
         
         
-        self.metadata = metadata
+        self.metadataEditPhoto = metadata
 
 
         let photoEditor = PhotoEditorViewController(nibName:"PhotoEditorViewController",bundle: Bundle(for: PhotoEditorViewController.self))
         let photoEditor = PhotoEditorViewController(nibName:"PhotoEditorViewController",bundle: Bundle(for: PhotoEditorViewController.self))
         
         
@@ -974,7 +976,7 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
     }
     }
     
     
     func doneEditing(image: UIImage) {
     func doneEditing(image: UIImage) {
-        guard let metadata = self.metadata else {
+        guard let metadata = self.metadataEditPhoto else {
             return
             return
         }
         }
         guard let path = CCUtility.getDirectoryProviderStorageFileID(metadata.fileID, fileNameView: metadata.fileNameView) else {
         guard let path = CCUtility.getDirectoryProviderStorageFileID(metadata.fileID, fileNameView: metadata.fileNameView) else {
@@ -1008,6 +1010,46 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
         print("Canceled")
         print("Canceled")
     }
     }
     
     
+    //MARK: - OpenIn
+    
+    @objc func downloadOpenIn(metadata: tableMetadata) {
+        
+        if CCUtility.fileProviderStorageExists(metadata.fileID, fileNameView: metadata.fileNameView) {
+            
+            openIn(metadata: metadata)
+            
+        } else {
+            
+            metadata.session = k_download_session
+            metadata.sessionError = ""
+            metadata.sessionSelector = selectorOpenIn
+            metadata.status = Int(k_metadataStatusWaitDownload)
+            
+            _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
+            reloadDatasource(ServerUrl: metadata.serverUrl, fileID: metadata.fileID, action: k_action_MOD)
+        }
+    }
+
+    func openIn(metadata: tableMetadata) {
+        
+        docController = UIDocumentInteractionController(url: NSURL(fileURLWithPath: CCUtility.getDirectoryProviderStorageFileID(metadata.fileID, fileNameView: metadata.fileNameView)) as URL)
+        docController?.delegate = self
+        
+        guard let splitViewController = self.appDelegate.window?.rootViewController as? UISplitViewController else {
+            return
+        }
+        
+        guard let view = splitViewController.viewControllers.first?.view else {
+            return
+        }
+        
+        guard let frame = splitViewController.viewControllers.first?.view.frame else {
+            return
+        }
+        
+        docController?.presentOptionsMenu(from: frame, in: view, animated: true)
+    }
+    
     //MARK: - NCAudioRecorder
     //MARK: - NCAudioRecorder
     
     
     func startAudioRecorder() {
     func startAudioRecorder() {
@@ -1171,12 +1213,7 @@ class NCNetworkingMain: NSObject, CCNetworkingDelegate {
                 
                 
                 if metadata.typeFile == k_metadataTypeFile_compress || metadata.typeFile == k_metadataTypeFile_unknown {
                 if metadata.typeFile == k_metadataTypeFile_compress || metadata.typeFile == k_metadataTypeFile_unknown {
 
 
-                    if appDelegate.activeMain.view.window != nil {
-                        appDelegate.activeMain.open(in: metadata)
-                    }
-                    if appDelegate.activeFavorites.view.window != nil {
-                        appDelegate.activeFavorites.open(in: metadata)
-                    }
+                    NCMainCommon.sharedInstance.openIn(metadata: metadata)
                     
                     
                 } else {
                 } else {
                     
                     
@@ -1192,12 +1229,7 @@ class NCNetworkingMain: NSObject, CCNetworkingDelegate {
             // Open in...
             // Open in...
             if selector == selectorOpenIn && UIApplication.shared.applicationState == UIApplication.State.active {
             if selector == selectorOpenIn && UIApplication.shared.applicationState == UIApplication.State.active {
 
 
-                if appDelegate.activeMain.view.window != nil {
-                    appDelegate.activeMain.open(in: metadata)
-                }
-                if appDelegate.activeFavorites.view.window != nil {
-                    appDelegate.activeFavorites.open(in: metadata)
-                }
+                NCMainCommon.sharedInstance.openIn(metadata: metadata)
             }
             }
             
             
             // Save to Photo Album
             // Save to Photo Album

+ 1 - 2
iOSClient/Media/NCMedia.swift

@@ -370,8 +370,7 @@ extension NCMedia: UIViewControllerPreviewingDelegate {
         previewingContext.sourceRect = cell.frame
         previewingContext.sourceRect = cell.frame
         viewController.metadata = metadata
         viewController.metadata = metadata
         viewController.imageFile = cell.imageItem.image
         viewController.imageFile = cell.imageItem.image
-        
-        viewController.hideAction = true
+        viewController.hideShare = true
         
         
         return viewController
         return viewController
     }
     }

+ 1 - 1
iOSClient/PeekPop/CCPeekPop.h

@@ -30,7 +30,7 @@
 
 
 @property (nonatomic, strong) tableMetadata *metadata;
 @property (nonatomic, strong) tableMetadata *metadata;
 @property (nonatomic, strong) UIImage *imageFile;
 @property (nonatomic, strong) UIImage *imageFile;
-@property BOOL hideAction;
+@property BOOL hideShare;
 
 
 @property (nonatomic, weak) IBOutlet UILabel *fileName;
 @property (nonatomic, weak) IBOutlet UILabel *fileName;
 @property (nonatomic, weak) IBOutlet UIImageView *imagePreview;
 @property (nonatomic, weak) IBOutlet UIImageView *imagePreview;

+ 7 - 14
iOSClient/PeekPop/CCPeekPop.m

@@ -83,21 +83,9 @@
 
 
 - (NSArray<id<UIPreviewActionItem>> *)previewActionItems
 - (NSArray<id<UIPreviewActionItem>> *)previewActionItems
 {
 {
-    if (self.hideAction) {
-        return @[];
-    }
-    
     UIPreviewAction *openIn = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_open_in_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action,  UIViewController *previewViewController){
     UIPreviewAction *openIn = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_open_in_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action,  UIViewController *previewViewController){
         
         
-        self.metadata.session = k_download_session;
-        self.metadata.sessionError = @"";
-        self.metadata.sessionSelector = selectorOpenIn;
-        self.metadata.status = k_metadataStatusWaitDownload;
-            
-        // Add Metadata for Download
-        (void)[[NCManageDatabase sharedInstance] addMetadata:_metadata];
-        
-        [appDelegate startLoadAutoDownloadUpload];
+        [[NCMainCommon sharedInstance] downloadOpenInMetadata:_metadata];
     }];
     }];
     
     
     UIPreviewAction *share = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_share_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action,  UIViewController *previewViewController){
     UIPreviewAction *share = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_share_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action,  UIViewController *previewViewController){
@@ -105,7 +93,12 @@
         [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:self.metadata];
         [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:self.metadata];
     }];
     }];
     
     
-    return @[openIn, share];
+    if (_hideShare == true) {
+        return @[openIn];
+
+    } else {
+        return @[openIn, share];
+    }
 }
 }
 
 
 #pragma --------------------------------------------------------------------------------------------
 #pragma --------------------------------------------------------------------------------------------