Browse Source

Normalized

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 1 year ago
parent
commit
fbedc57dc5

+ 0 - 4
iOSClient/AppDelegate.swift

@@ -47,11 +47,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     @objc var activeViewController: UIViewController?
     var mainTabBar: NCMainTabBar?
     var activeMetadata: tableMetadata?
-
     let listFilesVC = ThreadSafeDictionary<String, NCFiles>()
-    let listFavoriteVC = ThreadSafeDictionary<String, NCFavorite>()
-    let listOfflineVC = ThreadSafeDictionary<String, NCOffline>()
-    let listGroupfoldersVC = ThreadSafeDictionary<String, NCGroupfolders>()
 
     var disableSharesView: Bool = false
     var documentPickerViewController: NCDocumentPickerViewController?

+ 8 - 27
iOSClient/Favorites/NCFavorite.swift

@@ -35,7 +35,7 @@ class NCFavorite: NCCollectionViewCommon {
         layoutKey = NCGlobal.shared.layoutViewFavorite
         enableSearchBar = false
         headerMenuButtonsView = true
-        headerRichWorkspaceDisable = false
+        headerRichWorkspaceDisable = true
         emptyImage = UIImage(named: "star.fill")?.image(color: NCBrandColor.shared.yellowFavorite, size: UIScreen.main.bounds.width)
         emptyTitle = "_favorite_no_files_"
         emptyDescription = "_tutorial_favorite_view_"
@@ -91,36 +91,17 @@ class NCFavorite: NCCollectionViewCommon {
         isReloadDataSourceNetworkInProgress = true
         collectionView?.reloadData()
 
-        if serverUrl.isEmpty {
+        NextcloudKit.shared.listingFavorites(showHiddenFiles: CCUtility.getShowHiddenFiles(),
+                                             options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in
 
-            NextcloudKit.shared.listingFavorites(showHiddenFiles: CCUtility.getShowHiddenFiles(),
-                                                 options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in
-
-                self.isReloadDataSourceNetworkInProgress = false
-                if error == .success {
-                    NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: false) { _, _, metadatas in
-                        NCManageDatabase.shared.updateMetadatasFavorite(account: account, metadatas: metadatas)
-                        self.reloadDataSource()
-                    }
-                } else {
-                    NCContentPresenter.shared.showError(error: error)
+            self.isReloadDataSourceNetworkInProgress = false
+            if error == .success {
+                NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: false) { _, _, metadatas in
+                    NCManageDatabase.shared.updateMetadatasFavorite(account: account, metadatas: metadatas)
                     self.reloadDataSource()
                 }
             }
-
-        } else {
-
-            networkReadFolder(isForced: isForced) { tableDirectory, metadatas, _, _, error in
-
-                self.isReloadDataSourceNetworkInProgress = false
-                if error == .success, let metadatas {
-                    for metadata in metadatas where (!metadata.directory && NCManageDatabase.shared.isDownloadMetadata(metadata, download: false)) {
-                        NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile)
-                    }
-                }
-                self.richWorkspaceText = tableDirectory?.richWorkspace
-                self.reloadDataSource()
-            }
+            self.reloadDataSource()
         }
     }
 }

+ 18 - 29
iOSClient/Groupfolders/NCGroupfolders.swift

@@ -91,40 +91,29 @@ class NCGroupfolders: NCCollectionViewCommon {
         isReloadDataSourceNetworkInProgress = true
         collectionView?.reloadData()
 
-        if serverUrl.isEmpty {
-
-            let homeServerUrl = NCUtilityFileSystem.shared.getHomeServer(urlBase: self.appDelegate.urlBase, userId: self.appDelegate.userId)
-
-            NextcloudKit.shared.getGroupfolders(options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, results, _, error in
-
-                if error == .success, let groupfolders = results {
-
-                    NCManageDatabase.shared.addGroupfolders(account: account, groupfolders: groupfolders)
-
-                    Task {
-                        for groupfolder in groupfolders {
-                            let mountPoint = groupfolder.mountPoint.hasPrefix("/") ? groupfolder.mountPoint : "/" + groupfolder.mountPoint
-                            let serverUrlFileName = homeServerUrl + mountPoint
-                            if NCManageDatabase.shared.getMetadataFromDirectory(account: self.appDelegate.account, serverUrl: serverUrlFileName) == nil {
-                                let results = await NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", showHiddenFiles: CCUtility.getShowHiddenFiles())
-                                if results.error == .success, let file = results.files.first {
-                                    let isDirectoryE2EE = NCUtility.shared.isDirectoryE2EE(file: file)
-                                    let metadata = NCManageDatabase.shared.convertFileToMetadata(file, isDirectoryE2EE: isDirectoryE2EE)
-                                    NCManageDatabase.shared.addMetadata(metadata)
-                                    NCManageDatabase.shared.addDirectory(encrypted: isDirectoryE2EE, favorite: metadata.favorite, ocId: metadata.ocId, fileId: metadata.fileId, etag: nil, permissions: metadata.permissions, serverUrl: serverUrlFileName, account: metadata.account)
-                                }
+        let homeServerUrl = NCUtilityFileSystem.shared.getHomeServer(urlBase: self.appDelegate.urlBase, userId: self.appDelegate.userId)
+
+        NextcloudKit.shared.getGroupfolders(options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, results, _, error in
+
+            if error == .success, let groupfolders = results {
+                NCManageDatabase.shared.addGroupfolders(account: account, groupfolders: groupfolders)
+                Task {
+                    for groupfolder in groupfolders {
+                        let mountPoint = groupfolder.mountPoint.hasPrefix("/") ? groupfolder.mountPoint : "/" + groupfolder.mountPoint
+                        let serverUrlFileName = homeServerUrl + mountPoint
+                        if NCManageDatabase.shared.getMetadataFromDirectory(account: self.appDelegate.account, serverUrl: serverUrlFileName) == nil {
+                            let results = await NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", showHiddenFiles: CCUtility.getShowHiddenFiles())
+                            if results.error == .success, let file = results.files.first {
+                                let isDirectoryE2EE = NCUtility.shared.isDirectoryE2EE(file: file)
+                                let metadata = NCManageDatabase.shared.convertFileToMetadata(file, isDirectoryE2EE: isDirectoryE2EE)
+                                NCManageDatabase.shared.addMetadata(metadata)
+                                NCManageDatabase.shared.addDirectory(encrypted: isDirectoryE2EE, favorite: metadata.favorite, ocId: metadata.ocId, fileId: metadata.fileId, etag: nil, permissions: metadata.permissions, serverUrl: serverUrlFileName, account: metadata.account)
                             }
                         }
-                        self.reloadDataSource()
                     }
-                } else if error != .success {
                     self.reloadDataSource()
-                    NCContentPresenter.shared.showError(error: error)
                 }
-            }
-        } else {
-
-            networkReadFolder(isForced: isForced) { _, _, _, _, _ in
+            } else if error != .success {
                 self.reloadDataSource()
             }
         }

+ 10 - 145
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1064,151 +1064,16 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         guard let serverUrlPush = CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName) else { return }
         appDelegate.activeMetadata = metadata
 
-        // FILES
-        if layoutKey == NCGlobal.shared.layoutViewFiles && !pushed {
-
-            if let viewController = appDelegate.listFilesVC[serverUrlPush] {
-
-                if viewController.isViewLoaded {
-                    viewController.titleCurrentFolder = metadata.fileNameView
-                    pushViewController(viewController: viewController)
-                }
-
-            } else {
-
-                if let viewController: NCFiles = UIStoryboard(name: "NCFiles", bundle: nil).instantiateInitialViewController() as? NCFiles {
-
-                    viewController.isRoot = false
-                    viewController.serverUrl = serverUrlPush
-                    viewController.titlePreviusFolder = navigationItem.title
-                    viewController.titleCurrentFolder = metadata.fileNameView
-
-                    appDelegate.listFilesVC[serverUrlPush] = viewController
-
-                    pushViewController(viewController: viewController)
-                }
-            }
-        }
-
-        // FAVORITE
-        if layoutKey == NCGlobal.shared.layoutViewFavorite && !pushed {
-
-            if let viewController = appDelegate.listFavoriteVC[serverUrlPush] {
-
-                if viewController.isViewLoaded {
-                    pushViewController(viewController: viewController)
-                }
-
-            } else {
-
-                if let viewController: NCFavorite = UIStoryboard(name: "NCFavorite", bundle: nil).instantiateInitialViewController() as? NCFavorite {
-
-                    viewController.serverUrl = serverUrlPush
-                    viewController.titlePreviusFolder = navigationItem.title
-                    viewController.titleCurrentFolder = metadata.fileNameView
-
-                    appDelegate.listFavoriteVC[serverUrlPush] = viewController
-
-                    pushViewController(viewController: viewController)
-                }
-            }
-        }
-
-        // OFFLINE
-        if layoutKey == NCGlobal.shared.layoutViewOffline && !pushed {
-
-            if let viewController = appDelegate.listOfflineVC[serverUrlPush] {
-
-                if viewController.isViewLoaded {
-                    pushViewController(viewController: viewController)
-                }
-
-            } else {
-
-                if let viewController: NCOffline = UIStoryboard(name: "NCOffline", bundle: nil).instantiateInitialViewController() as? NCOffline {
-
-                    viewController.serverUrl = serverUrlPush
-                    viewController.titlePreviusFolder = navigationItem.title
-                    viewController.titleCurrentFolder = metadata.fileNameView
-
-                    appDelegate.listOfflineVC[serverUrlPush] = viewController
-
-                    pushViewController(viewController: viewController)
-                }
-            }
-        }
-
-        // RECENT ( for push use Files ... he he he )
-        if layoutKey == NCGlobal.shared.layoutViewRecent && !pushed {
-
-            if let viewController = appDelegate.listFilesVC[serverUrlPush] {
-
-                if viewController.isViewLoaded {
-                    pushViewController(viewController: viewController)
-                }
-
-            } else {
-
-                if let viewController: NCFiles = UIStoryboard(name: "NCFiles", bundle: nil).instantiateInitialViewController() as? NCFiles {
-
-                    viewController.isRoot = false
-                    viewController.serverUrl = serverUrlPush
-                    viewController.titlePreviusFolder = navigationItem.title
-                    viewController.titleCurrentFolder = metadata.fileNameView
-
-                    appDelegate.listFilesVC[serverUrlPush] = viewController
-
-                    pushViewController(viewController: viewController)
-                }
-            }
-        }
-
-        // SHARES ( for push use Files ... he he he )
-        if layoutKey == NCGlobal.shared.layoutViewShares && !pushed {
-
-            if let viewController = appDelegate.listFilesVC[serverUrlPush] {
-
-                if viewController.isViewLoaded {
-                    pushViewController(viewController: viewController)
-                }
-
-            } else {
-
-                if let viewController: NCFiles = UIStoryboard(name: "NCFiles", bundle: nil).instantiateInitialViewController() as? NCFiles {
-
-                    viewController.isRoot = false
-                    viewController.serverUrl = serverUrlPush
-                    viewController.titlePreviusFolder = navigationItem.title
-                    viewController.titleCurrentFolder = metadata.fileNameView
-
-                    appDelegate.listFilesVC[serverUrlPush] = viewController
-
-                    pushViewController(viewController: viewController)
-                }
-            }
-        }
-
-        // GROUPFOLDERS
-        if layoutKey == NCGlobal.shared.layoutViewGroupfolders && !pushed {
-
-            if let viewController = appDelegate.listGroupfoldersVC[serverUrlPush] {
-
-                if viewController.isViewLoaded {
-                    pushViewController(viewController: viewController)
-                }
-
-            } else {
-
-                if let viewController: NCGroupfolders = UIStoryboard(name: "NCGroupfolders", bundle: nil).instantiateInitialViewController() as? NCGroupfolders {
-
-                    viewController.serverUrl = serverUrlPush
-                    viewController.titlePreviusFolder = navigationItem.title
-                    viewController.titleCurrentFolder = metadata.fileNameView
-
-                    appDelegate.listGroupfoldersVC[serverUrlPush] = viewController
-
-                    pushViewController(viewController: viewController)
-                }
+        if let viewController = appDelegate.listFilesVC[serverUrlPush], viewController.isViewLoaded {
+            pushViewController(viewController: viewController)
+        } else {
+            if let viewController: NCFiles = UIStoryboard(name: "NCFiles", bundle: nil).instantiateInitialViewController() as? NCFiles {
+                viewController.isRoot = false
+                viewController.serverUrl = serverUrlPush
+                viewController.titlePreviusFolder = navigationItem.title
+                viewController.titleCurrentFolder = metadata.fileNameView
+                appDelegate.listFilesVC[serverUrlPush] = viewController
+                pushViewController(viewController: viewController)
             }
         }
     }

+ 1 - 28
iOSClient/Offline/NCOffline.swift

@@ -97,33 +97,6 @@ class NCOffline: NCCollectionViewCommon {
     override func reloadDataSourceNetwork(isForced: Bool = false) {
         super.reloadDataSourceNetwork(isForced: isForced)
 
-        guard !serverUrl.isEmpty else {
-            self.reloadDataSource()
-            return
-        }
-
-        NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Reload data source network offline forced \(isForced)")
-
-        isReloadDataSourceNetworkInProgress = true
-        collectionView?.reloadData()
-
-        networkReadFolder(isForced: isForced) { tableDirectory, metadatas, metadatasUpdate, metadatasDelete, error in
-            if error == .success, let metadatas = metadatas {
-                for metadata in metadatas where (!metadata.directory && NCManageDatabase.shared.isDownloadMetadata(metadata, download: true)) {
-                    NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile)
-                }
-            }
-
-            DispatchQueue.main.async {
-                self.refreshControl.endRefreshing()
-                self.isReloadDataSourceNetworkInProgress = false
-                self.richWorkspaceText = tableDirectory?.richWorkspace
-                if metadatasUpdate?.count ?? 0 > 0 || metadatasDelete?.count ?? 0 > 0 || isForced {
-                    self.reloadDataSource()
-                } else {
-                    self.collectionView?.reloadData()
-                }
-            }
-        }
+        return self.reloadDataSource()
     }
 }

+ 3 - 11
iOSClient/Recent/NCRecent.swift

@@ -149,14 +149,14 @@ class NCRecent: NCCollectionViewCommon {
         isReloadDataSourceNetworkInProgress = true
         collectionView?.reloadData()
 
-        NextcloudKit.shared.searchBodyRequest(serverUrl: appDelegate.urlBase, 
+        NextcloudKit.shared.searchBodyRequest(serverUrl: appDelegate.urlBase,
                                               requestBody: requestBody,
                                               showHiddenFiles: CCUtility.getShowHiddenFiles(),
                                               options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in
 
+            self.isReloadDataSourceNetworkInProgress = false
             if error == .success {
                 NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: false) { _, metadatasFolder, metadatas in
-
                     // Update sub directories
                     for metadata in metadatasFolder {
                         let serverUrl = metadata.serverUrl + "/" + metadata.fileName
@@ -164,18 +164,10 @@ class NCRecent: NCCollectionViewCommon {
                     }
                     // Add metadatas
                     NCManageDatabase.shared.addMetadatas(metadatas)
-
                     self.reloadDataSource()
                 }
             } else {
-                DispatchQueue.main.async {
-                    self.collectionView?.reloadData()
-                }
-            }
-
-            DispatchQueue.main.async {
-                self.refreshControl.endRefreshing()
-                self.isReloadDataSourceNetworkInProgress = false
+                self.reloadDataSource()
             }
         }
     }

+ 1 - 6
iOSClient/Shares/NCShares.swift

@@ -120,13 +120,8 @@ class NCShares: NCCollectionViewCommon {
                     let home = NCUtilityFileSystem.shared.getHomeServer(urlBase: self.appDelegate.urlBase, userId: self.appDelegate.userId)
                     NCManageDatabase.shared.addShare(account: self.appDelegate.account, home: home, shares: shares)
                 }
-                self.reloadDataSource()
-
-            } else {
-
-                self.collectionView?.reloadData()
-                NCContentPresenter.shared.showError(error: error)
             }
+            self.reloadDataSource()
         }
     }
 }