marinofaggiana 3 years ago
parent
commit
371c1129cc

+ 12 - 0
iOSClient/Images.xcassets/repeat.imageset/Contents.json

@@ -0,0 +1,12 @@
+{
+  "images" : [
+    {
+      "filename" : "repeat.svg",
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

+ 1 - 0
iOSClient/Images.xcassets/repeat.imageset/repeat.svg

@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M17,17H7V14L3,18L7,22V19H19V13H17M7,7H17V10L21,6L17,2V5H5V11H7V7Z" /></svg>

+ 10 - 0
iOSClient/Menu/NCViewer+Menu.swift

@@ -299,6 +299,16 @@ extension NCViewer {
                     }
                 )
             )
+            
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_go_to_page_", comment: ""),
+                    icon: NCUtility.shared.loadImage(named: "repeat"),
+                    action: { menuAction in
+                        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterMenuGotToPageInPDF)
+                    }
+                )
+            )
         }
         
         //

+ 1 - 0
iOSClient/NCGlobal.swift

@@ -313,6 +313,7 @@ class NCGlobal: NSObject {
 
     let notificationCenterMenuSearchTextPDF                     = "menuSearchTextPDF"
     let notificationCenterMenuPDFDisplayDirection               = "menuPDFDisplayDirection"         // userInfo: direction
+    let notificationCenterMenuGotToPageInPDF                    = "menuGotToPageInPDF"
     let notificationCenterMenuDetailClose                       = "menuDetailClose"
     
     let notificationCenterChangedLocation                       = "changedLocation"

+ 5 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -807,3 +807,8 @@
 "_open_in_onlyoffice_"      = "Open in ONLYOFFICE";
 "_open_in_collabora_"       = "Open with Collabora Online";
 "_login_address_detail_"    = "The link to your %@ web interface when you open it in the browser.";
+"_go_to_page_"              = "Go to page";
+"_page_"                    = "Page";
+"_this_document_has_%@_pages_"              = "This document has %@ pages";
+"_invalid_page_"                            = "Invalid Page";
+"_the_entered_page_number_doesn't_exist_"   = "The entered page number doesn't exist";

+ 5 - 5
iOSClient/Viewer/NCViewerImage/NCViewerImage.storyboard

@@ -236,7 +236,7 @@
                                                 <rect key="frame" x="0.0" y="0.0" width="364" height="100"/>
                                             </button>
                                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8AB-hx-yqN">
-                                                <rect key="frame" x="328.99999999999994" y="67.666666666666629" width="25" height="25"/>
+                                                <rect key="frame" x="328.99999999999994" y="62.666666666666629" width="25" height="25"/>
                                                 <constraints>
                                                     <constraint firstAttribute="width" constant="25" id="6yU-23-dkA"/>
                                                     <constraint firstAttribute="height" constant="25" id="hBk-Ku-BAd"/>
@@ -251,7 +251,7 @@
                                                 <rect key="frame" x="8" y="15" width="348" height="31"/>
                                             </slider>
                                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="x3E-b2-obf">
-                                                <rect key="frame" x="162" y="60" width="40" height="40"/>
+                                                <rect key="frame" x="162" y="55" width="40" height="40"/>
                                                 <constraints>
                                                     <constraint firstAttribute="width" constant="40" id="Cmv-LX-Phg"/>
                                                     <constraint firstAttribute="height" constant="40" id="djE-Ml-YD0"/>
@@ -278,7 +278,7 @@
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="F9L-PP-AbM">
-                                                <rect key="frame" x="251.99999999999994" y="67.666666666666629" width="25" height="25"/>
+                                                <rect key="frame" x="251.99999999999994" y="62.666666666666629" width="25" height="25"/>
                                                 <constraints>
                                                     <constraint firstAttribute="width" constant="25" id="hlL-XQ-OLa"/>
                                                     <constraint firstAttribute="height" constant="25" id="vEe-Fb-a9N"/>
@@ -289,7 +289,7 @@
                                                 </connections>
                                             </button>
                                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Isy-sX-Gji">
-                                                <rect key="frame" x="87" y="67.666666666666629" width="25" height="25"/>
+                                                <rect key="frame" x="87" y="62.666666666666629" width="25" height="25"/>
                                                 <constraints>
                                                     <constraint firstAttribute="width" constant="25" id="COm-r2-ubw"/>
                                                     <constraint firstAttribute="height" constant="25" id="mbb-ql-zCc"/>
@@ -303,7 +303,7 @@
                                         <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                         <constraints>
                                             <constraint firstAttribute="trailing" secondItem="8AB-hx-yqN" secondAttribute="trailing" constant="10" id="4LY-8e-z3y"/>
-                                            <constraint firstAttribute="bottom" secondItem="x3E-b2-obf" secondAttribute="bottom" id="7W8-qk-uwn"/>
+                                            <constraint firstAttribute="bottom" secondItem="x3E-b2-obf" secondAttribute="bottom" constant="5" id="7W8-qk-uwn"/>
                                             <constraint firstAttribute="height" constant="100" id="EyI-HW-pHA"/>
                                             <constraint firstItem="Isy-sX-Gji" firstAttribute="centerY" secondItem="x3E-b2-obf" secondAttribute="centerY" id="Hif-Fa-xc2"/>
                                             <constraint firstItem="a0D-B0-eGX" firstAttribute="leading" secondItem="sBp-t2-eFh" secondAttribute="leading" id="OIL-1t-uuh"/>

+ 48 - 0
iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift

@@ -129,6 +129,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
         NotificationCenter.default.addObserver(self, selector: #selector(viewUnload), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuDetailClose), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(searchText), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuSearchTextPDF), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(direction(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuPDFDisplayDirection), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(goToPage), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuGotToPageInPDF), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(handlePageChange), name: Notification.Name.PDFViewPageChanged, object: nil)
         
         //
@@ -149,6 +150,9 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
 
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuDetailClose), object: nil)
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuSearchTextPDF), object: nil)
+        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuPDFDisplayDirection), object: nil)
+        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuGotToPageInPDF), object: nil)
+
         NotificationCenter.default.removeObserver(self, name: Notification.Name.PDFViewPageChanged, object: nil)
     }
     
@@ -208,6 +212,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
     }
     
     @objc func renameFile(_ notification: NSNotification) {
+        
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
                 
@@ -230,6 +235,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
     }
     
     @objc func direction(_ notification: NSNotification) {
+        
         if let userInfo = notification.userInfo as NSDictionary? {
             if let direction = userInfo["direction"] as? PDFDisplayDirection {
                 pdfView.displayDirection = direction
@@ -239,6 +245,28 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
         }
     }
     
+    @objc func goToPage() {
+
+        guard let pdfDocument = pdfView.document else { return }
+
+        let alertMessage = NSString(format: NSLocalizedString("_this_document_has_%@_pages_", comment: "") as NSString, "\(pdfDocument.pageCount)") as String
+        let alertController = UIAlertController(title: NSLocalizedString("_go_to_page_", comment: ""), message: alertMessage, preferredStyle: .alert)
+        alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil))
+
+        alertController.addTextField(configurationHandler: { textField in
+            textField.placeholder = NSLocalizedString("_page_", comment: "")
+            textField.keyboardType = .decimalPad
+        })
+
+        alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { [unowned self] _ in
+            if let pageLabel = alertController.textFields?.first?.text {
+                self.selectPage(with: pageLabel)
+            }
+        }))
+
+        self.present(alertController, animated: true)
+    }
+
     //MARK: - Action
     
     @objc func openMenuMore() {
@@ -286,8 +314,28 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
     }
     
     func searchPdfSelection(_ pdfSelection: PDFSelection) {
+        
         pdfSelection.color = .yellow
         pdfView.currentSelection = pdfSelection
         pdfView.go(to: pdfSelection)
     }
+    
+    private func selectPage(with label:String) {
+        
+        guard let pdf = pdfView.document else { return }
+
+         if let pageNr = Int(label) {
+             if pageNr > 0 && pageNr <= pdf.pageCount {
+                 if let page = pdf.page(at: pageNr - 1) {
+                     self.pdfView.go(to: page)
+                 }
+             } else {
+                 let alertController = UIAlertController(title: NSLocalizedString("_invalid_page_", comment: ""),
+                                                         message: NSLocalizedString("_the_entered_page_number_doesn't_exist_", comment: ""),
+                                                         preferredStyle: .alert)
+                 alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: nil))
+                 self.present(alertController, animated: true, completion: nil)
+             }
+         }
+     }
 }