marinofaggiana %!s(int64=6) %!d(string=hai) anos
pai
achega
36f0097d71

+ 1 - 1
iOSClient/Main/CCMain.h

@@ -47,7 +47,7 @@
 
 @class tableMetadata;
 
-@interface CCMain : UIViewController <UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, UIDocumentInteractionControllerDelegate, UIViewControllerPreviewingDelegate, BKPasscodeViewControllerDelegate, UISplitViewControllerDelegate, UIPopoverControllerDelegate, CCShareOCDelegate, CCPeekPopDelegate, UIDocumentMenuDelegate, UIDocumentPickerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, UIScrollViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
+@interface CCMain : UIViewController <UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, UIDocumentInteractionControllerDelegate, UIViewControllerPreviewingDelegate, BKPasscodeViewControllerDelegate, UISplitViewControllerDelegate, UIPopoverControllerDelegate, CCShareOCDelegate, UIDocumentMenuDelegate, UIDocumentPickerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, UIScrollViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
 
 @property (nonatomic, weak) IBOutlet UITableView *tableView;
 @property (nonatomic, strong) tableMetadata *metadata;

+ 0 - 2
iOSClient/Main/CCMain.m

@@ -937,9 +937,7 @@
         previewingContext.sourceRect = cell.frame;
         CCPeekPop *vc = [[UIStoryboard storyboardWithName:@"CCPeekPop" bundle:nil] instantiateViewControllerWithIdentifier:@"PeekPopImagePreview"];
             
-        vc.delegate = self;
         vc.metadata = metadata;
-            
         return vc;
     }
     

+ 36 - 2
iOSClient/Media/NCMedia.swift

@@ -96,6 +96,11 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
         
         // Notification
         NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
+        
+        // 3D Touch peek and pop
+        if traitCollection.forceTouchCapability == .available {
+            registerForPreviewing(with: self, sourceView: view)
+        }
     }
     
     override func viewWillAppear(_ animated: Bool) {
@@ -351,6 +356,35 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
     }
 }
 
+// MARK: - 3D Touch peek and pop
+
+extension NCMedia: UIViewControllerPreviewingDelegate {
+    
+    func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
+        
+        let offsetPoint = collectionView.contentOffset
+        let realLocation = CGPoint(x: location.x + offsetPoint.x, y: location.y + offsetPoint.y)
+
+        guard let indexPath = collectionView?.indexPathForItem(at: realLocation) else { return nil }
+        guard let metadata = NCMainCommon.sharedInstance.getMetadataFromSectionDataSourceIndexPath(indexPath, sectionDataSource: sectionDatasource) else { return nil }
+        guard let cell = collectionView?.cellForItem(at: indexPath) else { return nil }
+        guard let viewController = UIStoryboard(name: "CCPeekPop", bundle: nil).instantiateViewController(withIdentifier: "PeekPopImagePreview") as? CCPeekPop else { return nil }
+        
+        previewingContext.sourceRect = cell.frame
+        viewController.metadata = metadata
+        viewController.hideOpenIn = true
+        
+        return viewController
+    }
+    
+    func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
+        
+        guard let indexPath = collectionView?.indexPathForItem(at: previewingContext.sourceRect.origin) else { return }
+        
+        collectionView(collectionView, didSelectItemAt: indexPath)
+    }
+}
+
 // MARK: - Collection View
 
 extension NCMedia: UICollectionViewDelegate {
@@ -457,7 +491,7 @@ extension NCMedia: UICollectionViewDelegateFlowLayout {
     }
 }
 
-// MARK: NC API & Algorithm
+// MARK: - NC API & Algorithm
 
 extension NCMedia {
 
@@ -672,7 +706,7 @@ extension NCMedia {
     }
 }
 
-// MARK: FastScroll - ScrollView
+// MARK: - FastScroll - ScrollView
 
 extension NCMedia: UIScrollViewDelegate {
     func scrollViewDidScroll(_ scrollView: UIScrollView) {

+ 1 - 8
iOSClient/PeekPop/CCPeekPop.h

@@ -26,19 +26,12 @@
 
 @class tableMetadata;
 
-@protocol CCPeekPopDelegate;
-
 @interface CCPeekPop : UIViewController
 
-@property (nonatomic, weak) id <CCPeekPopDelegate> delegate;
-
 @property (nonatomic, strong) tableMetadata *metadata;
+@property BOOL hideOpenIn;
 
 @property (nonatomic, weak) IBOutlet UILabel *fileName;
 @property (nonatomic, weak) IBOutlet UIImageView *imagePreview;
 
 @end
-
-@protocol CCPeekPopDelegate <NSObject>
-
-@end

+ 10 - 4
iOSClient/PeekPop/CCPeekPop.m

@@ -30,6 +30,7 @@
 @interface CCPeekPop ()
 {
     AppDelegate *appDelegate;
+    NSInteger highLabelFileName;
 }
 @end
 
@@ -49,6 +50,7 @@
     UIImage *image;
 
     self.fileName.text = self.metadata.fileNameView;
+    highLabelFileName = self.fileName.bounds.size.height + 5;
     
     if (self.metadata.hasPreview) {
         
@@ -60,7 +62,7 @@
             self.imagePreview.image = image;
         
             self.imagePreview.contentMode = UIViewContentModeScaleToFill;
-            self.preferredContentSize = CGSizeMake(image.size.width, image.size.height);
+            self.preferredContentSize = CGSizeMake(image.size.width, image.size.height + highLabelFileName);
             
         } else {
             
@@ -89,7 +91,7 @@
         
         self.imagePreview.image = image;
         self.imagePreview.contentMode = UIViewContentModeCenter;
-        self.preferredContentSize = CGSizeMake(image.size.width, image.size.height + 100);
+        self.preferredContentSize = CGSizeMake(image.size.width, image.size.height + highLabelFileName);
     }
 }
 
@@ -100,6 +102,10 @@
 
 - (NSArray<id<UIPreviewActionItem>> *)previewActionItems
 {
+    if (self.hideOpenIn) {
+        return @[];
+    }
+    
     UIPreviewAction *previewAction1 = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_open_in_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action,  UIViewController *previewViewController){
         
         self.metadata.session = k_download_session;
@@ -131,7 +137,7 @@
             self.imagePreview.image = image;
             
             self.imagePreview.contentMode = UIViewContentModeScaleToFill;
-            self.preferredContentSize = CGSizeMake(image.size.width, image.size.height);
+            self.preferredContentSize = CGSizeMake(image.size.width, image.size.height + highLabelFileName);
             
         } else {
             
@@ -142,7 +148,7 @@
             }
             
             self.imagePreview.contentMode = UIViewContentModeCenter;
-            self.preferredContentSize = CGSizeMake(self.imagePreview.image.size.width, self.imagePreview.image.size.height + 100);
+            self.preferredContentSize = CGSizeMake(self.imagePreview.image.size.width, self.imagePreview.image.size.height + highLabelFileName);
         }
     }];
 }