Procházet zdrojové kódy

improved change layout

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana před 2 roky
rodič
revize
6e16595c95

+ 11 - 0
iOSClient/Data/NCDataSource.swift

@@ -87,6 +87,17 @@ class NCDataSource: NSObject {
         self.directory = nil
     }
 
+    func changeGroupByField(_ groupByField: String) {
+
+        self.groupByField = groupByField
+        print("DATASOURCE: set group by filed " + groupByField)
+        self.metadatasForSection.removeAll()
+        self.sectionsValue.removeAll()
+        print("DATASOURCE: remove  all sections")
+
+        createSections()
+    }
+
     func addSection(metadatas: [tableMetadata], searchResult: NCCSearchResult?) {
 
         self.metadatas.append(contentsOf: metadatas)

+ 18 - 14
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -807,28 +807,30 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if collectionView.collectionViewLayout == gridLayout {
             // list layout
             headerMenu?.buttonSwitch.accessibilityLabel = NSLocalizedString("_grid_view_", comment: "")
-            UIView.animate(withDuration: 0.0, animations: {
-                self.collectionView.collectionViewLayout.invalidateLayout()
-                self.collectionView.setCollectionViewLayout(self.listLayout, animated: false, completion: { _ in
-                    self.collectionView.reloadData()
-                })
-            })
             layoutForView?.layout = NCGlobal.shared.layoutList
             NCUtility.shared.setLayoutForView(key: layoutKey, serverUrl: serverUrl, layout: layoutForView?.layout)
+            self.collectionView.collectionViewLayout.invalidateLayout()
+            self.collectionView.setCollectionViewLayout(self.listLayout, animated: false, completion: { _ in
+                self.groupByField = "name"
+                self.dataSource.changeGroupByField(self.groupByField)
+                self.collectionView.reloadData()
+            })
         } else {
             // grid layout
             headerMenu?.buttonSwitch.accessibilityLabel = NSLocalizedString("_list_view_", comment: "")
-            UIView.animate(withDuration: 0.0, animations: {
-                self.collectionView.collectionViewLayout.invalidateLayout()
-                self.collectionView.setCollectionViewLayout(self.gridLayout, animated: false, completion: { _ in
-                    self.collectionView.reloadData()
-                })
-            })
             layoutForView?.layout = NCGlobal.shared.layoutGrid
             NCUtility.shared.setLayoutForView(key: layoutKey, serverUrl: serverUrl, layout: layoutForView?.layout)
+            self.collectionView.collectionViewLayout.invalidateLayout()
+            self.collectionView.setCollectionViewLayout(self.gridLayout, animated: false, completion: { _ in
+                if self.isSearching {
+                    self.groupByField = "name"
+                } else {
+                    self.groupByField = "classFile"
+                }
+                self.dataSource.changeGroupByField(self.groupByField)
+                self.collectionView.reloadData()
+            })
         }
-        
-        reloadDataSource()
     }
 
     func tapButtonOrder(_ sender: Any) {
@@ -901,6 +903,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     }
 
     func tapButtonSection(_ sender: Any, metadataForSection: NCMetadataForSection?) {
+
+        self.headerMenu?.setStatusButtonsView(enable: false)
         unifiedSearchMore(metadataForSection: metadataForSection)
     }