marinofaggiana 4 years ago
parent
commit
3f1cdf9728

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -298,6 +298,7 @@
 		F7F878AF1FB9E3B900599E4F /* NCEndToEndMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F878AD1FB9E3B900599E4F /* NCEndToEndMetadata.swift */; };
 		F7F8D71C1ED6183000E711F3 /* CCCellShareExt.m in Sources */ = {isa = PBXBuildFile; fileRef = F7F8D71A1ED6183000E711F3 /* CCCellShareExt.m */; };
 		F7F8D71D1ED6183000E711F3 /* CCCellShareExt.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7F8D71B1ED6183000E711F3 /* CCCellShareExt.xib */; };
+		F7F9D1BB25397CE000D9BFF5 /* NCViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F9D1BA25397CE000D9BFF5 /* NCViewer.swift */; };
 		F7FCFFD81D70798C000E6E29 /* CCPeekPop.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7FCFFD61D70798C000E6E29 /* CCPeekPop.storyboard */; };
 		F7FCFFE01D707B83000E6E29 /* CCPeekPop.m in Sources */ = {isa = PBXBuildFile; fileRef = F7FCFFDE1D707B83000E6E29 /* CCPeekPop.m */; };
 /* End PBXBuildFile section */
@@ -704,6 +705,7 @@
 		F7F8D7191ED6183000E711F3 /* CCCellShareExt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCCellShareExt.h; sourceTree = "<group>"; };
 		F7F8D71A1ED6183000E711F3 /* CCCellShareExt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCCellShareExt.m; sourceTree = "<group>"; };
 		F7F8D71B1ED6183000E711F3 /* CCCellShareExt.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CCCellShareExt.xib; sourceTree = "<group>"; };
+		F7F9D1BA25397CE000D9BFF5 /* NCViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCViewer.swift; sourceTree = "<group>"; };
 		F7FC7D551DC1F93800BB2C6A /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
 		F7FCFFD61D70798C000E6E29 /* CCPeekPop.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = CCPeekPop.storyboard; sourceTree = "<group>"; };
 		F7FCFFDD1D707B83000E6E29 /* CCPeekPop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPeekPop.h; sourceTree = "<group>"; };
@@ -1087,6 +1089,7 @@
 				F76D3CEF2428B3DD005DFA87 /* NCViewerPDF */,
 				F790110D21415BF600D7B136 /* NCViewerRichdocument.swift */,
 				F7C7B488245EBA4100D93E60 /* NCViewerQuickLook.swift */,
+				F7F9D1BA25397CE000D9BFF5 /* NCViewer.swift */,
 				F79630ED215527D40015EEA5 /* NCViewerVideo.swift */,
 			);
 			path = Viewer;
@@ -2053,6 +2056,7 @@
 				F760329F252F0F8E0015A421 /* NCTransferCell.swift in Sources */,
 				F7682FE023C36B0500983A04 /* NCMainTabBar.swift in Sources */,
 				F77B0E5F1D118A16002130FE /* CCSettings.m in Sources */,
+				F7F9D1BB25397CE000D9BFF5 /* NCViewer.swift in Sources */,
 				F70460522499061800BB98A7 /* NotificationCenter+MainThread.swift in Sources */,
 				F78F74362163781100C2ADAD /* NCTrash.swift in Sources */,
 				F7651A8B23A2A3F2001403D2 /* NCCreateFormUploadDocuments.swift in Sources */,

+ 9 - 25
iOSClient/Detail/NCDetailViewController.swift

@@ -384,23 +384,7 @@ class NCDetailViewController: UIViewController {
         // DOCUMENT
         if metadata.typeFile == k_metadataTypeFile_document {
             
-            // PDF
-            if metadata.contentType == "application/pdf" {
-                    
-                let frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
-                let viewerPDF = NCViewerPDF.init(frame: frame)
-                    
-                let filePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
-                if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) == false {
-                    
-                    return
-                }
-                    
-                viewerPDF.setupPdfView(filePath: URL(fileURLWithPath: filePath), view: view)
-                self.navigationController?.navigationBar.topItem?.title = self.metadata!.fileNameView
-
-                return
-            }
+            
             
             // DirectEditinf: Nextcloud Text - OnlyOffice
             if NCUtility.shared.isDirectEditing(account: metadata.account, contentType: metadata.contentType) != nil &&  NCCommunication.shared.isNetworkReachable() {
@@ -533,18 +517,18 @@ extension NCDetailViewController: NCViewerImageViewControllerDelegate, NCViewerI
             self.viewerImageViewController = NCViewerImageViewController(index: index, dataSource: self, delegate: self)
             if self.viewerImageViewController != nil {
                            
-                self.viewerImageViewController!.view.isHidden = true
-                self.viewerImageViewController!.enableInteractiveDismissal = true
+//                self.viewerImageViewController!.view.isHidden = true
+//                self.viewerImageViewController!.enableInteractiveDismissal = true
                 self.addChild(self.viewerImageViewController!)
                 self.view.addSubview(self.viewerImageViewController!.view)
-                self.viewerImageViewController!.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
+//                self.viewerImageViewController!.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
                 self.viewerImageViewController!.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
-                self.viewerImageViewController!.didMove(toParent: self)
+//                self.viewerImageViewController!.didMove(toParent: self)
                 
-                DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {
-                    self.viewerImageViewController!.changeInViewSize(to: self.view.frame.size)
-                    self.viewerImageViewController!.view.isHidden = false
-                }
+//                DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {
+//                    self.viewerImageViewController!.changeInViewSize(to: self.view.frame.size)
+//                    self.viewerImageViewController!.view.isHidden = false
+//                }
             }
         }
     }

+ 1 - 12
iOSClient/Files/NCFiles.storyboard

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="EFX-fO-Oip">
     <device id="retina5_9" orientation="portrait" appearance="light"/>
     <dependencies>
         <deployment identifier="iOS"/>
@@ -43,22 +43,11 @@
                     </view>
                     <connections>
                         <outlet property="collectionView" destination="Zaz-Cl-qpZ" id="8oA-Gx-z7T"/>
-                        <segue destination="rIl-hI-jAh" kind="show" identifier="segueDetail" id="MHI-ti-PGq"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="JJ0-Le-6eT" userLabel="First Responder" sceneMemberID="firstResponder"/>
             </objects>
             <point key="canvasLocation" x="256.80000000000001" y="228.32512315270938"/>
         </scene>
-        <!--NCDetail-->
-        <scene sceneID="D5y-IR-BuC">
-            <objects>
-                <viewControllerPlaceholder storyboardName="NCDetail" referencedIdentifier="NCDetail" id="rIl-hI-jAh" sceneMemberID="viewController">
-                    <navigationItem key="navigationItem" id="nRf-yG-Cl8"/>
-                </viewControllerPlaceholder>
-                <placeholder placeholderIdentifier="IBFirstResponder" id="eCA-Ct-z68" userLabel="First Responder" sceneMemberID="firstResponder"/>
-            </objects>
-            <point key="canvasLocation" x="1080" y="228"/>
-        </scene>
     </scenes>
 </document>

+ 3 - 0
iOSClient/Main/Colleaction Common/NCCollectionViewCommon.swift

@@ -1218,6 +1218,9 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
             
         } else {
             
+            NCViewer.init(navigationController: self.navigationController!, metadata: metadataTouch!)
+            return
+            
             if metadata.typeFile == k_metadataTypeFile_video {
                 performSegue(withIdentifier: "segueDetail", sender: self)
                 return

+ 44 - 0
iOSClient/Viewer/NCViewer.swift

@@ -0,0 +1,44 @@
+//
+//  NCViewer.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 16/10/2020.
+//  Copyright © 2020 Marino Faggiana. All rights reserved.
+//
+//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+import Foundation
+
+class NCViewer: NSObject {
+    
+    init(navigationController: UINavigationController, metadata: tableMetadata) {
+        super.init()
+                
+        if metadata.typeFile == k_metadataTypeFile_document {
+                
+            // PDF
+            if metadata.contentType == "application/pdf" {
+                    
+                let ViewController:NCViewerPDF = UIStoryboard(name: "NCViewerPDF", bundle: nil).instantiateInitialViewController() as! NCViewerPDF
+                
+                ViewController.metadata = metadata
+                
+                navigationController.pushViewController(ViewController, animated: true)
+            }
+        }
+    }
+}

+ 23 - 1
iOSClient/Viewer/NCViewerPDF/NCViewerPDF.storyboard

@@ -1,9 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="whe-lk-OfI">
     <device id="retina5_5" orientation="portrait" appearance="light"/>
     <dependencies>
         <deployment identifier="iOS"/>
         <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17125"/>
+        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
+        <capability name="System colors in document resources" minToolsVersion="11.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <scenes>
@@ -26,6 +28,21 @@
             </objects>
             <point key="canvasLocation" x="26" y="1532"/>
         </scene>
+        <!--ViewerPDF-->
+        <scene sceneID="cMH-vX-JnR">
+            <objects>
+                <viewController hidesBottomBarWhenPushed="YES" id="whe-lk-OfI" customClass="NCViewerPDF" customModule="Nextcloud" customModuleProvider="target" sceneMemberID="viewController">
+                    <view key="view" contentMode="scaleToFill" id="IJJ-u9-0qv">
+                        <rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
+                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                        <viewLayoutGuide key="safeArea" id="QiL-bG-Ojl"/>
+                        <color key="backgroundColor" systemColor="systemBackgroundColor"/>
+                    </view>
+                </viewController>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="2am-kV-AB1" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
+            </objects>
+            <point key="canvasLocation" x="-716" y="779"/>
+        </scene>
         <!--Navigation Controller-->
         <scene sceneID="rmL-pT-QPn">
             <objects>
@@ -45,4 +62,9 @@
             <point key="canvasLocation" x="-715" y="1532"/>
         </scene>
     </scenes>
+    <resources>
+        <systemColor name="systemBackgroundColor">
+            <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+        </systemColor>
+    </resources>
 </document>

+ 43 - 37
iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift

@@ -24,9 +24,10 @@
 import Foundation
 import PDFKit
 
-@objc class NCViewerPDF: PDFView, NCViewerPDFSearchDelegate {
+@objc class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
     
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    private var pdfView = PDFView()
     private var thumbnailViewHeight: CGFloat = 40
     private var pdfThumbnailView: PDFThumbnailView?
     private var pdfDocument: PDFDocument?
@@ -34,36 +35,36 @@ import PDFKit
     private let pageViewLabel = UILabel()
     private var pageViewWidthAnchor : NSLayoutConstraint?
     
-    required init?(coder: NSCoder) {
-        super.init(coder: coder)
+    var metadata = tableMetadata()
+    
+    required init?(coder aDecoder: NSCoder) {
+        super.init(coder: aDecoder)
     }
     
-    override init(frame: CGRect) {
-        
-        let height = frame.height - thumbnailViewHeight
-        super.init(frame: CGRect(x: frame.origin.x, y: frame.origin.y, width: frame.width, height: height))
-        
+    override func viewDidLoad() {
+          
+        let filePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
+                
         NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: k_notificationCenter_changeTheming), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(searchText), name: NSNotification.Name(rawValue: k_notificationCenter_menuSearchTextPDF), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(handlePageChange), name: Notification.Name.PDFViewPageChanged, object: nil)
-    }
-    
-    @objc func setupPdfView(filePath: URL, view: UIView) {
-        pdfDocument = PDFDocument(url: filePath)
         
-        document = pdfDocument
-        backgroundColor = NCBrandColor.sharedInstance.backgroundView
-        displayMode = .singlePageContinuous
-        autoScales = true
-        displayDirection = .horizontal
-        autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleBottomMargin]
-        usePageViewController(true, withViewOptions: nil)
+        pdfView = PDFView.init(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height - thumbnailViewHeight))
+        pdfDocument = PDFDocument(url: URL(fileURLWithPath: filePath))
         
-        view.addSubview(self)
+        pdfView.document = pdfDocument
+        pdfView.backgroundColor = NCBrandColor.sharedInstance.backgroundView
+        pdfView.displayMode = .singlePageContinuous
+        pdfView.autoScales = true
+        pdfView.displayDirection = .horizontal
+        pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleBottomMargin]
+        pdfView.usePageViewController(true, withViewOptions: nil)
+        
+        view.addSubview(pdfView)
         
         pdfThumbnailView = PDFThumbnailView()
         pdfThumbnailView!.translatesAutoresizingMaskIntoConstraints = false
-        pdfThumbnailView!.pdfView = self
+        pdfThumbnailView!.pdfView = pdfView
         pdfThumbnailView!.layoutMode = .horizontal
         pdfThumbnailView!.thumbnailSize = CGSize(width: 40, height: thumbnailViewHeight)
         //pdfThumbnailView.layer.shadowOffset.height = -5
@@ -99,25 +100,31 @@ import PDFKit
         pageViewLabel.topAnchor.constraint(equalTo: pageView.topAnchor).isActive = true
         pageViewLabel.bottomAnchor.constraint(equalTo: pageView.bottomAnchor).isActive = true
         
-        layoutIfNeeded()
+        pdfView.layoutIfNeeded()
         handlePageChange()
         
         let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTap(_:)))
         tapGesture.numberOfTapsRequired = 1
-        addGestureRecognizer(tapGesture)
+        pdfView.addGestureRecognizer(tapGesture)
         
         // recognize single / double tap
-        for gesture in gestureRecognizers! {
+        for gesture in pdfView.gestureRecognizers! {
             tapGesture.require(toFail:gesture)
         }
     }
     
+    override func viewDidAppear(_ animated: Bool) {
+        super.viewDidAppear(animated)
+        
+        navigationController?.navigationBar.topItem?.title = metadata.fileNameView
+    }
+    
     //MARK: - NotificationCenter
     
     @objc private func handlePageChange() {
         
-        guard let curPage = currentPage?.pageRef?.pageNumber else { pageView.alpha = 0; return }
-        guard let totalPages = document?.pageCount else { return }
+        guard let curPage = pdfView.currentPage?.pageRef?.pageNumber else { pageView.alpha = 0; return }
+        guard let totalPages = pdfView.document?.pageCount else { return }
         
         pageView.alpha = 1
         pageViewLabel.text = String(curPage) + " " + NSLocalizedString("_of_", comment: "") + " " + String(totalPages)
@@ -132,41 +139,40 @@ import PDFKit
         guard let navigationController = appDelegate.activeDetail.navigationController else { return }
 
         if navigationController.isNavigationBarHidden == false {
-            backgroundColor = NCBrandColor.sharedInstance.backgroundView
+            pdfView.backgroundColor = NCBrandColor.sharedInstance.backgroundView
         }
     }
     
     //MARK: - Gesture Recognizer
     
     @objc func didTap(_ recognizer: UITapGestureRecognizer) {
-        guard let navigationController = appDelegate.activeDetail.navigationController else { return }
         
-        if navigationController.isNavigationBarHidden {
+        if navigationController?.isNavigationBarHidden ?? false {
             
             appDelegate.activeDetail.navigateControllerBarHidden(false)
             pdfThumbnailView!.isHidden = false
-            backgroundColor = NCBrandColor.sharedInstance.backgroundView
+            pdfView.backgroundColor = NCBrandColor.sharedInstance.backgroundView
             
         } else {
             
-            let point = recognizer.location(in: self)
-            if point.y > self.frame.height - thumbnailViewHeight { return }
+            let point = recognizer.location(in: pdfView)
+            if point.y > pdfView.frame.height - thumbnailViewHeight { return }
             
             appDelegate.activeDetail.navigateControllerBarHidden(true)
             pdfThumbnailView!.isHidden = true
-            backgroundColor = .black
+            pdfView.backgroundColor = .black
         }
 
         let size = self.appDelegate.activeDetail.view!.bounds
         var height: CGFloat = 0
             
-        if navigationController.isNavigationBarHidden {
+        if navigationController?.isNavigationBarHidden ?? false {
             height = size.height - size.origin.y
         } else {
             height = size.height - size.origin.y - self.thumbnailViewHeight
         }
              
-        self.frame = CGRect(x: 0, y: 0, width: size.width, height: height)
+        pdfView.frame = CGRect(x: 0, y: 0, width: size.width, height: height)
         
         handlePageChange()
     }
@@ -185,7 +191,7 @@ import PDFKit
     
     func searchPdfSelection(_ pdfSelection: PDFSelection) {
         pdfSelection.color = .yellow
-        currentSelection = pdfSelection
-        go(to: pdfSelection)
+        pdfView.currentSelection = pdfSelection
+        pdfView.go(to: pdfSelection)
     }
 }