Explorar o código

Start new share extension

marinofaggiana %!s(int64=3) %!d(string=hai) anos
pai
achega
bda3d25fda
Modificáronse 2 ficheiros con 143 adicións e 21 borrados
  1. 77 13
      Share/MainInterface.storyboard
  2. 66 8
      Share/NCShareExtension.swift

+ 77 - 13
Share/MainInterface.storyboard

@@ -18,7 +18,7 @@
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="0HI-k1-SD0">
-                                <rect key="frame" x="0.0" y="88" width="414" height="725"/>
+                                <rect key="frame" x="0.0" y="88" width="414" height="508"/>
                                 <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                                 <collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="0.0" minimumInteritemSpacing="0.0" id="D7P-75-aB1">
                                     <size key="itemSize" width="0.0" height="0.0"/>
@@ -32,35 +32,96 @@
                                     <outlet property="delegate" destination="VYq-xA-D35" id="EXB-bA-tje"/>
                                 </connections>
                             </collectionView>
-                            <toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="d1F-Sb-G9O">
-                                <rect key="frame" x="0.0" y="813" width="414" height="49"/>
-                                <items>
-                                    <barButtonItem title="Item" id="McS-ZS-WzN"/>
-                                </items>
-                            </toolbar>
+                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="FaV-kz-PEs">
+                                <rect key="frame" x="0.0" y="596" width="414" height="300"/>
+                                <subviews>
+                                    <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="LAs-iQ-u1X">
+                                        <rect key="frame" x="0.0" y="0.0" width="414" height="1"/>
+                                        <color key="backgroundColor" systemColor="separatorColor"/>
+                                        <constraints>
+                                            <constraint firstAttribute="height" constant="1" id="wOp-so-23c"/>
+                                        </constraints>
+                                    </view>
+                                    <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="eU0-LW-AnG">
+                                        <rect key="frame" x="0.0" y="11" width="414" height="239"/>
+                                        <color key="backgroundColor" systemColor="systemBackgroundColor"/>
+                                        <prototypes>
+                                            <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="Cell" rowHeight="50" id="6Kt-n0-i8J">
+                                                <rect key="frame" x="0.0" y="28" width="414" height="50"/>
+                                                <autoresizingMask key="autoresizingMask"/>
+                                                <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="6Kt-n0-i8J" id="WGN-Zn-lR8">
+                                                    <rect key="frame" x="0.0" y="0.0" width="414" height="50"/>
+                                                    <autoresizingMask key="autoresizingMask"/>
+                                                    <subviews>
+                                                        <imageView clipsSubviews="YES" userInteractionEnabled="NO" tag="10" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="uvl-De-S9p">
+                                                            <rect key="frame" x="15" y="5" width="40" height="40"/>
+                                                            <constraints>
+                                                                <constraint firstAttribute="width" constant="40" id="Vpb-6e-ta9"/>
+                                                                <constraint firstAttribute="height" constant="40" id="wvf-Ey-woY"/>
+                                                            </constraints>
+                                                        </imageView>
+                                                        <label opaque="NO" userInteractionEnabled="NO" tag="20" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rz6-pe-DB5">
+                                                            <rect key="frame" x="70" y="16.666666666666668" width="329" height="17.000000000000004"/>
+                                                            <fontDescription key="fontDescription" type="system" pointSize="14"/>
+                                                            <nil key="textColor"/>
+                                                            <nil key="highlightedColor"/>
+                                                        </label>
+                                                    </subviews>
+                                                    <constraints>
+                                                        <constraint firstItem="rz6-pe-DB5" firstAttribute="centerY" secondItem="WGN-Zn-lR8" secondAttribute="centerY" id="Ag7-Ow-Ifk"/>
+                                                        <constraint firstItem="uvl-De-S9p" firstAttribute="centerY" secondItem="WGN-Zn-lR8" secondAttribute="centerY" id="bFC-cS-ePy"/>
+                                                        <constraint firstItem="rz6-pe-DB5" firstAttribute="leading" secondItem="uvl-De-S9p" secondAttribute="trailing" constant="15" id="f94-aJ-igq"/>
+                                                        <constraint firstItem="uvl-De-S9p" firstAttribute="leading" secondItem="WGN-Zn-lR8" secondAttribute="leading" constant="15" id="ko0-iM-oWa"/>
+                                                        <constraint firstAttribute="trailing" secondItem="rz6-pe-DB5" secondAttribute="trailing" constant="15" id="mZN-du-84X"/>
+                                                    </constraints>
+                                                </tableViewCellContentView>
+                                            </tableViewCell>
+                                        </prototypes>
+                                        <connections>
+                                            <outlet property="dataSource" destination="VYq-xA-D35" id="pzA-Br-UUG"/>
+                                            <outlet property="delegate" destination="VYq-xA-D35" id="DAj-hF-SRY"/>
+                                        </connections>
+                                    </tableView>
+                                </subviews>
+                                <color key="backgroundColor" systemColor="systemBackgroundColor"/>
+                                <constraints>
+                                    <constraint firstItem="eU0-LW-AnG" firstAttribute="top" secondItem="LAs-iQ-u1X" secondAttribute="bottom" constant="10" id="14j-96-VwG"/>
+                                    <constraint firstAttribute="height" constant="300" id="50u-lA-AUo"/>
+                                    <constraint firstItem="eU0-LW-AnG" firstAttribute="leading" secondItem="FaV-kz-PEs" secondAttribute="leading" id="E40-Ul-MEV"/>
+                                    <constraint firstItem="LAs-iQ-u1X" firstAttribute="leading" secondItem="FaV-kz-PEs" secondAttribute="leading" id="dr0-zN-pwa"/>
+                                    <constraint firstItem="LAs-iQ-u1X" firstAttribute="top" secondItem="FaV-kz-PEs" secondAttribute="top" id="gvj-gm-XbO"/>
+                                    <constraint firstAttribute="trailing" secondItem="eU0-LW-AnG" secondAttribute="trailing" id="qQA-Ix-Ge1"/>
+                                    <constraint firstAttribute="bottom" secondItem="eU0-LW-AnG" secondAttribute="bottom" constant="50" id="r6E-QV-nj7"/>
+                                    <constraint firstAttribute="trailing" secondItem="LAs-iQ-u1X" secondAttribute="trailing" id="v8j-JB-2Io"/>
+                                </constraints>
+                            </view>
                         </subviews>
                         <viewLayoutGuide key="safeArea" id="vaA-85-uNN"/>
                         <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                         <constraints>
                             <constraint firstItem="0HI-k1-SD0" firstAttribute="top" secondItem="vaA-85-uNN" secondAttribute="top" id="552-sP-Paj"/>
+                            <constraint firstAttribute="bottom" secondItem="FaV-kz-PEs" secondAttribute="bottom" id="7TV-nN-N7u"/>
+                            <constraint firstItem="FaV-kz-PEs" firstAttribute="leading" secondItem="vaA-85-uNN" secondAttribute="leading" id="DUP-nF-RRO"/>
+                            <constraint firstItem="vaA-85-uNN" firstAttribute="trailing" secondItem="FaV-kz-PEs" secondAttribute="trailing" id="GSd-jh-TJN"/>
                             <constraint firstItem="vaA-85-uNN" firstAttribute="trailing" secondItem="0HI-k1-SD0" secondAttribute="trailing" id="KT1-YT-Lps"/>
-                            <constraint firstItem="vaA-85-uNN" firstAttribute="bottom" secondItem="d1F-Sb-G9O" secondAttribute="bottom" id="Wmt-Y6-V8T"/>
-                            <constraint firstItem="d1F-Sb-G9O" firstAttribute="leading" secondItem="vaA-85-uNN" secondAttribute="leading" id="aCp-9X-sbV"/>
-                            <constraint firstItem="d1F-Sb-G9O" firstAttribute="top" secondItem="0HI-k1-SD0" secondAttribute="bottom" id="buJ-18-IOK"/>
-                            <constraint firstItem="vaA-85-uNN" firstAttribute="trailing" secondItem="d1F-Sb-G9O" secondAttribute="trailing" id="o2P-Vd-ejX"/>
+                            <constraint firstItem="FaV-kz-PEs" firstAttribute="top" secondItem="0HI-k1-SD0" secondAttribute="bottom" id="sQc-Jm-MaY"/>
                             <constraint firstItem="0HI-k1-SD0" firstAttribute="leading" secondItem="vaA-85-uNN" secondAttribute="leading" id="uLL-RT-YFO"/>
                         </constraints>
                     </view>
                     <navigationItem key="navigationItem" id="N5K-De-4CP">
-                        <barButtonItem key="rightBarButtonItem" title="Cancel" id="qHj-AF-EN7">
+                        <barButtonItem key="rightBarButtonItem" title="cancel" id="qHj-AF-EN7">
                             <connections>
                                 <action selector="actionCancel:" destination="VYq-xA-D35" id="LRW-H2-pbh"/>
                             </connections>
                         </barButtonItem>
                     </navigationItem>
                     <connections>
-                        <outlet property="buttonCancel" destination="qHj-AF-EN7" id="Fky-XJ-BxL"/>
+                        <outlet property="cancelButton" destination="qHj-AF-EN7" id="ArV-Vj-BiO"/>
                         <outlet property="collectionView" destination="0HI-k1-SD0" id="xme-mG-bnz"/>
+                        <outlet property="commandViewHeightConstraint" destination="50u-lA-AUo" id="ygm-ah-cHw"/>
+                        <outlet property="separatorHeightConstraint" destination="wOp-so-23c" id="r8x-LQ-sxb"/>
+                        <outlet property="separatorView" destination="LAs-iQ-u1X" id="53E-lW-30T"/>
+                        <outlet property="tableView" destination="eU0-LW-AnG" id="mLD-VN-uyz"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="vH8-UY-9MN" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -87,6 +148,9 @@
         </scene>
     </scenes>
     <resources>
+        <systemColor name="separatorColor">
+            <color red="0.23529411764705882" green="0.23529411764705882" blue="0.2627450980392157" alpha="0.28999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
+        </systemColor>
         <systemColor name="systemBackgroundColor">
             <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
         </systemColor>

+ 66 - 8
Share/NCShareExtension.swift

@@ -27,8 +27,15 @@ import NCCommunication
 class NCShareExtension: UIViewController, NCListCellDelegate, NCGridCellDelegate, NCSectionHeaderMenuDelegate, NCEmptyDataSetDelegate {
     
     @IBOutlet weak var collectionView: UICollectionView!
-    @IBOutlet weak var buttonCancel: UIBarButtonItem!
-   
+    @IBOutlet weak var tableView: UITableView!
+    @IBOutlet weak var cancelButton: UIBarButtonItem!
+    @IBOutlet weak var separatorView: UIView!
+    @IBOutlet weak var separatorHeightConstraint: NSLayoutConstraint!
+    @IBOutlet weak var commandViewHeightConstraint: NSLayoutConstraint!
+
+    //@IBOutlet weak var createFolderButton: UIBarButtonItem!
+    //@IBOutlet weak var uploadButton: UIBarButtonItem!
+
     // -------------------------------------------------------------
     var titleCurrentFolder = NCBrandOptions.shared.brand
     var serverUrl = ""
@@ -63,7 +70,8 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCGridCellDelegate
     private let headerHeight: CGFloat = 50
     private var headerRichWorkspaceHeight: CGFloat = 0
     private let footerHeight: CGFloat = 100
-    
+    private let heightCell: CGFloat = 50
+
     private var shares: [tableShare]?
     
     private let refreshControl = UIRefreshControl()
@@ -73,7 +81,7 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCGridCellDelegate
     override func viewDidLoad() {
         super.viewDidLoad()
         
-        self.navigationController?.navigationBar.prefersLargeTitles = true
+        self.navigationController?.navigationBar.prefersLargeTitles = false
         
         // Cell
         collectionView.register(UINib.init(nibName: "NCListCell", bundle: nil), forCellWithReuseIdentifier: "listCell")
@@ -97,6 +105,12 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCGridCellDelegate
         
         // Empty
         emptyDataSet = NCEmptyDataSet.init(view: collectionView, offset: 0, delegate: self)
+
+        separatorView.backgroundColor = NCBrandColor.shared.separator
+        
+        cancelButton.title = NSLocalizedString("_cancel_", comment: "")
+        //createFolderButton.title = NSLocalizedString("_create_folder_", comment: "")
+        //uploadButton.title = NSLocalizedString("_upload_", comment: "")
     }
     
     override func viewWillAppear(_ animated: Bool) {
@@ -155,13 +169,13 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCGridCellDelegate
                         self.extensionContext?.completeRequest(returningItems: self.extensionContext?.inputItems, completionHandler: nil)
                         return
                     } else {
-                        self.loadDatasource(withLoadFolder: true)
+                        self.tableView.reloadData()
                     }
                 }
             }
-        } else {
-            loadDatasource(withLoadFolder: true)
         }
+            
+        loadDatasource(withLoadFolder: true)
 
         shares = NCManageDatabase.shared.getTableShares(account: activeAccount.account, serverUrl: serverUrl)
     }
@@ -205,7 +219,7 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCGridCellDelegate
         extensionContext?.completeRequest(returningItems: extensionContext?.inputItems, completionHandler: nil)
     }
     
-    func createFolderButtonPressed(_ sender: UIButton) {
+    @IBAction func actionCreateFolder(_ sender: UIButton) {
         
         let alertController = UIAlertController(title: NSLocalizedString("_create_folder_", comment: ""), message:"", preferredStyle: .alert)
         
@@ -229,6 +243,10 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCGridCellDelegate
         self.present(alertController, animated: true, completion:nil)
     }
     
+    @IBAction func actionUpload(_ sender: UIButton) {
+        
+    }
+    
     // MARK: TAP EVENT
     
     func tapSwitchHeader(sender: Any) {
@@ -612,12 +630,14 @@ extension NCShareExtension: UICollectionViewDelegateFlowLayout {
         
         headerRichWorkspaceHeight = 0
         
+        /*
         if let richWorkspaceText = richWorkspaceText {
             let trimmed = richWorkspaceText.trimmingCharacters(in: .whitespaces)
             if trimmed.count > 0 {
                 headerRichWorkspaceHeight = UIScreen.main.bounds.size.height / 4
             }
         }
+        */
         
         return CGSize(width: collectionView.frame.width, height: headerHeight + headerRichWorkspaceHeight)
     }
@@ -627,6 +647,44 @@ extension NCShareExtension: UICollectionViewDelegateFlowLayout {
     }
 }
 
+
+
+extension NCShareExtension: UITableViewDelegate {
+    
+    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
+        return heightCell
+    }
+    
+    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+        
+    }
+}
+
+extension NCShareExtension: UITableViewDataSource {
+    
+    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+        filesName.count
+    }
+    
+    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+               
+        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
+       
+        let imageCell = cell.viewWithTag(10) as? UIImageView
+        let fileNameCell = cell.viewWithTag(20) as? UILabel
+
+        let fileName = filesName[indexPath.row]
+        imageCell?.image = NCUtility.shared.loadImage(named: "file")
+        if let image = UIImage(contentsOfFile: (NSTemporaryDirectory() + fileName)) {
+            imageCell?.image = image
+        }
+        
+        fileNameCell?.text = fileName
+        
+        return cell
+    }
+}
+
 // MARK: - NC API & Algorithm
 
 extension NCShareExtension {