瀏覽代碼

Improved code

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 年之前
父節點
當前提交
70f8a2aa42

+ 11 - 20
iOSClient/Main/Create cloud/NCUploadScanDocument.swift

@@ -44,7 +44,7 @@ class NCHostingUploadScanDocumentView: NSObject {
 class NCUploadScanDocument: ObservableObject {
 class NCUploadScanDocument: ObservableObject {
 
 
     @Published var isTextRecognition: Bool = false
     @Published var isTextRecognition: Bool = false
-    @Published var size: Int64 = 0
+    @Published var size: String = ""
     @Published var url: URL = Bundle.main.url(forResource: "Reasons to use Nextcloud", withExtension: "pdf")!
     @Published var url: URL = Bundle.main.url(forResource: "Reasons to use Nextcloud", withExtension: "pdf")!
     let fileNameDefault = NSTemporaryDirectory() + "scandocument.pdf"
     let fileNameDefault = NSTemporaryDirectory() + "scandocument.pdf"
 
 
@@ -55,7 +55,7 @@ class NCUploadScanDocument: ObservableObject {
         createPDF()
         createPDF()
     }
     }
 
 
-    func createPDF(preview: Bool = true, password: String = "", textRecognition: Bool = false, quality: Double = 1) {
+    func createPDF(password: String = "", textRecognition: Bool = false, quality: Double = 1) {
 
 
         guard !images.isEmpty else { return }
         guard !images.isEmpty else { return }
         let pdfData = NSMutableData()
         let pdfData = NSMutableData()
@@ -75,24 +75,15 @@ class NCUploadScanDocument: ObservableObject {
             UIGraphicsBeginPDFContextToData(pdfData, CGRect.zero, info)
             UIGraphicsBeginPDFContextToData(pdfData, CGRect.zero, info)
         }
         }
 
 
-        if preview {
-            if var image = images.first {
-                image = changeCompressionImage(image, quality: quality)
-                let bounds = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
-                UIGraphicsBeginPDFPageWithInfo(bounds, nil)
-                image.draw(in: bounds)
-            }
-        } else {
-            for var image in images {
+        for var image in images {
 
 
-                image = changeCompressionImage(image, quality: quality)
-                let bounds = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
-                if textRecognition {
+            image = changeCompressionImage(image, quality: quality)
+            let bounds = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
+            if textRecognition {
 
 
-                } else {
-                    UIGraphicsBeginPDFPageWithInfo(bounds, nil)
-                    image.draw(in: bounds)
-                }
+            } else {
+                UIGraphicsBeginPDFPageWithInfo(bounds, nil)
+                image.draw(in: bounds)
             }
             }
         }
         }
 
 
@@ -105,7 +96,7 @@ class NCUploadScanDocument: ObservableObject {
             print("error catched")
             print("error catched")
         }
         }
 
 
-        size = NCUtilityFileSystem.shared.getFileSize(filePath: fileNameDefault)
+        size = CCUtility.transformedSize(NCUtilityFileSystem.shared.getFileSize(filePath: fileNameDefault))
     }
     }
 
 
     func changeCompressionImage(_ image: UIImage, quality: Double) -> UIImage {
     func changeCompressionImage(_ image: UIImage, quality: Double) -> UIImage {
@@ -258,7 +249,7 @@ struct UploadScanDocumentView: View {
                     }
                     }
                 }
                 }
 
 
-                Section(header: Text(NSLocalizedString("_quality_image_title_", comment: ""))) {
+                Section(header: Text(NSLocalizedString("_quality_image_title_", comment: "")), footer: Text( NSLocalizedString("_file_size_", comment: "") + " \(uploadScanDocument.size)")) {
                     VStack {
                     VStack {
                         Slider(value: $quality, in: 0...4, step: 1).onChange(of: quality, perform: { quality in
                         Slider(value: $quality, in: 0...4, step: 1).onChange(of: quality, perform: { quality in
                             uploadScanDocument.createPDF(quality: quality)
                             uploadScanDocument.createPDF(quality: quality)

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

@@ -176,6 +176,7 @@
 "_automatic_Download_Image_" = "Use images in full resolution";
 "_automatic_Download_Image_" = "Use images in full resolution";
 "_automatic_Download_Image_footer_" = "When viewing images always download, if not available locally, the images in full resolution";
 "_automatic_Download_Image_footer_" = "When viewing images always download, if not available locally, the images in full resolution";
 "_size_"                    = "Size";
 "_size_"                    = "Size";
+"_file_size_"               = "Exported file size";
 "_dimension_"               = "Dimension";
 "_dimension_"               = "Dimension";
 "_duration_"                = "Duration";
 "_duration_"                = "Duration";
 "_model_"                   = "Model";
 "_model_"                   = "Model";