marinofaggiana 4 years ago
parent
commit
6f398ddd20

+ 1 - 1
iOSClient/Activity/NCActivity.swift

@@ -393,7 +393,7 @@ extension activityTableViewCell: UICollectionViewDelegate {
             
             let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(activitySubjectRich.id, fileNameView: activitySubjectRich.name)!
             
-            NCUtility.sharedInstance.startActivityIndicator(view: (appDelegate.window.rootViewController?.view)!, bottom: 0)
+            NCUtility.sharedInstance.startActivityIndicator(view: (appDelegate.window.rootViewController?.view)!)
             
             NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, requestHandler: { (_) in
                 

+ 2 - 2
iOSClient/Main/NCDetailViewController.swift

@@ -492,7 +492,7 @@ class NCDetailViewController: UIViewController {
                 let editor = NCUtility.sharedInstance.isDirectEditing(metadata)!
                 if editor == k_editor_text || editor == k_editor_onlyoffice {
                     
-                    NCUtility.sharedInstance.startActivityIndicator(view: backgroundView, bottom: 0)
+                    NCUtility.sharedInstance.startActivityIndicator(view: backgroundView)
 
                     if metadata.url == "" {
                         
@@ -541,7 +541,7 @@ class NCDetailViewController: UIViewController {
             // RichDocument: Collabora
             if NCUtility.sharedInstance.isRichDocument(metadata) &&  NCCommunication.shared.isNetworkReachable() {
                 
-                NCUtility.sharedInstance.startActivityIndicator(view: backgroundView, bottom: 0)
+                NCUtility.sharedInstance.startActivityIndicator(view: backgroundView)
                 
                 if metadata.url == "" {
                     

+ 32 - 21
iOSClient/Media/NCMedia.swift

@@ -59,8 +59,9 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
     
     private var isDistantPast = false
 
-    private let refreshControl = UIRefreshControl()
-    private var loadingSearch = false
+    private var oldInProgress = false
+    private var newInProgress = false
+
     
     struct cacheImages {
         static var cellPlayImage = UIImage()
@@ -97,9 +98,6 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
         gridLayout.sectionHeadersPinToVisibleBounds = true
 
         collectionView.collectionViewLayout = gridLayout
-
-        // Add Refresh Control
-        collectionView.refreshControl = refreshControl
         
         // empty Data Source
         collectionView.emptyDataSetDelegate = self
@@ -184,11 +182,6 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
         
-        // Configure Refresh Control
-        refreshControl.tintColor = .lightGray
-        refreshControl.backgroundColor = NCBrandColor.sharedInstance.backgroundView
-        refreshControl.addTarget(self, action: #selector(searchNewPhotoVideo), for: .valueChanged)
-        
         // get auto upload folder
         autoUploadFileName = NCManageDatabase.sharedInstance.getAccountAutoUploadFileName()
         autoUploadDirectory = NCManageDatabase.sharedInstance.getAccountAutoUploadDirectory(appDelegate.activeUrl)
@@ -217,9 +210,6 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
     @objc func changeTheming() {
         appDelegate.changeTheming(self, tableView: nil, collectionView: collectionView, form: false)
         
-        refreshControl.tintColor = .lightGray
-        refreshControl.backgroundColor = NCBrandColor.sharedInstance.backgroundView
-        
         cacheImages.cellPlayImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "play"), width: 100, height: 100, color: .white)
         cacheImages.cellFavouriteImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 100, height: 100, color: NCBrandColor.sharedInstance.yellowFavorite)
     }
@@ -294,7 +284,7 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
         
         var text = "\n" + NSLocalizedString("_tutorial_photo_view_", comment: "")
 
-        if loadingSearch {
+        if oldInProgress || newInProgress {
             text = "\n" + NSLocalizedString("_search_in_progress_", comment: "")
         }
         
@@ -639,6 +629,9 @@ extension NCMedia {
     
     @objc func searchNewPhotoVideo() {
         
+        if newInProgress { return }
+        else { newInProgress = true }
+        
         let tableAccount = NCManageDatabase.sharedInstance.getAccountActive()
         
         //let elementDate = "nc:upload_time/"
@@ -651,20 +644,26 @@ extension NCMedia {
         if let date = tableAccount?.dateUpdateMedia {
             gteDate = date as Date
         }
-        
+                
         NCCommunication.shared.searchMedia(lteDate: lteDate, gteDate: gteDate, elementDate: "d:getlastmodified/" ,showHiddenFiles: CCUtility.getShowHiddenFiles(), user: appDelegate.activeUser) { (account, files, errorCode, errorDescription) in
+            
+            self.newInProgress = false
+
             if errorCode == 0 && files != nil && files!.count > 0 {
                 NCManageDatabase.sharedInstance.addMetadatas(files: files, account: self.appDelegate.activeAccount)
                 NCManageDatabase.sharedInstance.setAccountDateLteMedia(date: files?.last?.date)
                 NCManageDatabase.sharedInstance.setAccountDateUpdateMedia()
             }
-            self.refreshControl.endRefreshing()
+            
             self.reloadDataSource()
         }
     }
     
     private func searchOldPhotoVideo(gteDate: Date? = nil) {
         
+        if oldInProgress { return }
+        else { oldInProgress = true }
+        
         var lteDate = Date()
         let tableAccount = NCManageDatabase.sharedInstance.getAccountActive()
         if let date = tableAccount?.dateLteMedia {
@@ -672,30 +671,42 @@ extension NCMedia {
         }
 
         let height = self.tabBarController?.tabBar.frame.size.height ?? 0
-        NCUtility.sharedInstance.startActivityIndicator(view: self.view, bottom: height + 50)
-        
         
         var gteDate = gteDate
         if gteDate == nil {
             gteDate = Calendar.current.date(byAdding: .day, value: -30, to: lteDate)
         }
 
+        NCUtility.sharedInstance.startActivityIndicator(view: self.view, bottom: height + 50)
+
         NCCommunication.shared.searchMedia(lteDate: lteDate, gteDate: gteDate!, elementDate: "d:getlastmodified/" ,showHiddenFiles: CCUtility.getShowHiddenFiles(), user: appDelegate.activeUser) { (account, files, errorCode, errorDescription) in
+            
+            self.oldInProgress = false
+            NCUtility.sharedInstance.stopActivityIndicator()
+            
             if errorCode == 0 {
                 if files != nil && files!.count > 0 {
                     NCManageDatabase.sharedInstance.addMetadatas(files: files, account: self.appDelegate.activeAccount)
-                    NCManageDatabase.sharedInstance.setAccountDateLteMedia(date: files?.last?.date)
-                    NCManageDatabase.sharedInstance.setAccountDateUpdateMedia()
+                    
+                    var lastDate = files?.last?.date
+                    if lastDate != nil && lastDate == tableAccount?.dateLteMedia {
+                        lastDate = Calendar.current.date(byAdding: .second, value: -1, to: lastDate! as Date) as NSDate?
+                    }
+                    
+                    NCManageDatabase.sharedInstance.setAccountDateLteMedia(date: lastDate)
                     self.reloadDataSource()
+                    
                 } else {
+                    
                     if gteDate == Calendar.current.date(byAdding: .day, value: -30, to: lteDate) {
                         self.searchOldPhotoVideo(gteDate: Calendar.current.date(byAdding: .day, value: -90, to: lteDate))
                     } else if gteDate == Calendar.current.date(byAdding: .day, value: -90, to: lteDate) {
+                        self.searchOldPhotoVideo(gteDate: Calendar.current.date(byAdding: .day, value: -180, to: lteDate))
+                    } else {
                         self.searchOldPhotoVideo(gteDate: Date.distantPast)
                     }
                 }
             }
-            NCUtility.sharedInstance.stopActivityIndicator()
         }
     }
     

+ 1 - 1
iOSClient/Notification/NCNotification.swift

@@ -297,7 +297,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, DZNEmpt
     
     func getNetwokingNotification() {
     
-        NCUtility.sharedInstance.startActivityIndicator(view: self.navigationController?.view, bottom: 0)
+        NCUtility.sharedInstance.startActivityIndicator(view: self.navigationController?.view)
 
         NCCommunication.shared.getNotifications() { (account, notifications, errorCode, errorDescription) in
          

+ 2 - 2
iOSClient/RichWorkspace/NCRichWorkspaceCommon.swift

@@ -37,7 +37,7 @@ import NCCommunication
         
         guard let directEditingCreator = NCManageDatabase.sharedInstance.getDirectEditingCreators(predicate: NSPredicate(format: "account == %@ AND editor == 'text'", appDelegate.activeAccount))?.first else { return }
         
-        NCUtility.sharedInstance.startActivityIndicator(view: viewController.view, bottom: 0)
+        NCUtility.sharedInstance.startActivityIndicator(view: viewController.view)
         
         let fileNamePath = CCUtility.returnFileNamePath(fromFileName: k_fileNameRichWorkspace, serverUrl: serverUrl, activeUrl: appDelegate.activeUrl)!
         NCCommunication.shared.NCTextCreateFile(fileNamePath: fileNamePath, editorId: directEditingCreator.editor, creatorId: directEditingCreator.identifier ,templateId: "") { (account, url, errorCode, errorMessage) in
@@ -72,7 +72,7 @@ import NCCommunication
             
             if metadata.url == "" {
                 
-                NCUtility.sharedInstance.startActivityIndicator(view: viewController.view, bottom: 0)
+                NCUtility.sharedInstance.startActivityIndicator(view: viewController.view)
                 
                 let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: appDelegate.activeUrl)!
                 NCCommunication.shared.NCTextOpenFile(fileNamePath: fileNamePath, editor: "text") { (account, url, errorCode, errorMessage) in

+ 6 - 6
iOSClient/Share/NCShareNetworking.swift

@@ -41,7 +41,7 @@ class NCShareNetworking: NSObject {
     }
     
     func readShare() {
-        NCUtility.sharedInstance.startActivityIndicator(view: view, bottom: 0)
+        NCUtility.sharedInstance.startActivityIndicator(view: view)
         OCNetworking.sharedManager()?.readShare(withAccount: metadata.account, path: CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: activeUrl), completion: { (account, items, message, errorCode) in
             NCUtility.sharedInstance.stopActivityIndicator()
             if errorCode == 0 {
@@ -57,7 +57,7 @@ class NCShareNetworking: NSObject {
     }
     
     func share(password: String, permission: Int, hideDownload: Bool) {
-        NCUtility.sharedInstance.startActivityIndicator(view: view, bottom: 0)
+        NCUtility.sharedInstance.startActivityIndicator(view: view)
         let fileName = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: activeUrl)!
         OCNetworking.sharedManager()?.share(withAccount: metadata.account, fileName: fileName, password: password, permission: permission, hideDownload: hideDownload, completion: { (account, message, errorCode) in
             if errorCode == 0 {
@@ -81,7 +81,7 @@ class NCShareNetworking: NSObject {
     }
     
     func unShare(idRemoteShared: Int) {
-        NCUtility.sharedInstance.startActivityIndicator(view: view, bottom: 0)
+        NCUtility.sharedInstance.startActivityIndicator(view: view)
         OCNetworking.sharedManager()?.unshareAccount(metadata.account, shareID: idRemoteShared, completion: { (account, message, errorCode) in
             NCUtility.sharedInstance.stopActivityIndicator()
             if errorCode == 0 {
@@ -94,7 +94,7 @@ class NCShareNetworking: NSObject {
     }
     
     func updateShare(idRemoteShared: Int, password: String?, permission: Int, note: String?, expirationTime: String?, hideDownload: Bool) {
-        NCUtility.sharedInstance.startActivityIndicator(view: view, bottom: 0)
+        NCUtility.sharedInstance.startActivityIndicator(view: view)
         OCNetworking.sharedManager()?.shareUpdateAccount(metadata.account, shareID: idRemoteShared, password: password, note:note, permission: permission, expirationTime: expirationTime, hideDownload: hideDownload, completion: { (account, message, errorCode) in
             NCUtility.sharedInstance.stopActivityIndicator()
             if errorCode == 0 {
@@ -107,7 +107,7 @@ class NCShareNetworking: NSObject {
     }
     
     func getUserAndGroup(searchString: String) {
-        NCUtility.sharedInstance.startActivityIndicator(view: view, bottom: 0)
+        NCUtility.sharedInstance.startActivityIndicator(view: view)
         OCNetworking.sharedManager()?.getUserGroup(withAccount: metadata.account, search: searchString, completion: { (account, items, message, errorCode) in
             NCUtility.sharedInstance.stopActivityIndicator()
             if errorCode == 0 {
@@ -121,7 +121,7 @@ class NCShareNetworking: NSObject {
     }
     
     func shareUserAndGroup(name: String, shareeType: Int, metadata: tableMetadata) {
-        NCUtility.sharedInstance.startActivityIndicator(view: view, bottom: 0)
+        NCUtility.sharedInstance.startActivityIndicator(view: view)
         let fileName = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: activeUrl)!
         var permission: Int = 0
         if metadata.directory { permission = Int(k_max_folder_share_permission) } else { permission = Int(k_max_file_share_permission) }

+ 1 - 1
iOSClient/Utility/NCUtility.swift

@@ -224,7 +224,7 @@ class NCUtility: NSObject {
         }
     }
     
-    @objc func startActivityIndicator(view: UIView?, bottom: CGFloat) {
+    @objc func startActivityIndicator(view: UIView?, bottom: CGFloat = 0) {
     
         guard let view = view else { return }
         

+ 1 - 1
iOSClient/Viewer/NCViewerRichdocument.swift

@@ -142,7 +142,7 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
                         let fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + filename
                     
                         if type == "print" {
-                            NCUtility.sharedInstance.startActivityIndicator(view: self, bottom: 0)
+                            NCUtility.sharedInstance.startActivityIndicator(view: self)
                         }
                         
                         NCCommunication.shared.download(serverUrlFileName: urlString, fileNameLocalPath: fileNameLocalPath, requestHandler: { (_) in