marinofaggiana 6 years ago
parent
commit
b6f3a5729d

+ 2 - 2
iOSClient/Database/NCManageDatabase.swift

@@ -1973,7 +1973,7 @@ class NCManageDatabase: NSObject {
         }
     }
     
-    @objc func createTablePhotos(_ metadatas: [tableMetadata], account: String) {
+    @objc func createTablePhotos(_ metadatas: [tableMetadata], lteDate: Date, gteDate: Date,account: String) {
 
         let realm = try! Realm()
         realm.refresh()
@@ -1981,7 +1981,7 @@ class NCManageDatabase: NSObject {
         do {
             try realm.write {
                 // DELETE ALL
-                let results = realm.objects(tablePhotos.self).filter("account = %@", account)
+                let results = realm.objects(tablePhotos.self).filter("account = %@ AND date >= %@ AND date <= %@", account, gteDate, lteDate)
                 realm.delete(results)
                 // INSERT ALL
                 let photos = Array(metadatas.map { tablePhotos.init(value:$0) })

+ 1 - 1
iOSClient/Media/CCMedia.m

@@ -692,7 +692,7 @@
                             // Clear all Hardcoded new foto/video from CCNetworking
                             [self.addMetadatasFromUpload removeAllObjects];
                             
-                            [[NCManageDatabase sharedInstance] createTablePhotos:metadatas account:account];
+                           // [[NCManageDatabase sharedInstance] createTablePhotos:metadatas account:account];
                             
                             dispatch_async(dispatch_get_main_queue(), ^{
                                 [self reloadDatasource:nil action:k_action_NULL];

+ 9 - 10
iOSClient/Media/NCMedia.swift

@@ -51,6 +51,8 @@ class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
     private let footerHeight: CGFloat = 50
     
     private var addWidth: CGFloat = 10
+    
+    private var readLastdays = 30
 
     private let refreshControl = UIRefreshControl()
     
@@ -309,7 +311,7 @@ class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
         actionSheet?.present(in: self, from: sender as! UIButton)
     }
     
-    func search() {
+    func search(_ lteDate: Date, gteDate: Date) {
         
         if appDelegate.activeAccount.count == 0 {
             return
@@ -317,17 +319,11 @@ class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
         
         let startDirectory = NCManageDatabase.sharedInstance.getAccountStartDirectoryMediaTabView(CCUtility.getHomeServerUrlActiveUrl(appDelegate.activeUrl))
 
-        //let date = Calendar.current.date(byAdding: .day, value: -30, to: Date())!
-        
-        let formatter = DateFormatter()
-        formatter.dateFormat = "yyyy/MM/dd HH:mm"
-        let date2 = formatter.date(from: "2019/01/29 00:00")!
-
-        OCNetworking.sharedManager()?.search(withAccount: appDelegate.activeAccount, fileName: "", serverUrl: startDirectory, contentType: ["image/%", "video/%"], lteDateLastModified: Date(), gteDateLastModified: date2, depth: "infinity", completion: { (account, metadatas, message, errorCode) in
+        OCNetworking.sharedManager()?.search(withAccount: appDelegate.activeAccount, fileName: "", serverUrl: startDirectory, contentType: ["image/%", "video/%"], lteDateLastModified: lteDate, gteDateLastModified: gteDate, depth: "infinity", completion: { (account, metadatas, message, errorCode) in
             
             if errorCode == 0 && account == self.appDelegate.activeAccount {
-                NCManageDatabase.sharedInstance.createTablePhotos(metadatas as! [tableMetadata], account: account!)
-                
+               
+                NCManageDatabase.sharedInstance.createTablePhotos(metadatas as! [tableMetadata], lteDate: lteDate, gteDate: gteDate, account: account!)
                 self.loadDatasource()
             }
             
@@ -348,6 +344,9 @@ class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
                 self.sectionDatasource = CCSectionMetadata.creataDataSourseSectionMetadata(metadatas, listProgressMetadata: nil, groupByField: "date", filterFileID: nil, filterTypeFileImage: self.filterTypeFileImage, filterTypeFileVideo: self.filterTypeFileVideo, activeAccount: self.appDelegate.activeAccount)
             } else {
                 self.sectionDatasource = CCSectionDataSourceMetadata()
+                
+                let gteDate = Calendar.current.date(byAdding: .day, value: -self.readLastdays, to: Date())!
+                self.search(Date(), gteDate: gteDate)
             }
         
             DispatchQueue.main.async {