Browse Source

added print in menu

marinofaggiana 4 years ago
parent
commit
b8c43a765d

+ 15 - 0
iOSClient/Images.xcassets/print.imageset/Contents.json

@@ -0,0 +1,15 @@
+{
+  "images" : [
+    {
+      "filename" : "print.svg",
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  },
+  "properties" : {
+    "preserves-vector-representation" : true
+  }
+}

+ 1 - 0
iOSClient/Images.xcassets/print.imageset/print.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="M19 8C20.66 8 22 9.34 22 11V17H18V21H6V17H2V11C2 9.34 3.34 8 5 8H6V3H18V8H19M8 5V8H16V5H8M16 19V15H8V19H16M18 15H20V11C20 10.45 19.55 10 19 10H5C4.45 10 4 10.45 4 11V15H6V13H18V15M19 11.5C19 12.05 18.55 12.5 18 12.5C17.45 12.5 17 12.05 17 11.5C17 10.95 17.45 10.5 18 10.5C18.55 10.5 19 10.95 19 11.5Z" /></svg>

+ 20 - 0
iOSClient/Main/Colleaction Common/NCCollectionCommon.swift

@@ -287,6 +287,26 @@ class NCCollectionCommon: NSObject, NCSelectDelegate {
         })
         })
     }
     }
     
     
+    // MARK: - Print
+    
+    func printDocument(metadata: tableMetadata) {
+    
+        let fileNameURL = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!)
+        
+        if UIPrintInteractionController.canPrint(fileNameURL) {
+            
+            let printInfo = UIPrintInfo(dictionary: nil)
+            printInfo.jobName = fileNameURL.lastPathComponent
+            printInfo.outputType = .photo
+
+            let printController = UIPrintInteractionController.shared
+            printController.printInfo = printInfo
+            printController.showsNumberOfCopies = false
+            printController.printingItem = fileNameURL
+            printController.present(animated: true, completionHandler: nil)
+        }
+    }
+    
     // MARK: - Context Menu COnfiguration
     // MARK: - Context Menu COnfiguration
     
     
     @available(iOS 13.0, *)
     @available(iOS 13.0, *)

+ 19 - 0
iOSClient/Menu/NCCollectionViewCommon+Menu.swift

@@ -165,6 +165,25 @@ extension NCCollectionViewCommon {
             )
             )
         }
         }
         
         
+        //
+        // PRINT
+        //
+        if !metadata.directory && (metadata.typeFile == NCGlobal.shared.metadataTypeFileImage || metadata.contentType == "application/pdf") {
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_print_", comment: ""),
+                    icon: UIImage(named: "print")!.image(color: NCBrandColor.shared.icon, size: 50),
+                    action: { menuAction in
+                        if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
+                            NCCollectionCommon.shared.printDocument(metadata: metadata)
+                        } else {
+                            NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorPrint)
+                        }
+                    }
+                )
+            )
+        }
+        
         //
         //
         // SAVE
         // SAVE
         //
         //

+ 1 - 0
iOSClient/NCGlobal.swift

@@ -198,6 +198,7 @@ class NCGlobal: NSObject {
     let selectorLoadCopy                            = "loadCopy"
     let selectorLoadCopy                            = "loadCopy"
     let selectorLoadOffline                         = "loadOffline"
     let selectorLoadOffline                         = "loadOffline"
     let selectorOpenIn                              = "openIn"
     let selectorOpenIn                              = "openIn"
+    let selectorPrint                               = "print"
     let selectorUploadAutoUpload                    = "uploadAutoUpload"
     let selectorUploadAutoUpload                    = "uploadAutoUpload"
     let selectorUploadAutoUploadAll                 = "uploadAutoUploadAll"
     let selectorUploadAutoUploadAll                 = "uploadAutoUploadAll"
     let selectorUploadFile                          = "uploadFile"
     let selectorUploadFile                          = "uploadFile"

+ 4 - 0
iOSClient/Networking/NCNetworkingNotificationCenter.swift

@@ -108,6 +108,10 @@ import Foundation
                         
                         
                         NCManageDatabase.shared.setLocalFile(ocId: metadata.ocId, offline: true)
                         NCManageDatabase.shared.setLocalFile(ocId: metadata.ocId, offline: true)
                        
                        
+                    case NCGlobal.shared.selectorPrint:
+                        
+                        NCCollectionCommon.shared.printDocument(metadata: metadata)
+                        
                     case NCGlobal.shared.selectorSaveAlbum:
                     case NCGlobal.shared.selectorSaveAlbum:
                         
                         
                         NCCollectionCommon.shared.saveAlbum(metadata: metadata)
                         NCCollectionCommon.shared.saveAlbum(metadata: metadata)

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

@@ -161,6 +161,7 @@
 "_keep_"                    = "Keep";
 "_keep_"                    = "Keep";
 "_account_request_"         = "Request account";
 "_account_request_"         = "Request account";
 "_settings_account_request_" = "Request account at startup";
 "_settings_account_request_" = "Request account at startup";
+"_print_"                   = "Print";
 
 
 /* User status */
 /* User status */
 "_online_"                  = "Online";
 "_online_"                  = "Online";