marinofaggiana 6 vuotta sitten
vanhempi
commit
4a69f99bf3

+ 12 - 0
iOSClient/Database/NCManageDatabase.swift

@@ -1993,6 +1993,18 @@ class NCManageDatabase: NSObject {
         }
     }
     
+    @objc func getTablePhotoLastDate(account: String) -> NSDate? {
+        
+        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 nil
+    }
+    
     @objc func deletePhotos(fileID: String) {
         
         let realm = try! Realm()

+ 1 - 0
iOSClient/Media/NCMedia.storyboard

@@ -31,6 +31,7 @@
                                 <connections>
                                     <outlet property="dataSource" destination="EFX-fO-Oip" id="2On-qP-zuG"/>
                                     <outlet property="delegate" destination="EFX-fO-Oip" id="s3n-CL-8X2"/>
+                                    <outlet property="prefetchDataSource" destination="EFX-fO-Oip" id="KeK-gL-jXR"/>
                                 </connections>
                             </collectionView>
                         </subviews>

+ 16 - 1
iOSClient/Media/NCMedia.swift

@@ -24,7 +24,7 @@
 import Foundation
 import Sheeeeeeeeet
 
-class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UIGestureRecognizerDelegate, NCListCellDelegate, NCSectionHeaderMenuDelegate, DropdownMenuDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate  {
+class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDataSourcePrefetching, UICollectionViewDelegateFlowLayout, UIGestureRecognizerDelegate, NCListCellDelegate, NCSectionHeaderMenuDelegate, DropdownMenuDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate  {
     
     @IBOutlet fileprivate weak var collectionView: UICollectionView!
     
@@ -492,7 +492,22 @@ class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
         
         performSegue(withIdentifier: "segueDetail", sender: self)
     }
+    
+    func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) {
+
+        let section = indexPaths.last?.section ?? 0
 
+        var dateSection = sectionDatasource.sections.object(at: section) as! Date
+        dateSection = Calendar.current.date(byAdding: .day, value: -1, to: dateSection)!
+        print(dateSection)
+        if let lastDate = NCManageDatabase.sharedInstance.getTablePhotoLastDate(account: appDelegate.activeAccount) as Date? {
+            if lastDate > dateSection {
+                let gteDate = Calendar.current.date(byAdding: .day, value: self.stepDays, to: lastDate)!
+                search(lteDate: lastDate, gteDate: gteDate, reiteration: true)
+            }
+        }
+    }
+    
     // MARK: Utility
     
     func selectSearchSections() {