Browse Source

remove WeScan -> replaced with VisionKIT

marinofaggiana 4 years ago
parent
commit
f3581ab452

+ 0 - 3
Nextcloud.xcodeproj/project.pbxproj

@@ -79,7 +79,6 @@
 		F72A47EC2487B06B005AD489 /* NCOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72A47EB2487B06B005AD489 /* NCOperationQueue.swift */; };
 		F72D1007210B6882009C96B7 /* NCPushNotificationEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F72D1005210B6882009C96B7 /* NCPushNotificationEncryption.m */; };
 		F72D404923D2082500A97FD0 /* NCViewerNextcloudText.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72D404823D2082500A97FD0 /* NCViewerNextcloudText.swift */; };
-		F72E0B9D21AD60BC00898D7B /* WeScan.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F72E0B9C21AD60BC00898D7B /* WeScan.framework */; };
 		F733B65221997CC2001C1FFA /* TLPhotoPicker.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F733B65121997CC1001C1FFA /* TLPhotoPicker.framework */; };
 		F7362A1F220C853A005101B5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7362A1E220C853A005101B5 /* LaunchScreen.storyboard */; };
 		F7381EE1218218C9000B1560 /* NCOffline.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7381EDA218218C9000B1560 /* NCOffline.swift */; };
@@ -725,7 +724,6 @@
 				F745B251222D871800346520 /* QRCodeReader.framework in Frameworks */,
 				F710C5F02471A6D1009AD8B7 /* Sentry.framework in Frameworks */,
 				F765608723BF806D00765969 /* QuickLayout.framework in Frameworks */,
-				F72E0B9D21AD60BC00898D7B /* WeScan.framework in Frameworks */,
 				F7063DED2199E55F003F38DA /* SVGKit.framework in Frameworks */,
 				F7063DEF2199E568003F38DA /* CocoaLumberjack.framework in Frameworks */,
 				F765608B23BF80A400765969 /* SwiftEntryKit.framework in Frameworks */,
@@ -1879,7 +1877,6 @@
 				"$(SRCROOT)/Carthage/Build/iOS/SVGKit.framework",
 				"$(SRCROOT)/Carthage/Build/iOS/CocoaLumberjack.framework",
 				"$(SRCROOT)/Carthage/Build/iOS/CocoaLumberjackSwift.framework",
-				"$(SRCROOT)/Carthage/Build/iOS/WeScan.framework",
 				"$(SRCROOT)/Carthage/Build/iOS/SwiftRichString.framework",
 				"$(SRCROOT)/Carthage/Build/iOS/QRCodeReader.framework",
 				"$(SRCROOT)/Carthage/Build/iOS/ZIPFoundation.framework",

+ 77 - 78
iOSClient/Main/Create cloud/NCCreateFormUploadScanDocument.swift

@@ -21,12 +21,12 @@
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 
-
 import Foundation
-import WeScan
 import NCCommunication
 import Vision
+import VisionKit
 
+@available(iOS 13.0, *)
 class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NCCreateFormUploadConflictDelegate {
     
     enum typeQuality {
@@ -85,10 +85,8 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
 
         changeTheming()
         
-        if #available(iOS 13.0, *) {
-            let value = CCUtility.getTextRecognitionStatus()
-            SetTextRecognition(newValue: value)
-        }
+        let value = CCUtility.getTextRecognitionStatus()
+        SetTextRecognition(newValue: value)
     }
     
     @objc func changeTheming() {
@@ -166,21 +164,19 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
         
         // Section: Text recognition
         
-        if #available(iOS 13.0, *) {
-            section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_text_recognition_", comment: ""))
-            form.addFormSection(section)
-                
-            row = XLFormRowDescriptor(tag: "textRecognition", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_text_recognition_", comment: ""))
-            row.value = 0
-            row.cellConfig["backgroundColor"] = NCBrandColor.sharedInstance.backgroundForm
-
-            row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage(named: "textRecognition")!, width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement) as UIImage
+        section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_text_recognition_", comment: ""))
+        form.addFormSection(section)
             
-            row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
-            row.cellConfig["textLabel.textColor"] = NCBrandColor.sharedInstance.textView
+        row = XLFormRowDescriptor(tag: "textRecognition", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_text_recognition_", comment: ""))
+        row.value = 0
+        row.cellConfig["backgroundColor"] = NCBrandColor.sharedInstance.backgroundForm
 
-            section.addFormRow(row)
-        }
+        row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage(named: "textRecognition")!, width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement) as UIImage
+        
+        row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
+        row.cellConfig["textLabel.textColor"] = NCBrandColor.sharedInstance.textView
+
+        section.addFormRow(row)
         
         // Section: File
         
@@ -467,29 +463,26 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
             var textFile = ""
             for image in self.arrayImages {
                 
-                if #available(iOS 13.0, *) {
-                    
-                    let requestHandler = VNImageRequestHandler(cgImage: image.cgImage!, options: [:])
-                    
-                    let request = VNRecognizeTextRequest { (request, error) in
-                        guard let observations = request.results as? [VNRecognizedTextObservation] else {
-                            NCUtility.shared.stopActivityIndicator()
-                            return
-                        }
-                        for observation in observations {
-                            guard let textLine = observation.topCandidates(1).first else {
-                                continue
-                            }
-                               
-                            textFile += textLine.string
-                            textFile += "\n"
+                let requestHandler = VNImageRequestHandler(cgImage: image.cgImage!, options: [:])
+                
+                let request = VNRecognizeTextRequest { (request, error) in
+                    guard let observations = request.results as? [VNRecognizedTextObservation] else {
+                        NCUtility.shared.stopActivityIndicator()
+                        return
+                    }
+                    for observation in observations {
+                        guard let textLine = observation.topCandidates(1).first else {
+                            continue
                         }
+                           
+                        textFile += textLine.string
+                        textFile += "\n"
                     }
-                    
-                    request.recognitionLevel = .accurate
-                    request.usesLanguageCorrection = true
-                    try? requestHandler.perform([request])
                 }
+                
+                request.recognitionLevel = .accurate
+                request.usesLanguageCorrection = true
+                try? requestHandler.perform([request])
             }
             
             do {
@@ -522,48 +515,40 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
                 
                 let bounds = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
                 
-                if #available(iOS 13.0, *) {
+                if self.form.formRow(withTag: "textRecognition")!.value as! Int == 1 {
                     
-                    if self.form.formRow(withTag: "textRecognition")!.value as! Int == 1 {
-                        
-                        UIGraphicsBeginPDFPageWithInfo(bounds, nil)
-                        image.draw(in: bounds)
+                    UIGraphicsBeginPDFPageWithInfo(bounds, nil)
+                    image.draw(in: bounds)
 
-                        let requestHandler = VNImageRequestHandler(cgImage: image.cgImage!, options: [:])
-                        
-                        let request = VNRecognizeTextRequest { (request, error) in
-                            guard let observations = request.results as? [VNRecognizedTextObservation] else {
-                                NCUtility.shared.stopActivityIndicator()
-                                return
+                    let requestHandler = VNImageRequestHandler(cgImage: image.cgImage!, options: [:])
+                    
+                    let request = VNRecognizeTextRequest { (request, error) in
+                        guard let observations = request.results as? [VNRecognizedTextObservation] else {
+                            NCUtility.shared.stopActivityIndicator()
+                            return
+                        }
+                        for observation in observations {
+                            guard let textLine = observation.topCandidates(1).first else {
+                                continue
                             }
-                            for observation in observations {
-                                guard let textLine = observation.topCandidates(1).first else {
-                                    continue
-                                }
-                                
-                                var t: CGAffineTransform = CGAffineTransform.identity
-                                t = t.scaledBy(x: image.size.width, y: -image.size.height)
-                                t = t.translatedBy(x: 0, y: -1)
-                                let rect = observation.boundingBox.applying(t)
-                                let text = textLine.string
-
-                                let font = UIFont.systemFont(ofSize: rect.size.height, weight: .regular)
-                                let attributes = self.bestFittingFont(for: text, in: rect, fontDescriptor: font.fontDescriptor, fontColor: fontColor)
                             
-                                text.draw(with: rect, options: .usesLineFragmentOrigin, attributes: attributes, context: nil)
-                            }
-                        }
-                        
-                        request.recognitionLevel = .accurate
-                        request.usesLanguageCorrection = true
-                        try? requestHandler.perform([request])
-                        
-                    } else {
+                            var t: CGAffineTransform = CGAffineTransform.identity
+                            t = t.scaledBy(x: image.size.width, y: -image.size.height)
+                            t = t.translatedBy(x: 0, y: -1)
+                            let rect = observation.boundingBox.applying(t)
+                            let text = textLine.string
+
+                            let font = UIFont.systemFont(ofSize: rect.size.height, weight: .regular)
+                            let attributes = self.bestFittingFont(for: text, in: rect, fontDescriptor: font.fontDescriptor, fontColor: fontColor)
                         
-                        UIGraphicsBeginPDFPageWithInfo(bounds, nil)
-                        image.draw(in: bounds)
+                            text.draw(with: rect, options: .usesLineFragmentOrigin, attributes: attributes, context: nil)
+                        }
                     }
                     
+                    request.recognitionLevel = .accurate
+                    request.usesLanguageCorrection = true
+                    try? requestHandler.perform([request])
+                    
                 } else {
                     
                     UIGraphicsBeginPDFPageWithInfo(bounds, nil)
@@ -750,7 +735,8 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
 
 }
 
-class NCCreateScanDocument : NSObject, ImageScannerControllerDelegate {
+@available(iOS 13.0, *)
+class NCCreateScanDocument : NSObject, VNDocumentCameraViewControllerDelegate {
     
     @objc static let sharedInstance: NCCreateScanDocument = {
         let instance = NCCreateScanDocument()
@@ -764,12 +750,24 @@ class NCCreateScanDocument : NSObject, ImageScannerControllerDelegate {
         
         self.viewController = viewController
         
-        let scannerVC = ImageScannerController()
-        scannerVC.imageScannerDelegate = self
+        guard VNDocumentCameraViewController.isSupported else { return }
+            
+        let controller = VNDocumentCameraViewController()
+        controller.delegate = self
+
+        self.viewController?.present(controller, animated: true)
+    }
+    
+    func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
+        // save scan
+        //dismiss(animated: true, completion: nil)
+    }
         
-        self.viewController?.present(scannerVC, animated: true, completion: nil)
+    func documentCameraViewControllerDidCancel(_ controller: VNDocumentCameraViewController) {
+        controller.dismiss(animated: true, completion: nil)
     }
     
+    /*
     func imageScannerController(_ scanner: ImageScannerController, didFinishScanningWithResults results: ImageScannerResults) {
         
         let fileName = CCUtility.createFileName("scan.png", fileDate: Date(), fileType: PHAssetMediaType.image, keyFileName: k_keyFileNameMask, keyFileNameType: k_keyFileNameType, keyFileNameOriginal: k_keyFileNameOriginal)!
@@ -808,5 +806,6 @@ class NCCreateScanDocument : NSObject, ImageScannerControllerDelegate {
     func imageScannerController(_ scanner: ImageScannerController, didFailWithError error: Error) {
         NCContentPresenter.shared.messageNotification("_error_", description: error.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
     }
+    */
 }
 

+ 11 - 9
iOSClient/Main/Menu/AppDelegate+Menu.swift

@@ -106,16 +106,18 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
             )
         } 
         
-        actions.append(
-            NCMenuAction(
-                title: NSLocalizedString("_scans_document_", comment: ""),
-                icon: CCGraphics.changeThemingColorImage(UIImage(named: "scan"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
-                action: { menuAction in
-                    NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: appDelegate.window.rootViewController!)
-                }
+        if #available(iOS 13.0, *) {
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_scans_document_", comment: ""),
+                    icon: CCGraphics.changeThemingColorImage(UIImage(named: "scan"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                    action: { menuAction in
+                        NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: appDelegate.window.rootViewController!)
+                    }
+                )
             )
-        )
-
+        }
+        
         actions.append(
             NCMenuAction(
                 title: NSLocalizedString("_create_voice_memo_", comment: ""),

+ 8 - 6
iOSClient/More/NCMore.swift

@@ -126,12 +126,14 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
         functionMenu.append(item)
 
         // ITEM : Scan
-        item = NCCommunicationExternalSite()
-        item.name = "_scanned_images_"
-        item.icon = "scan"
-        item.url = "openStoryboardScan"
-        functionMenu.append(item)
-
+        if #available(iOS 13.0, *) {
+            item = NCCommunicationExternalSite()
+            item.name = "_scanned_images_"
+            item.icon = "scan"
+            item.url = "openStoryboardScan"
+            functionMenu.append(item)
+        }
+        
         // ITEM : Trash
         let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
         if serverVersionMajor >= Int(k_trash_version_available) {

+ 5 - 5
iOSClient/ScanDocument/ScanCollectionView.swift

@@ -23,6 +23,7 @@
 
 import UIKit
 
+@available(iOS 13.0, *)
 class DragDropViewController: UIViewController {
     
     //Data Source for collectionViewSource
@@ -100,11 +101,7 @@ class DragDropViewController: UIViewController {
         collectionViewDestination.reloadData()
 
         labelTitlePDFzone.textColor = NCBrandColor.sharedInstance.textView
-        if #available(iOS 13.0, *) {
-            labelTitlePDFzone.backgroundColor = .systemBackground
-        } else {
-            labelTitlePDFzone.backgroundColor = .systemGray
-        }
+        labelTitlePDFzone.backgroundColor = .systemBackground
     }
     
     //MARK: Button Action
@@ -377,6 +374,7 @@ class DragDropViewController: UIViewController {
 
 // MARK: - UICollectionViewDataSource Methods
 
+@available(iOS 13.0, *)
 extension DragDropViewController : UICollectionViewDataSource {
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
@@ -504,6 +502,7 @@ extension UIImage {
 
 // MARK: - UICollectionViewDragDelegate Methods
 
+@available(iOS 13.0, *)
 extension DragDropViewController : UICollectionViewDragDelegate
 {
     func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
@@ -565,6 +564,7 @@ extension DragDropViewController : UICollectionViewDragDelegate
 
 // MARK: - UICollectionViewDropDelegate Methods
 
+@available(iOS 13.0, *)
 extension DragDropViewController : UICollectionViewDropDelegate {
     
     func collectionView(_ collectionView: UICollectionView, canHandle session: UIDropSession) -> Bool {

+ 1 - 29
iOSClient/Settings/Acknowledgements.rtf

@@ -1,4 +1,4 @@
-{\rtf1\ansi\ansicpg1252\cocoartf2513
+{\rtf1\ansi\ansicpg1252\cocoartf2576
 \cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fswiss\fcharset0 Helvetica-Bold;}
 {\colortbl;\red255\green255\blue255;}
 {\*\expandedcolortbl;;}
@@ -41,15 +41,6 @@ Copyright (c) Matej Bukovinski\
 ____________________________________________\
 \
 
-\f1\b MGSwipeTableCell
-\f0\b0 \
-\
-The MIT License (MIT)\
-\
-Copyright (c) 2014 Imanol Fernandez @MortimerGoro\
-____________________________________________\
-\
-
 \f1\b NYMnemonic - BIP 39 style mnemonic codes\
 
 \f0\b0 ____________________________________________\
@@ -93,15 +84,6 @@ Copyright (c) Xmartlabs ( http://xmartlabs.com )\
 ____________________________________________\
 \
 
-\f1\b DownloadButton
-\f0\b0 \
-\
-Apache License, Version 2.0\
-\
-Copyright (c) Pavel Katunin\
-____________________________________________\
-\
-
 \f1\b KTVHTTPCache
 \f0\b0 \
 \
@@ -110,15 +92,6 @@ The MIT License (MIT)\
 Copyright (c) libobjc\
 ____________________________________________\
 \
-Includes a modified version of 
-\f1\b WeScan 
-\f0\b0 \
-\
-The MIT License (MIT)\
-\
-Copyright (c) WeTransfer\
-____________________________________________\
-\
 
 \f1\b SVGKit
 \f0\b0 \
@@ -212,7 +185,6 @@ ____________________________________________\
 \f0\b0 \
 \
 The MIT License (MIT)\
-\
 ____________________________________________\
 \