marinofaggiana 4 lat temu
rodzic
commit
2aa32bec3e

+ 1 - 1
iOSClient/Database/NCManageDatabase.swift

@@ -2393,7 +2393,7 @@ class NCManageDatabase: NSObject {
                 realm.refresh()
                 var metadatas = [tableMetadata]()
                 
-                let sortProperties = [SortDescriptor(keyPath: "date", ascending: false), SortDescriptor(keyPath: "fileNameView", ascending: false)]
+                let sortProperties = [SortDescriptor(keyPath: sort, ascending: false), SortDescriptor(keyPath: "fileNameView", ascending: false)]
                 let results = realm.objects(tableMetadata.self).filter(predicate).sorted(by: sortProperties)
                 if (results.count > 0) {
                     

+ 40 - 2
iOSClient/Media/NCMedia.swift

@@ -51,7 +51,6 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
     
     private var lastContentOffsetY: CGFloat = 0
     private var mediaPath = ""
-    private var mediaSort = "date"
     
     struct cacheImages {
         static var cellPlayImage = UIImage()
@@ -257,6 +256,45 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
                 )
             )
             
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_media_by_modified_date_", comment: ""),
+                    icon: CCGraphics.changeThemingColorImage(UIImage(named: "imageno"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                    selected: CCUtility.getMediaSortDate() == "date",
+                    on: true,
+                    action: { menuAction in
+                        CCUtility.setMediaSortDate("date")
+                        self.reloadDataSource()
+                    }
+                )
+            )
+            
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_media_by_created_date_", comment: ""),
+                    icon: CCGraphics.changeThemingColorImage(UIImage(named: "imageno"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                    selected: CCUtility.getMediaSortDate() == "creationDate",
+                    on: true,
+                    action: { menuAction in
+                        CCUtility.setMediaSortDate("creationDate")
+                        self.reloadDataSource()
+                    }
+                )
+            )
+            
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_media_by_upload_date_", comment: ""),
+                    icon: CCGraphics.changeThemingColorImage(UIImage(named: "imageno"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                    selected: CCUtility.getMediaSortDate() == "uploadDate",
+                    on: true,
+                    action: { menuAction in
+                        CCUtility.setMediaSortDate("uploadDate")
+                        self.reloadDataSource()
+                    }
+                )
+            )
+            
         } else {
            
             actions.append(
@@ -601,7 +639,7 @@ extension NCMedia {
             predicate = NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@ AND (typeFile == %@ OR typeFile == %@) AND NOT (session CONTAINS[c] 'upload')", appDelegate.activeAccount, startServerUrl, k_metadataTypeFile_image, k_metadataTypeFile_video)
         }
                 
-        NCManageDatabase.sharedInstance.getMetadatasMedia(predicate: predicate!, sort: mediaSort) { (metadatas) in
+        NCManageDatabase.sharedInstance.getMetadatasMedia(predicate: predicate!, sort: CCUtility.getMediaSortDate()) { (metadatas) in
             DispatchQueue.main.sync {
                 self.metadatas = metadatas
                 self.reloadDataThenPerform {

+ 3 - 0
iOSClient/Utility/CCUtility.h

@@ -171,6 +171,9 @@
 + (BOOL)getLivePhoto;
 + (void)setLivePhoto:(BOOL)set;
 
++ (NSString *)getMediaSortDate;
++ (void)setMediaSortDate:(NSString *)value;
+
 // ===== Varius =====
 
 + (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL;

+ 17 - 0
iOSClient/Utility/CCUtility.m

@@ -694,6 +694,23 @@
     [UICKeyChainStore setString:sSet forKey:@"livePhoto" service:k_serviceShareKeyChain];
 }
 
++ (NSString *)getMediaSortDate
+{
+    NSString *valueString = [UICKeyChainStore stringForKey:@"mediaSortDate" service:k_serviceShareKeyChain];
+    
+    // Default TRUE
+    if (valueString == nil) {
+        [self setMediaSortDate:@"date"];
+        return @"date";
+    }
+    
+    return valueString;
+}
+
++ (void)setMediaSortDate:(NSString *)value
+{
+    [UICKeyChainStore setString:value forKey:@"mediaSortDate" service:k_serviceShareKeyChain];
+}
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Various =====
 #pragma --------------------------------------------------------------------------------------------