Marino Faggiana 6 years ago
parent
commit
df125e5786

+ 21 - 1
iOSClient/Scan/Scan.storyboard

@@ -68,6 +68,9 @@
                             <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="fGo-qU-AYi" userLabel="collectionViewDestination">
                                 <rect key="frame" x="0.0" y="278" width="375" height="339"/>
                                 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+                                <constraints>
+                                    <constraint firstAttribute="height" constant="339" id="nTl-vy-iQ8"/>
+                                </constraints>
                                 <collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="0.0" minimumInteritemSpacing="0.0" id="9Sn-Y3-S86">
                                     <size key="itemSize" width="120" height="120"/>
                                     <size key="headerReferenceSize" width="0.0" height="0.0"/>
@@ -144,6 +147,20 @@
                                     <action selector="addWithSender:" destination="BYZ-38-t0r" eventType="touchUpInside" id="bkr-97-4RR"/>
                                 </connections>
                             </button>
+                            <segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="b3i-bF-ITj">
+                                <rect key="frame" x="16" y="629" width="343" height="28"/>
+                                <constraints>
+                                    <constraint firstAttribute="width" constant="343" id="BL3-tS-haJ"/>
+                                    <constraint firstAttribute="height" constant="27" id="Kx0-Zp-wJh"/>
+                                </constraints>
+                                <segments>
+                                    <segment title="First"/>
+                                    <segment title="Second"/>
+                                </segments>
+                                <connections>
+                                    <action selector="indexChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="yeI-C2-uGJ"/>
+                                </connections>
+                            </segmentedControl>
                         </subviews>
                         <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                         <constraints>
@@ -153,11 +170,13 @@
                             <constraint firstItem="0Gy-eG-A0f" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="18" id="BNZ-HM-6yi"/>
                             <constraint firstItem="jwq-kF-6Nq" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="57" id="ELU-RG-o16"/>
                             <constraint firstItem="fGo-qU-AYi" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="Ew2-9q-DKl"/>
-                            <constraint firstAttribute="bottom" secondItem="fGo-qU-AYi" secondAttribute="bottom" constant="50" id="Eza-ZC-K9z"/>
                             <constraint firstItem="YHy-9G-ngy" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="FvJ-EK-Evb"/>
                             <constraint firstItem="0Gy-eG-A0f" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="72" id="O4H-NJ-Mot"/>
                             <constraint firstItem="fGo-qU-AYi" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="aU0-Bn-B6T"/>
                             <constraint firstItem="jwq-kF-6Nq" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="8" id="dyH-ym-lrb"/>
+                            <constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="b3i-bF-ITj" secondAttribute="bottom" constant="11" id="iCt-vj-sDA"/>
+                            <constraint firstItem="b3i-bF-ITj" firstAttribute="top" secondItem="fGo-qU-AYi" secondAttribute="bottom" constant="12" id="kGQ-oN-ccm"/>
+                            <constraint firstItem="b3i-bF-ITj" firstAttribute="centerX" secondItem="6Tk-OE-BBY" secondAttribute="centerX" id="p4i-a8-soi"/>
                             <constraint firstItem="fGo-qU-AYi" firstAttribute="top" secondItem="YHy-9G-ngy" secondAttribute="bottom" constant="8" id="x2i-aj-hzf"/>
                         </constraints>
                         <viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
@@ -181,6 +200,7 @@
                         <outlet property="collectionViewSource" destination="jwq-kF-6Nq" id="6hn-7D-P8K"/>
                         <outlet property="labelTitlePDFzone" destination="YHy-9G-ngy" id="hQk-4n-stD"/>
                         <outlet property="save" destination="LAS-W8-RG6" id="Dan-xp-JAB"/>
+                        <outlet property="segmentControlFilter" destination="b3i-bF-ITj" id="lPr-xp-LVI"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>

+ 40 - 15
iOSClient/Scan/ScanCollectionView.swift

@@ -27,8 +27,6 @@ import UIKit
 
 class DragDropViewController: UIViewController {
     
-    //MARK: Private Properties
-    
     //Data Source for collectionViewSource
     private var itemsSource = [String]()
     
@@ -41,14 +39,14 @@ class DragDropViewController: UIViewController {
     //MARK: Outlets
     @IBOutlet weak var collectionViewSource: UICollectionView!
     @IBOutlet weak var collectionViewDestination: UICollectionView!
-    
     @IBOutlet weak var cancel: UIBarButtonItem!
     @IBOutlet weak var save: UIBarButtonItem!
-
     @IBOutlet weak var add: UIButton!
-
     @IBOutlet weak var labelTitlePDFzone: UILabel!
-
+    @IBOutlet weak var segmentControlFilter: UISegmentedControl!
+    
+    // filter
+    private var filterGrayscale = true;
     
     //MARK: View Lifecycle Methods
     override func viewDidLoad() {
@@ -67,7 +65,9 @@ class DragDropViewController: UIViewController {
         cancel.title = NSLocalizedString("_cancel_", comment: "")
         save.title = NSLocalizedString("_save_", comment: "")
         labelTitlePDFzone.text = NSLocalizedString("_scan_label_PDF_zone_", comment: "")
-        
+        segmentControlFilter.setTitle(NSLocalizedString("_filter_grayscale_", comment: ""), forSegmentAt: 0)
+        segmentControlFilter.setTitle(NSLocalizedString("_filter_original_", comment: ""), forSegmentAt: 1)
+
         add.setImage(CCGraphics.changeThemingColorImage(UIImage(named: "add"), multiplier:2, color: NCBrandColor.sharedInstance.brand), for: .normal)
     }
     
@@ -79,6 +79,8 @@ class DragDropViewController: UIViewController {
         labelTitlePDFzone.textColor = NCBrandColor.sharedInstance.brandText
         labelTitlePDFzone.backgroundColor = NCBrandColor.sharedInstance.brand
         
+        segmentControlFilter.tintColor = NCBrandColor.sharedInstance.brand
+        
         loadImage(atPath: CCUtility.getDirectoryScan(), items: &itemsSource)
         
         self.collectionViewSource.reloadData()
@@ -93,7 +95,14 @@ class DragDropViewController: UIViewController {
     @IBAction func saveAction(sender: UIBarButtonItem) {
         
         if imagesDestination.count > 0 {
-            let formViewController = CreateFormUploadScanDocument.init(serverUrl: appDelegate.activeMain.serverUrl, arrayImages: self.imagesDestination)
+            
+            var images = [UIImage]()
+
+            for image in imagesDestination {
+                images.append(filter(image: image)!)
+            }
+            
+            let formViewController = CreateFormUploadScanDocument.init(serverUrl: appDelegate.activeMain.serverUrl, arrayImages: images)
             self.navigationController?.pushViewController(formViewController, animated: true)
         }
     }
@@ -103,6 +112,23 @@ class DragDropViewController: UIViewController {
         NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: self, openScan: false)
     }
     
+    @IBAction func indexChanged(_ sender: AnyObject) {
+        
+        switch segmentControlFilter.selectedSegmentIndex
+        {
+        case 0:
+            // Grayscale
+            filterGrayscale = true
+        case 1:
+            // Original
+            filterGrayscale = false
+        default:
+            break
+        }
+        
+        self.collectionViewDestination.reloadData()
+    }
+    
     //MARK: Private Methods
     
     private func loadImage(atPath: String, items: inout [String]) {
@@ -123,6 +149,10 @@ class DragDropViewController: UIViewController {
     
     func filter(image: UIImage) -> UIImage? {
         
+        if filterGrayscale == false {
+            return image
+        }
+        
         let ciImage = CIImage(image: image)!
         let imageFilter = ciImage.applyingFilter("CIColorControls", parameters: ["inputSaturation": 0, "inputContrast": 1])
         
@@ -200,17 +230,12 @@ class DragDropViewController: UIViewController {
                     guard let image =  UIImage(data: data) else {
                         return
                     }
-                    guard let imageFilter = self.filter(image: image) else {
-                        return
-                    }
-                    
-                    self.imagesDestination.insert(imageFilter, at: indexPath.row)
+                   
+                    self.imagesDestination.insert(image, at: indexPath.row)
                     
                 } else {
                     
                     // NOT PERMITTED
-                    //self.itemsSource.insert(item.dragItem.localObject as! String, at: indexPath.row)
-                    
                     return
                 }
                 

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

@@ -565,6 +565,8 @@
 "_scanned_images_"                  = "Scanned images";
 "_scan_document_pdf_page_"          = "Page";
 "_scan_label_PDF_zone_"             = "Drag below the images for make your PDF document";
+"_filter_original_"                 = "Original";
+"_filter_grayscale_"                = "Grayscale";
 
 /* The title on the navigation bar of the Scanning screen. */
 "wescan.scanning.title"             = "Scanning";