Prechádzať zdrojové kódy

Improved code

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 rokov pred
rodič
commit
79ee45bc49

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

@@ -163,6 +163,20 @@ class NCUploadScanDocument: ObservableObject {
         }
     }
 
+    func removeAllFile() {
+
+        let path = CCUtility.getDirectoryScan()!
+
+        do {
+            let filePaths = try FileManager.default.contentsOfDirectory(atPath: path)
+            for filePath in filePaths {
+                try FileManager.default.removeItem(atPath: path + "/" + filePath)
+            }
+        } catch let error as NSError {
+            print("Error: \(error.debugDescription)")
+        }
+    }
+
     private func changeCompressionImage(_ image: UIImage, quality: Double) -> UIImage {
 
         var compressionQuality: CGFloat = 0.0
@@ -344,6 +358,8 @@ struct UploadScanDocumentView: View {
     @State var isPresentedSelect = false
     @State var isPresentedUploadConflict = false
 
+    @State var removeAllFiles = false
+
     var metadatasConflict: [tableMetadata] = []
 
     @ObservedObject var uploadScanDocument: NCUploadScanDocument
@@ -440,21 +456,28 @@ struct UploadScanDocumentView: View {
                         }
                     }
 
-                    Button(NSLocalizedString("_save_", comment: "")) {
-                        uploadScanDocument.showHUD.toggle()
-                        uploadScanDocument.save(fileName: fileName, password: password, isTextRecognition: isTextRecognition, quality: quality) { openConflictViewController in
+                    VStack(spacing: 20) {
+
+                        Toggle(NSLocalizedString("_delete_all_scanned_images_", comment: ""), isOn: $removeAllFiles)
+                            .toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand)))
+                            .onChange(of: removeAllFiles) { newValue in
+
+                            }
+
+                        Button(NSLocalizedString("_save_", comment: "")) {
                             uploadScanDocument.showHUD.toggle()
-                            if openConflictViewController {
-                                isPresentedUploadConflict = true
-                            } else {
-                                NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDismissScanDocument)
+                            uploadScanDocument.save(fileName: fileName, password: password, isTextRecognition: isTextRecognition, quality: quality) { openConflictViewController in
+                                uploadScanDocument.showHUD.toggle()
+                                if openConflictViewController {
+                                    isPresentedUploadConflict = true
+                                } else {
+                                    NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDismissScanDocument)
+                                }
                             }
                         }
+                        .buttonStyle(ButtonUploadScanDocumenStyle(disabled: fileName.isEmpty))
                     }
-                    .offset(y: -10)
-                    .buttonStyle(ButtonUploadScanDocumenStyle(disabled: fileName.isEmpty))
-                    .frame(maxWidth: .infinity, alignment: .center)
-                    .listRowBackground(Color(UIColor.systemGroupedBackground))
+                    // .listRowBackground(Color(UIColor.systemGroupedBackground))
                 }
                 HUDView(showHUD: $uploadScanDocument.showHUD, textLabel: NSLocalizedString("_wait_", comment: ""), image: "doc.badge.arrow.up")
                     .offset(y: uploadScanDocument.showHUD ? 0 : -200)

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

@@ -733,7 +733,7 @@
 "_file_type_"                       = "File type";
 "_pdf_password_"                    = "PDF Password";
 "_file_creation_"                   = "File creation";
-"_delete_all_scanned_images_"       = "Do you want to delete all scanned images?";
+"_delete_all_scanned_images_"       = "Delete all scanned images";
 "_text_recognition_"                = "Text recognition";
 
 /* The title on the navigation bar of the Scanning screen. */