Marino Faggiana пре 8 година
родитељ
комит
d4abafc67b

+ 18 - 3
Picker/Base.lproj/MainInterface.storyboard

@@ -23,14 +23,14 @@
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="vA7-yc-aM1">
-                                <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
+                                <rect key="frame" x="0.0" y="0.0" width="375" height="623"/>
                                 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                 <prototypes>
                                     <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" rowHeight="50" id="0H6-U8-fd4" userLabel="Cell" customClass="recordMetadataCell" customModule="Picker" customModuleProvider="target">
                                         <rect key="frame" x="0.0" y="28" width="375" height="50"/>
                                         <autoresizingMask key="autoresizingMask"/>
                                         <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="0H6-U8-fd4" id="44X-Sr-gc0">
-                                            <rect key="frame" x="0.0" y="0.0" width="375" height="49.5"/>
+                                            <rect key="frame" x="0.0" y="0.0" width="375" height="49"/>
                                             <autoresizingMask key="autoresizingMask"/>
                                             <subviews>
                                                 <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Wk9-rb-4yv">
@@ -64,17 +64,32 @@
                                     <outlet property="delegate" destination="J6p-g8-CHO" id="wBq-lQ-Kon"/>
                                 </connections>
                             </tableView>
+                            <toolbar clearsContextBeforeDrawing="NO" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kOP-Rg-Mvb">
+                                <rect key="frame" x="0.0" y="623" width="375" height="44"/>
+                                <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
+                                <items>
+                                    <barButtonItem style="plain" systemItem="flexibleSpace" id="Wcn-Rh-qba"/>
+                                    <barButtonItem title="Item" id="LlY-NF-IiS" userLabel="Save">
+                                        <connections>
+                                            <action selector="saveButtonTapped:" destination="J6p-g8-CHO" id="oZp-Hv-neh"/>
+                                        </connections>
+                                    </barButtonItem>
+                                    <barButtonItem style="plain" systemItem="flexibleSpace" id="xmG-u1-O7D"/>
+                                </items>
+                            </toolbar>
                         </subviews>
                         <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                         <constraints>
                             <constraint firstAttribute="trailing" secondItem="vA7-yc-aM1" secondAttribute="trailing" id="36a-TC-Qul"/>
                             <constraint firstItem="vA7-yc-aM1" firstAttribute="top" secondItem="Vdh-Gp-eV6" secondAttribute="top" id="B3X-Ni-wvz"/>
                             <constraint firstItem="vA7-yc-aM1" firstAttribute="leading" secondItem="Vdh-Gp-eV6" secondAttribute="leading" id="S3f-mR-ElS"/>
-                            <constraint firstItem="vA7-yc-aM1" firstAttribute="bottom" secondItem="UQD-kz-Mfv" secondAttribute="top" id="wSm-cl-ClV"/>
+                            <constraint firstItem="vA7-yc-aM1" firstAttribute="bottom" secondItem="UQD-kz-Mfv" secondAttribute="top" constant="-44" id="wSm-cl-ClV"/>
                         </constraints>
                     </view>
                     <connections>
+                        <outlet property="saveButton" destination="LlY-NF-IiS" id="Vh2-iV-omb"/>
                         <outlet property="tableView" destination="vA7-yc-aM1" id="nuO-LH-LFc"/>
+                        <outlet property="toolBar" destination="kOP-Rg-Mvb" id="lu3-pV-yxw"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="UoZ-ya-W3e" userLabel="First Responder" sceneMemberID="firstResponder"/>

+ 67 - 9
Picker/DocumentPickerViewController.swift

@@ -27,7 +27,15 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
     
     // MARK: - Properties
     
-    var provider : providerSession?
+    var providerDB : providerSessionDB?
+    
+    lazy var fileCoordinator: NSFileCoordinator = {
+    
+        let fileCoordinator = NSFileCoordinator()
+        fileCoordinator.purposeIdentifier = self.providerIdentifier
+        return fileCoordinator
+        
+    }()
     
     var metadata : CCMetadata?
     var recordsTableMetadata : [TableMetadata]?
@@ -61,11 +69,14 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
     
     @IBOutlet weak var tableView: UITableView!
     
+    @IBOutlet weak var toolBar: UIToolbar!
+    @IBOutlet weak var saveButton: UIBarButtonItem!
+    
     // MARK: - View Life Cycle
     
     override func viewDidLoad() {
         
-        provider = providerSession.sharedInstance
+        providerDB = providerSessionDB.sharedInstance
         
         if let record = CCCoreData.getActiveAccount() {
             
@@ -114,25 +125,34 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
     }
     
     // MARK: - Overridden Instance Methods
+    
     override func prepareForPresentation(in mode: UIDocumentPickerMode) {
         
         switch mode {
+            
         case .exportToService:
-            //Show confirmation button
+            
             print("Document Picker Mode : exportToService")
+            saveButton.title = "Save in this position"
+            
         case .moveToService:
+            
             //Show confirmation button
             print("Document Picker Mode : moveToService")
+            saveButton.title = "Save in this position"
+            
         case .open:
-            //Show file list
+            
             print("Document Picker Mode : open")
+            saveButton.tintColor = UIColor.clear
+            
         case .import:
-            //Show file list
+            
             print("Document Picker Mode : import")
+            saveButton.tintColor = UIColor.clear
         }
     }
 
-    
     //  MARK: - Read folder
     
     func readFolder() {
@@ -328,6 +348,44 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
     }
 }
 
+// MARK: - IBActions
+
+extension DocumentPickerViewController {
+    
+    @IBAction func saveButtonTapped(_ sender: AnyObject) {
+        
+        guard let sourceURL = originalURL else {
+            return
+        }
+        
+        switch documentPickerMode {
+            
+        case .moveToService, .exportToService:
+            
+            let fileName = sourceURL.deletingPathExtension().lastPathComponent
+            
+            /*
+            guard let destinationURL = Note.fileUrlForDocumentNamed(fileName) else {
+                return
+            }
+            
+            fileCoordinator.coordinate(readingItemAt: sourceURL, options: .withoutChanges, error: nil, byAccessor: { [weak self] newURL in
+                do {
+                    try FileManager.default.copyItem(at: sourceURL, to: destinationURL)
+                    self?.dismissGrantingAccess(to: destinationURL)
+                } catch _ {
+                    print("error copying file")
+                }
+            })
+            */
+            
+        default:
+            dismiss(animated: true, completion: nil)
+        }
+    }
+}
+
+
 // MARK: - UITableViewDelegate
 
 extension DocumentPickerViewController: UITableViewDelegate {
@@ -450,13 +508,13 @@ class recordMetadataCell: UITableViewCell {
 
 // MARK: - Class providerSession
 
-class providerSession {
+class providerSessionDB {
     
-    class var sharedInstance : providerSession {
+    class var sharedInstance : providerSessionDB {
         
         struct Static {
             
-            static let instance = providerSession()
+            static let instance = providerSessionDB()
         }
         
         return Static.instance

+ 2 - 4
Picker/Picker-Bridging-Header.h

@@ -6,10 +6,8 @@
 
 
 #import "TableAccount.h"
+#import "CCNetworking.h"
+#import "OCNetworking.h"
 #import "CCCoreData.h"
 #import "CCGlobal.h"
-
-
 #import "CCHud.h"
-#import "CCMove.h"
-#import "CCSection.h"