marinofaggiana 4 жил өмнө
parent
commit
047746c4a1

+ 4 - 4
Nextcloud.xcodeproj/project.pbxproj

@@ -254,7 +254,7 @@
 		F7BAADCB1ED5A87C00B7EAD4 /* NCManageDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BAADB51ED5A87C00B7EAD4 /* NCManageDatabase.swift */; };
 		F7BAADCC1ED5A87C00B7EAD4 /* NCManageDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BAADB51ED5A87C00B7EAD4 /* NCManageDatabase.swift */; };
 		F7BF1B431D51E893000854F6 /* CCLogin.m in Sources */ = {isa = PBXBuildFile; fileRef = F7BF1B401D51E893000854F6 /* CCLogin.m */; };
-		F7C1EEA525053A9C00866ACC /* NCSectionDataSourceMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C1EEA425053A9C00866ACC /* NCSectionDataSourceMetadata.swift */; };
+		F7C1EEA525053A9C00866ACC /* NCDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C1EEA425053A9C00866ACC /* NCDataSource.swift */; };
 		F7C40BE521998D5B0004137E /* MGSwipeTableCell.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7C40BE421998D5A0004137E /* MGSwipeTableCell.framework */; };
 		F7C40BE721998F410004137E /* DZNEmptyDataSet.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7C40BE621998F410004137E /* DZNEmptyDataSet.framework */; };
 		F7C40BEF219994ED0004137E /* KTVCocoaHTTPServer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7C40BEE219994ED0004137E /* KTVCocoaHTTPServer.framework */; };
@@ -635,7 +635,7 @@
 		F7BFCCC11B68C21900548E76 /* CCManageLocation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCManageLocation.m; sourceTree = "<group>"; };
 		F7C0F46E1C8880540059EC54 /* ShareViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = ShareViewController.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
 		F7C0F46F1C8880540059EC54 /* ShareViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ShareViewController.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
-		F7C1EEA425053A9C00866ACC /* NCSectionDataSourceMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCSectionDataSourceMetadata.swift; sourceTree = "<group>"; };
+		F7C1EEA425053A9C00866ACC /* NCDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCDataSource.swift; sourceTree = "<group>"; };
 		F7C40BE221998C050004137E /* PDFGenerator.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PDFGenerator.framework; path = Carthage/Build/iOS/PDFGenerator.framework; sourceTree = "<group>"; };
 		F7C40BE421998D5A0004137E /* MGSwipeTableCell.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MGSwipeTableCell.framework; path = Carthage/Build/iOS/MGSwipeTableCell.framework; sourceTree = "<group>"; };
 		F7C40BE621998F410004137E /* DZNEmptyDataSet.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DZNEmptyDataSet.framework; path = Carthage/Build/iOS/DZNEmptyDataSet.framework; sourceTree = "<group>"; };
@@ -816,7 +816,7 @@
 				F73F537E1E929C8500F8678D /* CCMore.swift */,
 				F78F6FAE1CC8CCB700F4EA25 /* CCSection.h */,
 				F78F6FAF1CC8CCB700F4EA25 /* CCSection.m */,
-				F7C1EEA425053A9C00866ACC /* NCSectionDataSourceMetadata.swift */,
+				F7C1EEA425053A9C00866ACC /* NCDataSource.swift */,
 				F78ACD3E21903BA20088454D /* Cell */,
 				F7DFB7E9219C5A0500680748 /* Create cloud */,
 				F78ACD4D219043E70088454D /* Layout */,
@@ -2044,7 +2044,7 @@
 				F710D1F52405770F00A6033D /* NCViewerPDF.swift in Sources */,
 				F7501C332212E57500FB1415 /* NCMedia.swift in Sources */,
 				F70BFC7420E0FA7D00C67599 /* NCUtility.swift in Sources */,
-				F7C1EEA525053A9C00866ACC /* NCSectionDataSourceMetadata.swift in Sources */,
+				F7C1EEA525053A9C00866ACC /* NCDataSource.swift in Sources */,
 				F713FF002472764100214AF6 /* UIImage+animatedGIF.m in Sources */,
 				F7B174C822FAC0A8000B7579 /* AppDelegate.m in Sources */,
 				F749C10B23C4A5340027D966 /* NCIntroCollectionViewCell.swift in Sources */,

+ 21 - 29
iOSClient/Favorites/NCFavorite.swift

@@ -36,7 +36,7 @@ class NCFavorite: UIViewController, UIGestureRecognizerDelegate, NCListCellDeleg
     private var isEditMode = false
     private var selectocId: [String] = []
     
-    private var sectionDatasource = CCSectionDataSourceMetadata()
+    private var dataSource: NCDataSource?
     
     private var layout = ""
     private var groupBy = ""
@@ -89,7 +89,8 @@ class NCFavorite: UIViewController, UIGestureRecognizerDelegate, NCListCellDeleg
         
         NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: k_notificationCenter_changeTheming), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_deleteFile), object: nil)
-        
+        NotificationCenter.default.addObserver(self, selector: #selector(reloadDataSource), name: NSNotification.Name(rawValue: k_notificationCenter_reloadDataSource), object: nil)
+
         changeTheming()
     }
     
@@ -244,9 +245,8 @@ class NCFavorite: UIViewController, UIGestureRecognizerDelegate, NCListCellDeleg
         
         let photoDataSource: NSMutableArray = []
         
-        for ocId: String in sectionDatasource.allOcId as! [String] {
-            let metadata = sectionDatasource.allRecordsDataSource.object(forKey: ocId) as! tableMetadata
-            if metadata.typeFile == k_metadataTypeFile_image {
+        for metadata in (dataSource?.metadatas ?? [tableMetadata]()) {
+            if metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video {
                 photoDataSource.add(metadata)
             }
         }
@@ -268,7 +268,7 @@ extension NCFavorite: UIViewControllerPreviewingDelegate {
         
         guard let point = collectionView?.convert(location, from: collectionView?.superview) else { return nil }
         guard let indexPath = collectionView?.indexPathForItem(at: point) else { return nil }
-        guard let metadata = NCMainCommon.sharedInstance.getMetadataFromSectionDataSourceIndexPath(indexPath, sectionDataSource: sectionDatasource) else { return nil }
+        guard let metadata = dataSource?.cellForItemAt(indexPath: indexPath) else { return nil }
         guard let viewController = UIStoryboard(name: "CCPeekPop", bundle: nil).instantiateViewController(withIdentifier: "PeekPopImagePreview") as? CCPeekPop else { return nil }
 
         viewController.metadata = metadata
@@ -304,9 +304,7 @@ extension NCFavorite: UICollectionViewDelegate {
 
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
         
-        guard let metadata = NCMainCommon.sharedInstance.getMetadataFromSectionDataSourceIndexPath(indexPath, sectionDataSource: sectionDatasource) else {
-            return
-        }
+        guard let metadata = dataSource?.cellForItemAt(indexPath: indexPath) else { return }
         metadataPush = metadata
         
         if isEditMode {
@@ -355,16 +353,12 @@ extension NCFavorite: UICollectionViewDataSource {
                 header.delegate = self
                 header.backgroundColor = NCBrandColor.sharedInstance.backgroundView
                 header.separator.backgroundColor = NCBrandColor.sharedInstance.separator
-                header.setStatusButton(count: sectionDatasource.allOcId.count)
+                header.setStatusButton(count: dataSource?.metadatas.count ?? 0)
                 header.setTitleSorted(datasourceTitleButton: titleButton)
                 
                 if groupBy == "none" {
                     header.labelSection.isHidden = true
                     header.labelSectionHeightConstraint.constant = 0
-                } else {
-                    header.labelSection.isHidden = false
-                    header.setTitleLabel(sectionDatasource: sectionDatasource, section: indexPath.section)
-                    header.labelSectionHeightConstraint.constant = sectionHeaderHeight
                 }
                 
                 return header
@@ -373,7 +367,7 @@ extension NCFavorite: UICollectionViewDataSource {
                 
                 let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as! NCSectionFooter
                 
-                footer.setTitleLabel(sectionDatasource: sectionDatasource)
+                //footer.setTitleLabel(sectionDatasource: sectionDatasource)
                 
                 return footer
             }
@@ -384,7 +378,7 @@ extension NCFavorite: UICollectionViewDataSource {
                 
                 let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeader", for: indexPath) as! NCSectionHeader
                 
-                header.setTitleLabel(sectionDatasource: sectionDatasource, section: indexPath.section)
+                //header.setTitleLabel(sectionDatasource: sectionDatasource, section: indexPath.section)
                 
                 return header
                 
@@ -392,7 +386,7 @@ extension NCFavorite: UICollectionViewDataSource {
                 
                 let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as! NCSectionFooter
                 
-                footer.setTitleLabel(sectionDatasource: sectionDatasource)
+                //footer.setTitleLabel(sectionDatasource: sectionDatasource)
                 
                 return footer
             }
@@ -400,21 +394,18 @@ extension NCFavorite: UICollectionViewDataSource {
     }
     
     func numberOfSections(in collectionView: UICollectionView) -> Int {
-        let sections = sectionDatasource.sectionArrayRow.allKeys.count
-        return sections
+        return dataSource?.sections ?? 1
     }
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        let key = sectionDatasource.sections.object(at: section)
-        let datasource = sectionDatasource.sectionArrayRow.object(forKey: key) as! [tableMetadata]
-        return datasource.count
+        return dataSource?.numberOfItemsInSection(section: section) ?? 1
     }
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         
         let cell: UICollectionViewCell
         
-        guard let metadata = NCMainCommon.sharedInstance.getMetadataFromSectionDataSourceIndexPath(indexPath, sectionDataSource: sectionDatasource) else {
+        guard let metadata = dataSource?.cellForItemAt(indexPath: indexPath) else {
             return collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
         }
         
@@ -448,7 +439,7 @@ extension NCFavorite: UICollectionViewDelegateFlowLayout {
     }
     
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
-        let sections = sectionDatasource.sectionArrayRow.allKeys.count
+        let sections = dataSource?.sections ?? 1
         if (section == sections - 1) {
             return CGSize(width: collectionView.frame.width, height: footerHeight)
         } else {
@@ -467,18 +458,19 @@ extension NCFavorite {
         var ascending: Bool
         var directoryOnTop: Bool
         
-        sectionDatasource = CCSectionDataSourceMetadata()
         (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: k_layout_view_favorite)
         
         if serverUrl == "" {
             
-            let metadatas = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND favorite == true", appDelegate.account))
-            sectionDatasource = CCSectionMetadata.creataDataSourseSectionMetadata(metadatas, listProgressMetadata: nil, groupBy: groupBy, filterTypeFileImage: false, filterTypeFileVideo: false, filterLivePhoto: true, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, account: appDelegate.account)
+            let metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND favorite == true", appDelegate.account))
+            
+            self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, filterLivePhoto: true)
             
         } else {
             
-            let metadatas = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl))
-            sectionDatasource = CCSectionMetadata.creataDataSourseSectionMetadata(metadatas, listProgressMetadata: nil, groupBy: groupBy, filterTypeFileImage: false, filterTypeFileVideo: false, filterLivePhoto: true, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, account: appDelegate.account)
+            let metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl))
+            
+            self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, filterLivePhoto: true)
         }
         
         collectionView.reloadData()

+ 33 - 13
iOSClient/Main/NCSectionDataSourceMetadata.swift → iOSClient/Main/NCDataSource.swift

@@ -1,5 +1,5 @@
 //
-//  NCSectionDataSourceMetadata.swift
+//  NCDataSource.swift
 //  Nextcloud
 //
 //  Created by Marino Faggiana on 06/09/2020.
@@ -23,19 +23,16 @@
 
 import Foundation
 
-class NCSectionDataSourceMetadata: NSObject {
+@objc class NCDataSource: NSObject {
     
-    override init() {
-        super.init()
-    }
+    @objc var metadatas: [tableMetadata] = []
+    @objc var sections: Int = 1
     
-    @objc func creataDataSourseSectionMetadata(metadatasSource: [tableMetadata], sort: String, ascending: Bool, groupBy: String? = nil, directoryOnTop: Bool, filterLivePhoto: Bool) -> [tableMetadata] {
+    @objc init(metadatasSource: [tableMetadata], sort: String, ascending: Bool, groupBy: String? = nil, directoryOnTop: Bool, filterLivePhoto: Bool) {
         
-        var metadatas: [tableMetadata] = []
         var metadatasFavorite: [tableMetadata] = []
         var numDirectory: Int = 0
         var numDirectoryFavorite:Int = 0
-        
 
         /*
         Metadata order
@@ -63,9 +60,9 @@ class NCSectionDataSourceMetadata: NSObject {
             } else {
                 let range = Range(NSMakeRange(0, obj1.fileNameView.count), in: obj1.fileNameView)
                 if ascending {
-                    return obj1.fileNameView.compare(obj1.fileNameView, options: .caseInsensitive, range: range, locale: .current) == ComparisonResult.orderedAscending
+                    return obj1.fileNameView.compare(obj2.fileNameView, options: .caseInsensitive, range: range, locale: .current) == ComparisonResult.orderedAscending
                 } else {
-                    return obj1.fileNameView.compare(obj1.fileNameView, options: .caseInsensitive, range: range, locale: .current) == ComparisonResult.orderedDescending
+                    return obj1.fileNameView.compare(obj2.fileNameView, options: .caseInsensitive, range: range, locale: .current) == ComparisonResult.orderedDescending
                 }
             }
         }
@@ -83,12 +80,12 @@ class NCSectionDataSourceMetadata: NSObject {
             
             if metadata.directory && directoryOnTop {
                 if metadata.favorite {
+                    metadatas.insert(metadata, at: numDirectoryFavorite)
                     numDirectoryFavorite += 1
                     numDirectory += 1
-                    metadatas.insert(metadata, at: numDirectoryFavorite)
                 } else {
-                    numDirectory += 1
                     metadatas.insert(metadata, at: numDirectory)
+                    numDirectory += 1
                 }
             } else {
                 if metadata.favorite && directoryOnTop {
@@ -107,7 +104,30 @@ class NCSectionDataSourceMetadata: NSObject {
             [sectionDataSource.metadatas insertObjects:metadataFilesFavorite atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(numDirectoryFavorite, metadataFilesFavorite.count)]]; // Add Favorite files at end of favorite folders
         }
         */
+    }
+    
+    @objc func cellForItemAt(indexPath: IndexPath) -> tableMetadata? {
+        
+        let row = indexPath.row
         
-        return metadatas
+        if row > self.metadatas.count - 1 {
+            return nil
+        } else {
+            return metadatas[row]
+        }
+    }
+    
+    @objc func numberOfItemsInSection(section: Int) -> Int {
+        return metadatas.count
+    }
+    
+    @objc func getSize() -> Double {
+        
+        var size: Double = 0
+        for metadata in metadatas {
+            size = size + metadata.size
+        }
+        return size
     }
+    
 }