Browse Source

new table tablePhotoLibrary

Marino Faggiana 7 years ago
parent
commit
b8d3071c91
2 changed files with 19 additions and 3 deletions
  1. 2 1
      iOSClient/Database/NCDatabase.swift
  2. 17 2
      iOSClient/Database/NCManageDatabase.swift

+ 2 - 1
iOSClient/Database/NCDatabase.swift

@@ -208,7 +208,8 @@ class tablePhotoLibrary: Object {
     
     dynamic var account = ""
     dynamic var assetLocalIdentifier = ""
-    
+    dynamic var mediaType : Int = 0
+
     override static func primaryKey() -> String {
         return "assetLocalIdentifier"
     }

+ 17 - 2
iOSClient/Database/NCManageDatabase.swift

@@ -1903,7 +1903,7 @@ class NCManageDatabase: NSObject {
         }
     }
     
-    func getPhotoLibrary() -> [tablePhotoLibrary]? {
+    func getPhotoLibrary(image: Bool, video: Bool) -> [tablePhotoLibrary]? {
         
         let tableAccount = self.getAccountActive()
         if tableAccount == nil {
@@ -1912,7 +1912,22 @@ class NCManageDatabase: NSObject {
         
         let realm = try! Realm()
         
-        let results = realm.objects(tablePhotoLibrary.self).filter("account = %@", tableAccount!.account)
+        var predicate = NSPredicate()
+        
+        if (image && video) {
+         
+            predicate = NSPredicate(format: "account = %@ AND (mediaType = 0 || mediaType = 1)", tableAccount!.account)
+            
+        } else if (image) {
+            
+            predicate = NSPredicate(format: "account = %@ AND mediaType = 0", tableAccount!.account)
+
+        } else {
+            
+            predicate = NSPredicate(format: "account = %@ AND mediaType = 1", tableAccount!.account)
+        }
+        
+        let results = realm.objects(tablePhotoLibrary.self).filter(predicate)
         
         return Array(results)
     }