Browse Source

dev trash

Marino Faggiana 6 years ago
parent
commit
a880ff3492

+ 2 - 2
iOSClient/Trash/NCTrash.storyboard

@@ -21,8 +21,8 @@
                             <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="Zaz-Cl-qpZ">
                                 <rect key="frame" x="0.0" y="20" width="375" height="647"/>
                                 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
-                                <collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="fF1-wd-0xN">
-                                    <size key="itemSize" width="50" height="50"/>
+                                <collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="0.0" minimumInteritemSpacing="0.0" id="fF1-wd-0xN">
+                                    <size key="itemSize" width="0.0" height="0.0"/>
                                     <size key="headerReferenceSize" width="50" height="30"/>
                                     <size key="footerReferenceSize" width="0.0" height="0.0"/>
                                     <inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>

+ 28 - 16
iOSClient/Trash/NCTrash.swift

@@ -9,14 +9,13 @@
 import Foundation
  
 
-class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDelegate, UIGestureRecognizerDelegate, NCTrashListDelegate, NCTrashGridDelegate, NCTrashHeaderDelegate {
+class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UIGestureRecognizerDelegate, NCTrashListDelegate, NCTrashGridDelegate, NCTrashHeaderDelegate {
     
     @IBOutlet fileprivate weak var collectionView: UICollectionView!
 
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     var path = ""
     var titleCurrentFolder = NSLocalizedString("_trash_view_", comment: "")
-    var itemHeight: CGFloat = 60
     var datasource = [tableTrash]()
 
     var listLayout: ListLayout!
@@ -29,7 +28,8 @@ class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDe
         collectionView.register(UINib.init(nibName: "NCTrashGridCell", bundle: nil), forCellWithReuseIdentifier: "cell-grid")
         
         listLayout = ListLayout(itemHeight: 60)
-        collectionView.collectionViewLayout = listLayout
+        gridLayout = GridLayout(numberOfColumns: 5)
+        collectionView.collectionViewLayout = gridLayout
     }
     
     override func viewWillAppear(_ animated: Bool) {
@@ -76,7 +76,20 @@ class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDe
     }
     
     func tapSwitchHeader() {
-        print("tap header switch")
+        
+        if collectionView.collectionViewLayout == gridLayout {
+            // list layout
+            UIView.animate(withDuration: 0.1, animations: {
+                self.collectionView.collectionViewLayout.invalidateLayout()
+                self.collectionView.setCollectionViewLayout(self.listLayout, animated: true)
+            })
+        } else {
+            // grid layout
+            UIView.animate(withDuration: 0.1, animations: {
+                self.collectionView.collectionViewLayout.invalidateLayout()
+                self.collectionView.setCollectionViewLayout(self.gridLayout, animated: true)
+            })
+        }
     }
     
     func tapMoreHeader() {
@@ -93,6 +106,11 @@ class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDe
         return trashHeader
     }
     
+    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
+        return CGSize(width: collectionView.frame.width, height: 30)
+    }
+    
+    
     func numberOfSections(in collectionView: UICollectionView) -> Int {
         return 1
     }
@@ -132,7 +150,7 @@ class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDe
         
         } else {
             
-            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell-grid", for: indexPath) as! NCTrashListCell
+            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell-grid", for: indexPath) as! NCTrashGridCell
             cell.delegate = self
             
             cell.fileID = tableTrash.fileID
@@ -165,17 +183,13 @@ class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDe
 class ListLayout: UICollectionViewFlowLayout {
     
     var itemHeight: CGFloat = 60
-    var headerHeight: CGFloat = 30
     
     init(itemHeight: CGFloat) {
         super.init()
         
-        minimumLineSpacing = 1
-        minimumInteritemSpacing = 1
-        
         self.itemHeight = itemHeight
         self.scrollDirection = .vertical
-        self.headerReferenceSize = CGSize(width: 0, height: headerHeight)
+        self.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
     }
     
     required init?(coder aDecoder: NSCoder) {
@@ -200,18 +214,16 @@ class ListLayout: UICollectionViewFlowLayout {
 
 class GridLayout: UICollectionViewFlowLayout {
     
-    var numberOfColumns: Int = 3
-    var headerHeight: CGFloat = 30
+    var numberOfColumns: Int = 5
     
     init(numberOfColumns: Int) {
         super.init()
         
-        minimumLineSpacing = 1
-        minimumInteritemSpacing = 1
+        minimumInteritemSpacing = 10
         
         self.numberOfColumns = numberOfColumns
         self.scrollDirection = .vertical
-        self.headerReferenceSize = CGSize(width: 0, height: headerHeight)
+        self.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
     }
     
     required init?(coder aDecoder: NSCoder) {
@@ -222,7 +234,7 @@ class GridLayout: UICollectionViewFlowLayout {
         get {
             if let collectionView = collectionView {
                 let itemWidth: CGFloat = (collectionView.frame.width/CGFloat(self.numberOfColumns)) - self.minimumInteritemSpacing
-                let itemHeight: CGFloat = 100.0
+                let itemHeight: CGFloat = itemWidth + 20 + 60
                 return CGSize(width: itemWidth, height: itemHeight)
             }
             

+ 2 - 7
iOSClient/Trash/NCTrashGridCell.swift

@@ -16,6 +16,8 @@ class NCTrashGridCell: UICollectionViewCell {
     @IBOutlet weak var restore: UIImageView!
     @IBOutlet weak var tapRestore: UIImageView!
 
+    @IBOutlet weak var labelTitle: UILabel!
+
     @IBOutlet weak var more: UIImageView!
     @IBOutlet weak var tapMore: UIImageView!
 
@@ -42,13 +44,6 @@ class NCTrashGridCell: UICollectionViewCell {
         tapMore.addGestureRecognizer(tapGestureMore)
     }
     
-    public func configure(with fileID: String, image: UIImage?, title: String, info: String) {
-
-        self.fileID = fileID
-
-        imageItem.image = image
-    }
-    
     @objc func tapRestore(sender: UITapGestureRecognizer) {
         delegate?.tapRestoreItem(with: fileID)
     }

+ 22 - 12
iOSClient/Trash/NCTrashGridCell.xib

@@ -13,38 +13,44 @@
         <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
         <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
         <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="cell-grid" id="vf1-Kf-9uL" customClass="NCTrashGridCell" customModule="Nextcloud" customModuleProvider="target">
-            <rect key="frame" x="0.0" y="0.0" width="220" height="280"/>
+            <rect key="frame" x="0.0" y="0.0" width="220" height="308"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
             <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO">
-                <rect key="frame" x="0.0" y="0.0" width="220" height="280"/>
+                <rect key="frame" x="0.0" y="0.0" width="220" height="308"/>
                 <autoresizingMask key="autoresizingMask"/>
                 <subviews>
                     <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="5Ci-V1-hf5" userLabel="ImageItem">
-                        <rect key="frame" x="0.0" y="0.0" width="220" height="220"/>
+                        <rect key="frame" x="0.0" y="0.0" width="220" height="228"/>
                     </imageView>
+                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eU3-lY-fKr" userLabel="Label Title">
+                        <rect key="frame" x="0.0" y="228" width="220" height="17"/>
+                        <fontDescription key="fontDescription" type="system" pointSize="14"/>
+                        <nil key="textColor"/>
+                        <nil key="highlightedColor"/>
+                    </label>
                     <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="u5S-jk-VdX" userLabel="tapRestore">
-                        <rect key="frame" x="0.0" y="220" width="60" height="60"/>
+                        <rect key="frame" x="0.0" y="245" width="60" height="60"/>
                         <constraints>
                             <constraint firstAttribute="height" constant="60" id="X2d-a1-gaa"/>
                             <constraint firstAttribute="width" constant="60" id="kFt-s1-hBy"/>
                         </constraints>
                     </imageView>
                     <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="b2F-OH-tLj" userLabel="restore">
-                        <rect key="frame" x="17" y="237" width="26" height="26"/>
+                        <rect key="frame" x="17" y="262" width="26" height="26"/>
                         <constraints>
                             <constraint firstAttribute="height" constant="26" id="L0E-5H-HIf"/>
                             <constraint firstAttribute="width" constant="26" id="Qmu-32-cdJ"/>
                         </constraints>
                     </imageView>
                     <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="BAZ-pD-XUh" userLabel="tapMore">
-                        <rect key="frame" x="160" y="220" width="60" height="60"/>
+                        <rect key="frame" x="160" y="245" width="60" height="60"/>
                         <constraints>
                             <constraint firstAttribute="width" constant="60" id="KeR-CV-it5"/>
                             <constraint firstAttribute="height" constant="60" id="zCg-ZG-RPg"/>
                         </constraints>
                     </imageView>
                     <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="3sA-NC-kIg" userLabel="More">
-                        <rect key="frame" x="177" y="237" width="26" height="26"/>
+                        <rect key="frame" x="177" y="262" width="26" height="26"/>
                         <constraints>
                             <constraint firstAttribute="width" constant="26" id="hoH-4o-Tff"/>
                             <constraint firstAttribute="height" constant="26" id="vGK-h7-x3M"/>
@@ -53,29 +59,33 @@
                 </subviews>
             </view>
             <constraints>
-                <constraint firstItem="VXh-sQ-LeX" firstAttribute="bottom" secondItem="5Ci-V1-hf5" secondAttribute="bottom" constant="60" id="Gvf-MS-ZTo"/>
-                <constraint firstItem="u5S-jk-VdX" firstAttribute="top" secondItem="5Ci-V1-hf5" secondAttribute="bottom" id="Ik4-A3-18F"/>
+                <constraint firstItem="eU3-lY-fKr" firstAttribute="top" secondItem="5Ci-V1-hf5" secondAttribute="bottom" id="4Yq-Nh-z1l"/>
+                <constraint firstItem="u5S-jk-VdX" firstAttribute="top" secondItem="eU3-lY-fKr" secondAttribute="bottom" id="Fzz-oG-ku0"/>
+                <constraint firstItem="VXh-sQ-LeX" firstAttribute="trailing" secondItem="eU3-lY-fKr" secondAttribute="trailing" id="Lu1-AM-kPq"/>
                 <constraint firstItem="5Ci-V1-hf5" firstAttribute="top" secondItem="VXh-sQ-LeX" secondAttribute="top" id="Ouj-ZD-UFm"/>
+                <constraint firstItem="BAZ-pD-XUh" firstAttribute="top" secondItem="eU3-lY-fKr" secondAttribute="bottom" id="PvL-Zh-yPu"/>
                 <constraint firstItem="VXh-sQ-LeX" firstAttribute="trailing" secondItem="BAZ-pD-XUh" secondAttribute="trailing" id="R5r-VT-N0I"/>
-                <constraint firstItem="BAZ-pD-XUh" firstAttribute="top" secondItem="5Ci-V1-hf5" secondAttribute="bottom" id="X6x-hS-u2A"/>
                 <constraint firstItem="3sA-NC-kIg" firstAttribute="centerX" secondItem="BAZ-pD-XUh" secondAttribute="centerX" id="Xnl-Jn-Y8H"/>
                 <constraint firstItem="b2F-OH-tLj" firstAttribute="centerY" secondItem="u5S-jk-VdX" secondAttribute="centerY" id="ZW1-bm-DB8"/>
                 <constraint firstItem="b2F-OH-tLj" firstAttribute="centerX" secondItem="u5S-jk-VdX" secondAttribute="centerX" id="aVh-gg-Krs"/>
                 <constraint firstItem="VXh-sQ-LeX" firstAttribute="trailing" secondItem="5Ci-V1-hf5" secondAttribute="trailing" id="cHT-cP-NN6"/>
+                <constraint firstItem="VXh-sQ-LeX" firstAttribute="bottom" secondItem="5Ci-V1-hf5" secondAttribute="bottom" constant="80" id="eEC-eB-alE"/>
                 <constraint firstItem="u5S-jk-VdX" firstAttribute="leading" secondItem="VXh-sQ-LeX" secondAttribute="leading" id="fxs-Ju-143"/>
+                <constraint firstItem="eU3-lY-fKr" firstAttribute="leading" secondItem="VXh-sQ-LeX" secondAttribute="leading" id="gZe-FC-8XQ"/>
                 <constraint firstItem="3sA-NC-kIg" firstAttribute="centerY" secondItem="BAZ-pD-XUh" secondAttribute="centerY" id="k1J-aj-7W5"/>
                 <constraint firstItem="5Ci-V1-hf5" firstAttribute="leading" secondItem="VXh-sQ-LeX" secondAttribute="leading" id="qT3-WD-iTV"/>
             </constraints>
             <viewLayoutGuide key="safeArea" id="VXh-sQ-LeX"/>
-            <size key="customSize" width="220" height="267"/>
+            <size key="customSize" width="220" height="303"/>
             <connections>
                 <outlet property="imageItem" destination="5Ci-V1-hf5" id="xky-Nw-NUb"/>
+                <outlet property="labelTitle" destination="eU3-lY-fKr" id="0P7-yM-Asb"/>
                 <outlet property="more" destination="3sA-NC-kIg" id="LTq-2s-hq2"/>
                 <outlet property="restore" destination="b2F-OH-tLj" id="bsp-In-8UB"/>
                 <outlet property="tapMore" destination="BAZ-pD-XUh" id="Uxq-lx-bdO"/>
                 <outlet property="tapRestore" destination="u5S-jk-VdX" id="mfd-g7-OtK"/>
             </connections>
-            <point key="canvasLocation" x="88" y="132"/>
+            <point key="canvasLocation" x="88" y="161.01949025487258"/>
         </collectionViewCell>
     </objects>
 </document>

+ 0 - 9
iOSClient/Trash/NCTrashListCell.swift

@@ -49,15 +49,6 @@ class NCTrashListCell: UICollectionViewCell {
         tapMore.addGestureRecognizer(tapGestureMore)
     }
     
-    public func configure(with fileID: String, image: UIImage?, title: String, info: String) {
-
-        self.fileID = fileID
-
-        imageItem.image = image
-        labelTitle.text = title
-        labelInfo.text = info
-    }
-    
     @objc func tapRestore(sender: UITapGestureRecognizer) {
         delegate?.tapRestoreItem(with: fileID)
     }