Browse Source

add old Activity

Marino Faggiana 6 years ago
parent
commit
5f8626cd29

+ 35 - 5
iOSClient/Activity/NCActivity.swift

@@ -35,6 +35,8 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
 
     var activities = [tableActivity]()
     var sectionDate = [Date]()
+    
+    var loadingIdActivity: Int = 0
 
     override func viewDidLoad() {
         super.viewDidLoad()
@@ -51,7 +53,7 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
         // Configure Refresh Control
         refreshControl.tintColor = NCBrandColor.sharedInstance.brandText
         refreshControl.backgroundColor = NCBrandColor.sharedInstance.brand
-        refreshControl.addTarget(self, action: #selector(loadActivity), for: .valueChanged)
+        refreshControl.addTarget(self, action: #selector(loadActivityRefreshing), for: .valueChanged)
         
         self.title = NSLocalizedString("_activity_", comment: "")
     }
@@ -154,11 +156,25 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
     }
     
     func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) {
+        
         print("prefetchRowsAt \(indexPaths)")
+        
+        let section = indexPaths.last?.section ?? 0
+        let row = indexPaths.last?.row ?? 0
+        
+        let lastSection = self.sectionDate.count - 1
+        let lastRow = getTableActivitiesFromSection(section).count - 1
+        
+        if section == lastSection && row > lastRow - 1 {
+            let results = getTableActivitiesFromSection(section)
+            let activity = results[lastRow]
+            
+            loadActivity(idActivity: activity.idActivity)
+        }
     }
     
     func tableView(_ tableView: UITableView, cancelPrefetchingForRowsAt indexPaths: [IndexPath]) {
-        print("cancelPrefetchingForRowsAt \(indexPaths)")
+        //print("cancelPrefetchingForRowsAt \(indexPaths)")
     }
     
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
@@ -282,17 +298,31 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
     
     // MARK: NC API
     
-    @objc func loadActivity() {
+    @objc func loadActivityRefreshing() {
+        loadActivity(idActivity: 0)
+    }
+
+    @objc func loadActivity(idActivity: Int) {
+        
+        if loadingIdActivity > 0 {
+            return
+        } else {
+            loadingIdActivity = idActivity
+            NCUtility.sharedInstance.startActivityIndicator(view: self.view, bottom: true)
+        }
         
-        OCNetworking.sharedManager().getActivityWithAccount(appDelegate.activeAccount, since: 0, limit: 100, link: "", completion: { (account, listOfActivity, message, errorCode) in
+        OCNetworking.sharedManager().getActivityWithAccount(appDelegate.activeAccount, since: idActivity, limit: 100, link: "", completion: { (account, listOfActivity, message, errorCode) in
             
             self.refreshControl.endRefreshing()
+            NCUtility.sharedInstance.stopActivityIndicator()
             
             if errorCode == 0 && account == self.appDelegate.activeAccount {
                 NCManageDatabase.sharedInstance.addActivity(listOfActivity as! [OCActivity], account: account!)
                 
                 self.loadDataSource()
             }
+            
+            self.loadingIdActivity = 0
         })
     }
 }
@@ -462,7 +492,7 @@ class activityTableViewCell: UITableViewCell, UICollectionViewDelegate, UICollec
             
             let fileNameLocalPath = CCUtility.getDirectoryProviderStorageFileID(activitySubjectRich.id, fileNameView: activitySubjectRich.name)
             
-            NCUtility.sharedInstance.startActivityIndicator(view: (appDelegate.window.rootViewController?.view)!)
+            NCUtility.sharedInstance.startActivityIndicator(view: (appDelegate.window.rootViewController?.view)!, bottom: false)
             
             let _ = OCNetworking.sharedManager()?.download(withAccount: activityPreview.account, url: url, fileNameLocalPath: fileNameLocalPath, completion: { (account, message, errorCode) in
                 

+ 1 - 1
iOSClient/Main/CCDetail.m

@@ -214,7 +214,7 @@
         // RichDocument
         if ([[NCViewerRichdocument sharedInstance] isRichDocument:self.metadataDetail]) {
             
-            [[NCUtility sharedInstance] startActivityIndicatorWithView:self.view];
+            [[NCUtility sharedInstance] startActivityIndicatorWithView:self.view bottom:false];
             
             if ([self.metadataDetail.url isEqualToString:@""]) {
                 [[OCNetworking sharedManager] createLinkRichdocumentsWithAccount:appDelegate.activeAccount fileID:self.metadataDetail.fileID completion:^(NSString *account, NSString *link, NSString *message, NSInteger errorCode) {

+ 1 - 1
iOSClient/Main/NCMainCommon.swift

@@ -176,7 +176,7 @@ class NCMainCommon: NSObject, PhotoEditorDelegate {
         // Delete k_metadataStatusWaitUpload OR k_metadataStatusUploadError
         NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "status == %d OR status == %d", appDelegate.activeAccount, k_metadataStatusWaitUpload, k_metadataStatusUploadError))
         
-        NCUtility.sharedInstance.startActivityIndicator(view: view)
+        NCUtility.sharedInstance.startActivityIndicator(view: view, bottom: false)
         
         DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
             if let metadatas = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "status != %d AND status != %d", k_metadataStatusNormal, k_metadataStatusHide), sorted: "fileName", ascending: true)  {

+ 10 - 4
iOSClient/Utility/NCUtility.swift

@@ -243,8 +243,8 @@ class NCUtility: NSObject {
         return imageNamePath
     }
     
-    @objc func startActivityIndicator(view: UIView) {
-        
+    @objc func startActivityIndicator(view: UIView, bottom: Bool) {
+    
         activityIndicator.color = NCBrandColor.sharedInstance.brand
         activityIndicator.hidesWhenStopped = true
             
@@ -254,8 +254,14 @@ class NCUtility: NSObject {
             
         let horizontalConstraint = NSLayoutConstraint(item: activityIndicator, attribute: NSLayoutConstraint.Attribute.centerX, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerX, multiplier: 1, constant: 0)
         view.addConstraint(horizontalConstraint)
-            
-        let verticalConstraint = NSLayoutConstraint(item: activityIndicator, attribute: NSLayoutConstraint.Attribute.centerY, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerY, multiplier: 1, constant: 0)
+        
+        
+        var verticalConstant: CGFloat = 0
+        if bottom {
+            verticalConstant = (view.frame.size.height / 2) - 50
+        }
+        
+        let verticalConstraint = NSLayoutConstraint(item: activityIndicator, attribute: NSLayoutConstraint.Attribute.centerY, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerY, multiplier: 1, constant: verticalConstant)
         view.addConstraint(verticalConstraint)
 
         activityIndicator.startAnimating()