marinofaggiana 6 年之前
父節點
當前提交
457a2d2628
共有 2 個文件被更改,包括 11 次插入11 次删除
  1. 2 2
      iOSClient/Database/NCManageDatabase.swift
  2. 9 9
      iOSClient/Media/NCMedia.swift

+ 2 - 2
iOSClient/Database/NCManageDatabase.swift

@@ -1998,13 +1998,13 @@ class NCManageDatabase: NSObject {
         return differentInsert
     }
     
-    @objc func getTablePhotoLastDate(account: String) -> NSDate? {
+    @objc func getTablePhotoLastDate(account: String) -> tablePhotos? {
         
         let realm = try! Realm()
         realm.refresh()
         
         if let entities = realm.objects(tablePhotos.self).filter("account = %@", account).max(by: { $0.date.compare($1.date as Date) == .orderedDescending }) {
-            return entities.date
+            return entities
         }
         
         return nil

+ 9 - 9
iOSClient/Media/NCMedia.swift

@@ -326,8 +326,9 @@ class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
             return
         }
         
-        if loadingSearch {
-            return         } else {
+        if loadingSearch && prefetching == false {
+            return
+        } else {
             loadingSearch = true
         }
         
@@ -522,20 +523,19 @@ class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
     
     func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) {
 
-        let section = indexPaths.last?.section ?? 0
+        var section = indexPaths.last?.section ?? 0
         var gteDate = NSDate.distantPast
 
-        var dateSection = sectionDatasource.sections.object(at: section) as! Date
-        dateSection = Calendar.current.date(byAdding: .day, value: -1, to: dateSection)!
+        let dateSection = sectionDatasource.sections.object(at: section) as! Date
         
-        if let lastDate = NCManageDatabase.sharedInstance.getTablePhotoLastDate(account: appDelegate.activeAccount) as Date? {
-            if lastDate > dateSection && fetchingDistantPast == false {
+        if let result = NCManageDatabase.sharedInstance.getTablePhotoLastDate(account: appDelegate.activeAccount)  {
+            if result.date as Date >= dateSection && fetchingDistantPast == false {
                 if fetchingInsert == 0 {
                     fetchingDistantPast = true
                 } else {
-                    gteDate = Calendar.current.date(byAdding: .day, value: self.stepDays, to: lastDate)!
+                    gteDate = Calendar.current.date(byAdding: .day, value: self.stepDays, to: result.date as Date)!
                 }
-                search(lteDate: lastDate, gteDate: gteDate, reiteration: true, activityIndicator: true, prefetching: true)
+                search(lteDate: result.date as Date, gteDate: gteDate, reiteration: true, activityIndicator: true, prefetching: true)
             }
         }
     }