Ver código fonte

coding

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 anos atrás
pai
commit
efb6e3100c

+ 2 - 1
iOSClient/Data/NCDataSource.swift

@@ -238,7 +238,8 @@ class NCDataSource: NSObject {
     }
 
     func getSectionValue(indexPath: IndexPath) -> String {
-        
+
+        if metadatasForSection.count == 0 { return "" }
         let metadataForSection = self.metadatasForSection[indexPath.section]
         return metadataForSection.sectionValue
     }

+ 85 - 62
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -54,8 +54,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     internal var listLayout: NCListLayout!
     internal var gridLayout: NCGridLayout!
 
-    private let headerHeight: CGFloat = 50
-    private var headerRichWorkspaceHeight: CGFloat = 0
+    let headerCommand: CGFloat = 50
+    let headerSection: CGFloat = 50
+
     private let footerHeight: CGFloat = 0
     private let footerEndHeight: CGFloat = 100
 
@@ -121,7 +122,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         }
 
         // Empty
-        emptyDataSet = NCEmptyDataSet(view: collectionView, offset: headerHeight, delegate: self)
+        emptyDataSet = NCEmptyDataSet(view: collectionView, offset: headerCommand, delegate: self)
 
         // Long Press on CollectionView
         let longPressedGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressCollecationView(_:)))
@@ -676,6 +677,28 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         return userAlias
     }
 
+    func getHeaderHeight(section:Int) -> (heightHeaderCommand: CGFloat, heightHeaderRichWorkspace: CGFloat, heightHeaderSection: CGFloat) {
+
+        var headerRichWorkspace: CGFloat = 0
+
+        if let richWorkspaceText = richWorkspaceText {
+            let trimmed = richWorkspaceText.trimmingCharacters(in: .whitespaces)
+            if trimmed.count > 0 && !isSearching {
+                headerRichWorkspace = UIScreen.main.bounds.size.height / 4
+            }
+        }
+
+        if section == 0 && dataSource.numberOfSections() > 1 {
+            return (headerCommand, headerRichWorkspace, headerSection)
+        } else if section == 0 && dataSource.numberOfSections() == 1 {
+            return (headerCommand, headerRichWorkspace, 0)
+        } else if section > 1 && dataSource.numberOfSections() > 1 {
+            return (0, 0, headerSection)
+        } else {
+            return (0, 0, 0)
+        }
+    }
+
     // MARK: - BackgroundImageColor Delegate
 
     func colorPickerCancel() {
@@ -1310,56 +1333,6 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
 
 extension NCCollectionViewCommon: UICollectionViewDataSource {
 
-    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
-
-        if kind == UICollectionView.elementKindSectionHeader {
-
-            if dataSource.numberOfSections() == 1 {
-
-                let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeaderMenu", for: indexPath) as! NCSectionHeaderMenu
-                self.headerMenu = header
-
-                if collectionView.collectionViewLayout == gridLayout {
-                    header.buttonSwitch.setImage(UIImage(named: "switchList")!.image(color: NCBrandColor.shared.gray, size: 50), for: .normal)
-                    header.buttonSwitch.accessibilityLabel = NSLocalizedString("_list_view_", comment: "")
-                } else {
-                    header.buttonSwitch.setImage(UIImage(named: "switchGrid")!.image(color: NCBrandColor.shared.gray, size: 50), for: .normal)
-                    header.buttonSwitch.accessibilityLabel = NSLocalizedString("_grid_view_", comment: "")
-                }
-
-                header.delegate = self
-                header.setStatusButton(count: dataSource.metadatasSource.count)
-                header.setTitleSorted(datasourceTitleButton: layoutForView?.titleButtonHeader ?? "")
-                header.viewRichWorkspaceHeightConstraint.constant = headerRichWorkspaceHeight
-                header.setRichWorkspaceText(richWorkspaceText: richWorkspaceText)
-
-                return header
-
-            } else {
-
-                let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeader", for: indexPath) as! NCSectionHeader
-
-                header.labelSection.text = self.dataSource.getSectionValue(indexPath: indexPath).firstUppercased
-                header.labelSection.textColor = NCBrandColor.shared.brandElement
-
-                return header
-            }
-
-        } else {
-
-            let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as! NCSectionFooter
-
-            if dataSource.numberOfSections() == 1 {
-                let info = dataSource.getFooterInformation()
-                footer.setTitleLabel(directories: info.directories, files: info.files, size: info.size )
-            } else {
-                footer.setTitleLabel(text: "")
-            }
-
-            return footer
-        }
-    }
-
     func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
         guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return }
 
@@ -1817,25 +1790,75 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
 
         return collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
     }
-}
 
-extension NCCollectionViewCommon: UICollectionViewDelegateFlowLayout {
+    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
 
-    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
+        if kind == UICollectionView.elementKindSectionHeader {
 
-        headerRichWorkspaceHeight = 0
+            if indexPath.section == 0 {
 
-        if let richWorkspaceText = richWorkspaceText {
-            let trimmed = richWorkspaceText.trimmingCharacters(in: .whitespaces)
-            if trimmed.count > 0 && !isSearching {
-                headerRichWorkspaceHeight = UIScreen.main.bounds.size.height / 4
+                let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeaderMenu", for: indexPath) as! NCSectionHeaderMenu
+                let (_, heightHeaderRichWorkspace, heightHeaderSection) = getHeaderHeight(section: indexPath.section)
+
+                self.headerMenu = header
+
+                if collectionView.collectionViewLayout == gridLayout {
+                    header.buttonSwitch.setImage(UIImage(named: "switchList")!.image(color: NCBrandColor.shared.gray, size: 50), for: .normal)
+                    header.buttonSwitch.accessibilityLabel = NSLocalizedString("_list_view_", comment: "")
+                } else {
+                    header.buttonSwitch.setImage(UIImage(named: "switchGrid")!.image(color: NCBrandColor.shared.gray, size: 50), for: .normal)
+                    header.buttonSwitch.accessibilityLabel = NSLocalizedString("_grid_view_", comment: "")
+                }
+
+                header.delegate = self
+                header.setStatusButton(count: dataSource.metadatasSource.count)
+                header.setTitleSorted(datasourceTitleButton: layoutForView?.titleButtonHeader ?? "")
+                header.setRichWorkspaceText(richWorkspaceText: richWorkspaceText)
+                header.labelSection.text = self.dataSource.getSectionValue(indexPath: indexPath).firstUppercased
+                header.labelSection.textColor = NCBrandColor.shared.brandElement
+
+                header.setRichWorkspaceHeight(heightHeaderRichWorkspace)
+                header.setSectionHeight(heightHeaderSection)
+
+                return header
+
+            } else {
+
+                let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeader", for: indexPath) as! NCSectionHeader
+
+                header.labelSection.text = self.dataSource.getSectionValue(indexPath: indexPath).firstUppercased
+                header.labelSection.textColor = NCBrandColor.shared.brandElement
+
+                return header
+            }
+
+        } else {
+
+            let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as! NCSectionFooter
+
+            if dataSource.numberOfSections() == 1 {
+                let info = dataSource.getFooterInformation()
+                footer.setTitleLabel(directories: info.directories, files: info.files, size: info.size )
+            } else {
+                footer.setTitleLabel(text: "")
             }
+
+            return footer
         }
+    }
+}
+
+extension NCCollectionViewCommon: UICollectionViewDelegateFlowLayout {
 
-        return CGSize(width: collectionView.frame.width, height: headerHeight + headerRichWorkspaceHeight)
+    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
+
+        let (heightHeaderCommand, heightHeaderRichWorkspace, heightHeaderSection) = getHeaderHeight(section: section)
+
+        return CGSize(width: collectionView.frame.width, height: heightHeaderCommand + heightHeaderRichWorkspace + heightHeaderSection)
     }
 
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
+
         if dataSource.numberOfSections() == 1 {
             return CGSize(width: collectionView.frame.width, height: footerEndHeight)
         } else {

+ 16 - 2
iOSClient/Main/Section Header Footer/NCSectionHeaderFooter.swift

@@ -31,14 +31,15 @@ class NCSectionHeaderMenu: UICollectionReusableView, UIGestureRecognizerDelegate
     @IBOutlet weak var buttonOrder: UIButton!
     @IBOutlet weak var buttonOrderWidthConstraint: NSLayoutConstraint!
     @IBOutlet weak var viewRichWorkspace: UIView!
-    @IBOutlet weak var viewRichWorkspaceHeightConstraint: NSLayoutConstraint!
     @IBOutlet weak var textViewRichWorkspace: UITextView!
     @IBOutlet weak var separator: UIView!
     @IBOutlet weak var separatorHeightConstraint: NSLayoutConstraint!
     @IBOutlet weak var viewSection: UIView!
-    @IBOutlet weak var viewSectionHeightConstraint: NSLayoutConstraint!
     @IBOutlet weak var labelSection: UILabel!
 
+    @IBOutlet weak var viewRichWorkspaceHeightConstraint: NSLayoutConstraint!
+    @IBOutlet weak var viewSectionHeightConstraint: NSLayoutConstraint!
+
     weak var delegate: NCSectionHeaderMenuDelegate?
 
     private var markdownParser = MarkdownParser()
@@ -129,6 +130,19 @@ class NCSectionHeaderMenu: UICollectionReusableView, UIGestureRecognizerDelegate
         }
     }
 
+    func setRichWorkspaceHeight(_ size: CGFloat) {
+        viewRichWorkspaceHeightConstraint.constant = size
+    }
+
+    func setSectionHeight(_ size:CGFloat) {
+        viewSectionHeightConstraint.constant = size
+        if size == 0 {
+            viewSection.isHidden = true
+        } else {
+            viewSection.isHidden = false
+        }
+    }
+
     @IBAction func touchUpInsideMore(_ sender: Any) {
         delegate?.tapMoreHeader(sender: sender)
     }

+ 9 - 9
iOSClient/Main/Section Header Footer/NCSectionHeaderMenu.xib

@@ -12,14 +12,14 @@
         <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
         <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
         <collectionReusableView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" reuseIdentifier="sectionHeaderMenu" id="tys-A2-nDX" customClass="NCSectionHeaderMenu" customModule="Nextcloud" customModuleProvider="target">
-            <rect key="frame" x="0.0" y="0.0" width="375" height="299"/>
+            <rect key="frame" x="0.0" y="0.0" width="375" height="150"/>
             <autoresizingMask key="autoresizingMask"/>
             <subviews>
                 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="QBu-GJ-Y52" userLabel="View Menu">
-                    <rect key="frame" x="0.0" y="0.0" width="375" height="199"/>
+                    <rect key="frame" x="0.0" y="0.0" width="375" height="50"/>
                     <subviews>
                         <button opaque="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1LD-cd-zhc" userLabel="buttonSwitch">
-                            <rect key="frame" x="12" y="87" width="25" height="25"/>
+                            <rect key="frame" x="12" y="12.5" width="25" height="25"/>
                             <constraints>
                                 <constraint firstAttribute="width" constant="25" id="D76-X9-Tw9"/>
                                 <constraint firstAttribute="height" constant="25" id="izT-Ru-XYG"/>
@@ -30,7 +30,7 @@
                             </connections>
                         </button>
                         <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0bo-yl-t5k" userLabel="buttonOrder">
-                            <rect key="frame" x="55" y="85.5" width="230" height="28"/>
+                            <rect key="frame" x="55" y="11" width="230" height="28"/>
                             <constraints>
                                 <constraint firstAttribute="width" constant="230" id="jvv-Ug-l3I"/>
                             </constraints>
@@ -43,7 +43,7 @@
                             </connections>
                         </button>
                         <button hidden="YES" opaque="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="D0O-wK-14O" userLabel="buttonSwitch">
-                            <rect key="frame" x="338" y="87" width="25" height="25"/>
+                            <rect key="frame" x="338" y="12.5" width="25" height="25"/>
                             <constraints>
                                 <constraint firstAttribute="width" constant="25" id="aEr-j8-JDO"/>
                                 <constraint firstAttribute="height" constant="25" id="bvx-Uh-NWD"/>
@@ -54,7 +54,7 @@
                             </connections>
                         </button>
                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="LZu-Te-clJ" userLabel="Separator">
-                            <rect key="frame" x="0.0" y="198" width="375" height="1"/>
+                            <rect key="frame" x="0.0" y="49" width="375" height="1"/>
                             <color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                             <color key="tintColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                             <constraints>
@@ -75,7 +75,7 @@
                     </constraints>
                 </view>
                 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="NC1-5C-E5z" userLabel="View RichWorkspace">
-                    <rect key="frame" x="0.0" y="199" width="375" height="50"/>
+                    <rect key="frame" x="0.0" y="50" width="375" height="50"/>
                     <subviews>
                         <textView clipsSubviews="YES" multipleTouchEnabled="YES" userInteractionEnabled="NO" contentMode="scaleToFill" editable="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="pYo-pF-MGv">
                             <rect key="frame" x="5" y="0.0" width="365" height="50"/>
@@ -94,7 +94,7 @@
                     </constraints>
                 </view>
                 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="f9U-NY-4OS">
-                    <rect key="frame" x="0.0" y="249" width="375" height="50"/>
+                    <rect key="frame" x="0.0" y="100" width="375" height="50"/>
                     <subviews>
                         <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mB5-5n-AL9">
                             <rect key="frame" x="10" y="16.5" width="355" height="17"/>
@@ -138,7 +138,7 @@
                 <outlet property="viewSection" destination="f9U-NY-4OS" id="idM-C9-2nP"/>
                 <outlet property="viewSectionHeightConstraint" destination="ZcL-Wd-xhN" id="RDs-yy-I6W"/>
             </connections>
-            <point key="canvasLocation" x="138.40000000000001" y="255.92203898050977"/>
+            <point key="canvasLocation" x="124" y="140.32983508245877"/>
         </collectionReusableView>
     </objects>
     <resources>