marinofaggiana 4 years ago
parent
commit
7464629c47
2 changed files with 117 additions and 0 deletions
  1. 4 0
      Nextcloud.xcodeproj/project.pbxproj
  2. 113 0
      iOSClient/Main/NCSectionDataSourceMetadata.swift

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -254,6 +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 */; };
 		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 */; };
@@ -634,6 +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>"; };
 		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>"; };
@@ -814,6 +816,7 @@
 				F73F537E1E929C8500F8678D /* CCMore.swift */,
 				F78F6FAE1CC8CCB700F4EA25 /* CCSection.h */,
 				F78F6FAF1CC8CCB700F4EA25 /* CCSection.m */,
+				F7C1EEA425053A9C00866ACC /* NCSectionDataSourceMetadata.swift */,
 				F78ACD3E21903BA20088454D /* Cell */,
 				F7DFB7E9219C5A0500680748 /* Create cloud */,
 				F78ACD4D219043E70088454D /* Layout */,
@@ -2041,6 +2044,7 @@
 				F710D1F52405770F00A6033D /* NCViewerPDF.swift in Sources */,
 				F7501C332212E57500FB1415 /* NCMedia.swift in Sources */,
 				F70BFC7420E0FA7D00C67599 /* NCUtility.swift in Sources */,
+				F7C1EEA525053A9C00866ACC /* NCSectionDataSourceMetadata.swift in Sources */,
 				F713FF002472764100214AF6 /* UIImage+animatedGIF.m in Sources */,
 				F7B174C822FAC0A8000B7579 /* AppDelegate.m in Sources */,
 				F749C10B23C4A5340027D966 /* NCIntroCollectionViewCell.swift in Sources */,

+ 113 - 0
iOSClient/Main/NCSectionDataSourceMetadata.swift

@@ -0,0 +1,113 @@
+//
+//  NCSectionDataSourceMetadata.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 06/09/2020.
+//  Copyright © 2020 Marino Faggiana. All rights reserved.
+//
+//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+import Foundation
+
+class NCSectionDataSourceMetadata: NSObject {
+    
+    override init() {
+        super.init()
+    }
+    
+    @objc func creataDataSourseSectionMetadata(metadatasSource: [tableMetadata], sort: String, ascending: Bool, groupBy: String? = nil, directoryOnTop: Bool, filterLivePhoto: Bool) -> [tableMetadata] {
+        
+        var metadatas: [tableMetadata] = []
+        var metadatasFavorite: [tableMetadata] = []
+        var numDirectory: Int = 0
+        var numDirectoryFavorite:Int = 0
+        
+
+        /*
+        Metadata order
+        */
+        
+        let metadatasSourceSorted = metadatasSource.sorted { (obj1:tableMetadata, obj2:tableMetadata) -> Bool in
+            if sort == "date" {
+                if ascending {
+                    return obj1.date.compare(obj2.date as Date) == ComparisonResult.orderedAscending
+                } else {
+                    return obj1.date.compare(obj2.date as Date) == ComparisonResult.orderedDescending
+                }
+            } else if sort == "sessionTaskIdentifier" {
+                if ascending {
+                    return obj1.sessionTaskIdentifier < obj2.sessionTaskIdentifier
+                } else {
+                    return obj1.sessionTaskIdentifier > obj2.sessionTaskIdentifier
+                }
+            } else if sort == "size" {
+                if ascending {
+                    return obj1.size < obj2.size
+                } else {
+                    return obj1.size > obj2.size
+                }
+            } 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
+                } else {
+                    return obj1.fileNameView.compare(obj1.fileNameView, options: .caseInsensitive, range: range, locale: .current) == ComparisonResult.orderedDescending
+                }
+            }
+        }
+        
+        /*
+        Initialize datasource
+        */
+        
+        for metadata in metadatasSourceSorted {
+            
+            // skipped livePhoto
+            if metadata.ext == "mov" && metadata.livePhoto {
+                continue
+            }
+            
+            if metadata.directory && directoryOnTop {
+                if metadata.favorite {
+                    numDirectoryFavorite += 1
+                    numDirectory += 1
+                    metadatas.insert(metadata, at: numDirectoryFavorite)
+                } else {
+                    numDirectory += 1
+                    metadatas.insert(metadata, at: numDirectory)
+                }
+            } else {
+                if metadata.favorite && directoryOnTop {
+                    metadatasFavorite.append(metadata)
+                } else {
+                    metadatas.append(metadata)
+                }
+            }
+        }
+        if directoryOnTop && metadatasFavorite.count > 0 {
+            metadatas.insert(contentsOf: metadatasFavorite, at: numDirectory)
+        }
+                
+        /*
+        if (directoryOnTop && metadataFilesFavorite.count > 0) {
+            [sectionDataSource.metadatas insertObjects:metadataFilesFavorite atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(numDirectoryFavorite, metadataFilesFavorite.count)]]; // Add Favorite files at end of favorite folders
+        }
+        */
+        
+        return metadatas
+    }
+}