marinofaggiana 5 years ago
parent
commit
1f87ba71f3

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

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

+ 53 - 0
iOSClient/Images.xcassets/transferDown.imageset/transferDown.pdf

@@ -0,0 +1,53 @@
+%PDF-1.4
+%Óëéá
+1 0 obj
+<</Creator (Chromium)
+/Producer (Skia/PDF m69)
+/CreationDate (D:20190715105909+00'00')
+/ModDate (D:20190715105909+00'00')>>
+endobj
+2 0 obj
+<</Filter /FlateDecode
+/Length 132>> stream
+xœUŽK
+‚1„÷sŠ¬k“ØÖžÀµ+ >ýõþ`šZÑfÈ|h­þ(Ú¬ÃϪé´à�NXKò<㸢»å©©œóÖoÿ7;Üì#]_àLJK·D
»�ª©·2
+ÕÑÐ2‰óh°:œÆ_Ú`ßK½T»[,$2ã†.8ؼQ.Â
+endstream
+endobj
+3 0 obj
+<</Type /Catalog
+/Pages 4 0 R>>
+endobj
+4 0 obj
+<</Type /Pages
+/Count 1
+/Kids [5 0 R]>>
+endobj
+5 0 obj
+<</Type /Page
+/Resources <</ProcSets [/PDF /Text /ImageB /ImageC /ImageI]
+/ExtGState <</G0 6 0 R>>>>
+/MediaBox [0 0 330 330]
+/Contents 2 0 R
+/Parent 4 0 R>>
+endobj
+6 0 obj
+<</ca 1
+/BM /Normal>>
+endobj
+xref
+0 7
+0000000000 65535 f 
+0000000015 00000 n 
+0000000154 00000 n 
+0000000356 00000 n 
+0000000403 00000 n 
+0000000458 00000 n 
+0000000630 00000 n 
+trailer
+<</Size 7
+/Root 3 0 R
+/Info 1 0 R>>
+startxref
+667
+%%EOF

+ 21 - 6
iOSClient/Scan/Scan.storyboard

@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="bdK-eL-mz4">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="bdK-eL-mz4">
     <device id="retina4_7" orientation="portrait">
         <adaptation id="fullscreen"/>
     </device>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
         <capability name="Safe area layout guides" minToolsVersion="9.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
@@ -158,7 +158,7 @@
                                 <nil key="highlightedColor"/>
                             </label>
                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0Gy-eG-A0f">
-                                <rect key="frame" x="18" y="136" width="30" height="30"/>
+                                <rect key="frame" x="20" y="102" width="30" height="30"/>
                                 <constraints>
                                     <constraint firstAttribute="height" constant="30" id="A6e-zC-q5t"/>
                                     <constraint firstAttribute="width" constant="30" id="U2p-ow-Iad"/>
@@ -183,17 +183,30 @@
                                     <action selector="indexChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="yeI-C2-uGJ"/>
                                 </connections>
                             </segmentedControl>
+                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Fqr-e6-s3n" userLabel="transferDown">
+                                <rect key="frame" x="18" y="172" width="30" height="30"/>
+                                <constraints>
+                                    <constraint firstAttribute="height" constant="30" id="YPl-DJ-aNS"/>
+                                    <constraint firstAttribute="width" constant="30" id="yGb-Y2-8Oj"/>
+                                </constraints>
+                                <state key="normal" title="+" image="transferDown"/>
+                                <connections>
+                                    <action selector="transferDownWithSender:" destination="BYZ-38-t0r" eventType="touchUpInside" id="IXg-q4-MB7"/>
+                                </connections>
+                            </button>
                         </subviews>
                         <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                         <constraints>
                             <constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="YHy-9G-ngy" secondAttribute="trailing" id="3ff-G8-wiq"/>
+                            <constraint firstItem="Fqr-e6-s3n" firstAttribute="top" secondItem="jwq-kF-6Nq" secondAttribute="bottom" constant="-60" id="5FJ-rD-ncI"/>
                             <constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="jwq-kF-6Nq" secondAttribute="trailing" id="6EM-YK-lEy"/>
+                            <constraint firstItem="jwq-kF-6Nq" firstAttribute="top" secondItem="0Gy-eG-A0f" secondAttribute="bottom" constant="-60" id="8D3-HY-PIM"/>
                             <constraint firstItem="YHy-9G-ngy" firstAttribute="top" secondItem="jwq-kF-6Nq" secondAttribute="bottom" constant="8" id="90f-NC-udY"/>
-                            <constraint firstItem="0Gy-eG-A0f" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="18" id="BNZ-HM-6yi"/>
+                            <constraint firstItem="0Gy-eG-A0f" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="20" 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 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="Fqr-e6-s3n" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="18" id="UJ4-nd-oV8"/>
                             <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"/>
@@ -223,6 +236,7 @@
                         <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"/>
+                        <outlet property="transferDown" destination="Fqr-e6-s3n" id="8e4-CK-FQQ"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
@@ -252,8 +266,9 @@
         </scene>
     </scenes>
     <resources>
-        <image name="add" width="37.5" height="37.5"/>
+        <image name="add" width="25" height="25"/>
         <image name="deleteScan" width="25" height="25"/>
         <image name="rotate" width="25" height="25"/>
+        <image name="transferDown" width="330" height="330"/>
     </resources>
 </document>

+ 73 - 45
iOSClient/Scan/ScanCollectionView.swift

@@ -32,7 +32,8 @@ class DragDropViewController: UIViewController {
     
     //Data Source for collectionViewDestination
     private var imagesDestination = [UIImage]()
-
+    private var itemsDestination = [String]()
+    
     //AppDelegate
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
 
@@ -42,6 +43,7 @@ class DragDropViewController: UIViewController {
     @IBOutlet weak var cancel: UIBarButtonItem!
     @IBOutlet weak var save: UIBarButtonItem!
     @IBOutlet weak var add: UIButton!
+    @IBOutlet weak var transferDown: UIButton!
     @IBOutlet weak var labelTitlePDFzone: UILabel!
     @IBOutlet weak var segmentControlFilter: UISegmentedControl!
 
@@ -59,14 +61,14 @@ class DragDropViewController: UIViewController {
     override func viewDidLoad() {
         super.viewDidLoad()
         
-        self.collectionViewSource.dragInteractionEnabled = true
-        self.collectionViewSource.dragDelegate = self
-        self.collectionViewSource.dropDelegate = self
+        collectionViewSource.dragInteractionEnabled = true
+        collectionViewSource.dragDelegate = self
+        collectionViewSource.dropDelegate = self
         
-        self.collectionViewDestination.dragInteractionEnabled = true
-        self.collectionViewDestination.dropDelegate = self
-        self.collectionViewDestination.dragDelegate = self
-        self.collectionViewDestination.reorderingCadence = .fast //default value - .immediate
+        collectionViewDestination.dragInteractionEnabled = true
+        collectionViewDestination.dropDelegate = self
+        collectionViewDestination.dragDelegate = self
+        collectionViewDestination.reorderingCadence = .fast //default value - .immediate
         
         self.navigationItem.title = NSLocalizedString("_scanned_images_", comment: "")
         cancel.title = NSLocalizedString("_cancel_", comment: "")
@@ -78,6 +80,7 @@ class DragDropViewController: UIViewController {
         segmentControlFilter.setTitle(NSLocalizedString("_filter_bn_", comment: ""), forSegmentAt: 2)
 
         add.setImage(CCGraphics.changeThemingColorImage(UIImage(named: "add"), multiplier:2, color: NCBrandColor.sharedInstance.brand), for: .normal)
+        transferDown.setImage(CCGraphics.changeThemingColorImage(UIImage(named: "transferDown"), multiplier:2, color: NCBrandColor.sharedInstance.brand), for: .normal)
         
         let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPressGesture(recognizer:)))
         add.addGestureRecognizer(longPressRecognizer)
@@ -129,6 +132,25 @@ class DragDropViewController: UIViewController {
         NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: self, openScan: false)
     }
     
+    @IBAction func transferDown(sender: UIButton) {
+     
+        for fileName in itemsSource {
+            
+            if !itemsDestination.contains(fileName) {
+                
+                let fileNamePathAt = CCUtility.getDirectoryScan() + "/" + fileName
+                
+                guard let data = try? Data(contentsOf: URL(fileURLWithPath: fileNamePathAt)) else { return }
+                guard let image = UIImage(data: data) else { return }
+                
+                imagesDestination.append(image)
+                itemsDestination.append(fileName)
+            }
+        }
+        
+        collectionViewDestination.reloadData()
+    }
+    
     @IBAction func indexChanged(_ sender: AnyObject) {
         
         switch segmentControlFilter.selectedSegmentIndex
@@ -143,7 +165,7 @@ class DragDropViewController: UIViewController {
             break
         }
         
-        self.collectionViewDestination.reloadData()
+        collectionViewDestination.reloadData()
     }
     
     //MARK: Private Methods
@@ -163,7 +185,7 @@ class DragDropViewController: UIViewController {
             print(error.localizedDescription)
         }
         
-        self.collectionViewSource.reloadData()
+        collectionViewSource.reloadData()
     }
     
     func filter(image: UIImage) -> UIImage? {
@@ -212,15 +234,19 @@ class DragDropViewController: UIViewController {
             
             collectionView.performBatchUpdates({
                 
-                if collectionView === self.collectionViewDestination {
+                if collectionView === collectionViewDestination {
                     
-                    self.imagesDestination.remove(at: sourceIndexPath.row)
-                    self.imagesDestination.insert(item.dragItem.localObject as! UIImage, at: dIndexPath.row)
+                    imagesDestination.remove(at: sourceIndexPath.row)
+                    imagesDestination.insert(item.dragItem.localObject as! UIImage, at: dIndexPath.row)
                     
+                    let fileName = itemsDestination[sourceIndexPath.row]
+                    itemsDestination.remove(at: sourceIndexPath.row)
+                    itemsDestination.insert(fileName, at: dIndexPath.row)
+                
                 } else {
                     
-                    self.itemsSource.remove(at: sourceIndexPath.row)
-                    self.itemsSource.insert(item.dragItem.localObject as! String, at: dIndexPath.row)
+                    itemsSource.remove(at: sourceIndexPath.row)
+                    itemsSource.insert(item.dragItem.localObject as! String, at: dIndexPath.row)
                 }
                 
                 collectionView.deleteItems(at: [sourceIndexPath])
@@ -248,10 +274,10 @@ class DragDropViewController: UIViewController {
                 
                 let indexPath = IndexPath(row: destinationIndexPath.row + index, section: destinationIndexPath.section)
                 
-                if collectionView === self.collectionViewDestination {
+                if collectionView === collectionViewDestination {
                     
-                    let fileName = item.dragItem.localObject as! NSString
-                    let fileNamePathAt = CCUtility.getDirectoryScan() + "/" + (fileName as String)
+                    let fileName = item.dragItem.localObject as! String
+                    let fileNamePathAt = CCUtility.getDirectoryScan() + "/" + fileName
                     
                     guard let data = try? Data(contentsOf: URL(fileURLWithPath: fileNamePathAt)) else {
                         return
@@ -260,7 +286,8 @@ class DragDropViewController: UIViewController {
                         return
                     }
                    
-                    self.imagesDestination.insert(image, at: indexPath.row)
+                    imagesDestination.insert(image, at: indexPath.row)
+                    itemsDestination.insert(fileName, at: indexPath.row)
                     
                 } else {
                     
@@ -333,16 +360,16 @@ extension DragDropViewController : UICollectionViewDataSource {
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
         
-        return collectionView == self.collectionViewSource ? self.itemsSource.count : self.imagesDestination.count
+        return collectionView == collectionViewSource ? itemsSource.count : imagesDestination.count
     }
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         
-        if collectionView == self.collectionViewSource {
+        if collectionView == collectionViewSource {
             
             let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell1", for: indexPath) as! ScanCell
             
-            let fileNamePath = CCUtility.getDirectoryScan() + "/" + self.itemsSource[indexPath.row]
+            let fileNamePath = CCUtility.getDirectoryScan() + "/" + itemsSource[indexPath.row]
             
             guard let data = try? Data(contentsOf: URL(fileURLWithPath: fileNamePath)) else {
                 return cell
@@ -369,7 +396,7 @@ extension DragDropViewController : UICollectionViewDataSource {
             
             let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell2", for: indexPath) as! ScanCell
             
-            var image = self.imagesDestination[indexPath.row]
+            var image = imagesDestination[indexPath.row]
             
             let imageWidthInPixels = image.size.width * image.scale
             let imageHeightInPixels = image.size.height * image.scale
@@ -390,24 +417,25 @@ extension DragDropViewController : UICollectionViewDataSource {
     
     @objc func deleteSource(_ sender: UIButton) {
         
-        let buttonPosition:CGPoint =  sender.convert(.zero, to: self.collectionViewSource)
-        let indexPath:IndexPath = self.collectionViewSource.indexPathForItem(at: buttonPosition)!
+        let buttonPosition:CGPoint =  sender.convert(.zero, to: collectionViewSource)
+        let indexPath:IndexPath = collectionViewSource.indexPathForItem(at: buttonPosition)!
         
-        let fileNameAtPath = CCUtility.getDirectoryScan() + "/" + self.itemsSource[indexPath.row]
+        let fileNameAtPath = CCUtility.getDirectoryScan() + "/" + itemsSource[indexPath.row]
         CCUtility.removeFile(atPath: fileNameAtPath)
-        self.itemsSource.remove(at: indexPath.row)
+        itemsSource.remove(at: indexPath.row)
         
-        self.collectionViewSource.reloadData()
+        collectionViewSource.reloadData()
     }
     
     @objc func deleteDestination(_ sender:UIButton) {
         
-        let buttonPosition:CGPoint =  sender.convert(.zero, to: self.collectionViewDestination)
-        let indexPath:IndexPath = self.collectionViewDestination.indexPathForItem(at: buttonPosition)!
+        let buttonPosition:CGPoint =  sender.convert(.zero, to: collectionViewDestination)
+        let indexPath:IndexPath = collectionViewDestination.indexPathForItem(at: buttonPosition)!
         
-        self.imagesDestination.remove(at: indexPath.row)
+        imagesDestination.remove(at: indexPath.row)
+        itemsDestination.remove(at: indexPath.row)
         
-        self.collectionViewDestination.reloadData()
+        collectionViewDestination.reloadData()
         
         // Save button
         if imagesDestination.count == 0 {
@@ -419,13 +447,13 @@ extension DragDropViewController : UICollectionViewDataSource {
     
     @objc func rotateDestination(_ sender:UIButton) {
         
-        let buttonPosition:CGPoint =  sender.convert(.zero, to: self.collectionViewDestination)
-        let indexPath:IndexPath = self.collectionViewDestination.indexPathForItem(at: buttonPosition)!
+        let buttonPosition:CGPoint =  sender.convert(.zero, to: collectionViewDestination)
+        let indexPath:IndexPath = collectionViewDestination.indexPathForItem(at: buttonPosition)!
         
-        let image = self.imagesDestination[indexPath.row]
+        let image = imagesDestination[indexPath.row]
         imagesDestination[indexPath.row] = image.rotate(radians: .pi/2)!
         
-        self.collectionViewDestination.reloadData()
+        collectionViewDestination.reloadData()
     }
 }
 
@@ -461,8 +489,8 @@ extension DragDropViewController : UICollectionViewDragDelegate
 {
     func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
         
-        if collectionView == self.collectionViewSource {
-            let item = self.itemsSource[indexPath.row]
+        if collectionView == collectionViewSource {
+            let item = itemsSource[indexPath.row]
             let itemProvider = NSItemProvider(object: item as NSString)
             let dragItem = UIDragItem(itemProvider: itemProvider)
 
@@ -471,7 +499,7 @@ extension DragDropViewController : UICollectionViewDragDelegate
             return [dragItem]
 
         } else {
-            let item = self.imagesDestination[indexPath.row]
+            let item = imagesDestination[indexPath.row]
             let itemProvider = NSItemProvider(object: item as UIImage)
             let dragItem = UIDragItem(itemProvider: itemProvider)
 
@@ -483,8 +511,8 @@ extension DragDropViewController : UICollectionViewDragDelegate
     
     func collectionView(_ collectionView: UICollectionView, itemsForAddingTo session: UIDragSession, at indexPath: IndexPath, point: CGPoint) -> [UIDragItem] {
         
-        if collectionView == self.collectionViewSource {
-            let item = self.itemsSource[indexPath.row]
+        if collectionView == collectionViewSource {
+            let item = itemsSource[indexPath.row]
             let itemProvider = NSItemProvider(object: item as NSString)
             let dragItem = UIDragItem(itemProvider: itemProvider)
             
@@ -493,7 +521,7 @@ extension DragDropViewController : UICollectionViewDragDelegate
             return [dragItem]
             
         } else {
-            let item = self.imagesDestination[indexPath.row]
+            let item = imagesDestination[indexPath.row]
             let itemProvider = NSItemProvider(object: item as UIImage)
             let dragItem = UIDragItem(itemProvider: itemProvider)
             
@@ -506,7 +534,7 @@ extension DragDropViewController : UICollectionViewDragDelegate
     func collectionView(_ collectionView: UICollectionView, dragPreviewParametersForItemAt indexPath: IndexPath) -> UIDragPreviewParameters? {
         
         let previewParameters = UIDragPreviewParameters()
-        if collectionView == self.collectionViewSource {
+        if collectionView == collectionViewSource {
             previewParameters.visiblePath = UIBezierPath(rect: CGRect(x: 20, y: 20, width: 100, height: 100))
         } else {
             previewParameters.visiblePath = UIBezierPath(rect: CGRect(x: 20, y: 20, width: 80, height: 80))
@@ -529,7 +557,7 @@ extension DragDropViewController : UICollectionViewDropDelegate {
     
     func collectionView(_ collectionView: UICollectionView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UICollectionViewDropProposal {
         
-        if collectionView == self.collectionViewSource {
+        if collectionView == collectionViewSource {
             
             if collectionView.hasActiveDrag {
                 return UICollectionViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
@@ -589,7 +617,7 @@ extension DragDropViewController : UICollectionViewDropDelegate {
     
     func collectionView(_ collectionView: UICollectionView, dropSessionDidEnd session: UIDropSession) {
         
-        self.collectionViewDestination.reloadData()
+        collectionViewDestination.reloadData()
         
         // Save button
         if imagesDestination.count == 0 {