Browse Source

cleaning

Signed-off-by: Marino Faggiana <8616947+marinofaggiana@users.noreply.github.com>
Marino Faggiana 1 year ago
parent
commit
f3ce9284e2

+ 4 - 4
Nextcloud.xcodeproj/project.pbxproj

@@ -384,7 +384,7 @@
 		F769CA1A2966EA3C00039397 /* ComponentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F769CA182966EA3C00039397 /* ComponentView.swift */; };
 		F76B3CCE1EAE01BD00921AC9 /* NCBrand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76B3CCD1EAE01BD00921AC9 /* NCBrand.swift */; };
 		F76B3CCF1EAE01BD00921AC9 /* NCBrand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76B3CCD1EAE01BD00921AC9 /* NCBrand.swift */; };
-		F76B649C2ADFFAED00014640 /* NCMediaManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76B649B2ADFFAED00014640 /* NCMediaManager.swift */; };
+		F76B649C2ADFFAED00014640 /* NCMediaCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76B649B2ADFFAED00014640 /* NCMediaCache.swift */; };
 		F76B649E2ADFFDEC00014640 /* LRUCache in Frameworks */ = {isa = PBXBuildFile; productRef = F76B649D2ADFFDEC00014640 /* LRUCache */; };
 		F76C26A62850D3A500E42BDF /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F7F67BB81A24D27800EE80DA /* Images.xcassets */; };
 		F76D364628A4F8BF00214537 /* NCActivityIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76D364528A4F8BF00214537 /* NCActivityIndicator.swift */; };
@@ -1070,7 +1070,7 @@
 		F769CA162965AB7C00039397 /* NCUploadAssets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCUploadAssets.swift; sourceTree = "<group>"; };
 		F769CA182966EA3C00039397 /* ComponentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComponentView.swift; sourceTree = "<group>"; };
 		F76B3CCD1EAE01BD00921AC9 /* NCBrand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCBrand.swift; sourceTree = "<group>"; };
-		F76B649B2ADFFAED00014640 /* NCMediaManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCMediaManager.swift; sourceTree = "<group>"; };
+		F76B649B2ADFFAED00014640 /* NCMediaCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCMediaCache.swift; sourceTree = "<group>"; };
 		F76D364528A4F8BF00214537 /* NCActivityIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityIndicator.swift; sourceTree = "<group>"; };
 		F76D3CF02428B40E005DFA87 /* NCViewerPDFSearch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCViewerPDFSearch.swift; sourceTree = "<group>"; };
 		F76D3CF22428B94E005DFA87 /* NCViewerPDFSearchCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCViewerPDFSearchCell.xib; sourceTree = "<group>"; };
@@ -2380,7 +2380,7 @@
 				F720B5B72507B9A5008C94E5 /* Cell */,
 				F7501C302212E57400FB1415 /* NCMedia.storyboard */,
 				F7501C312212E57400FB1415 /* NCMedia.swift */,
-				F76B649B2ADFFAED00014640 /* NCMediaManager.swift */,
+				F76B649B2ADFFAED00014640 /* NCMediaCache.swift */,
 				F7F1E54B2492369A00E42386 /* NCMediaCommandView.xib */,
 			);
 			path = Media;
@@ -3664,7 +3664,7 @@
 				F72A47EC2487B06B005AD489 /* NCOperationQueue.swift in Sources */,
 				F769454622E9F1B0000A798A /* NCShareCommon.swift in Sources */,
 				F70753F12542A9A200972D44 /* NCViewerMedia.swift in Sources */,
-				F76B649C2ADFFAED00014640 /* NCMediaManager.swift in Sources */,
+				F76B649C2ADFFAED00014640 /* NCMediaCache.swift in Sources */,
 				F78A18B823CDE2B300F681F3 /* NCViewerRichWorkspace.swift in Sources */,
 				F7A60F86292D215000FCE1F2 /* NCShareAccounts.swift in Sources */,
 				F77910AB25DD53C700CEDB9E /* NCSettingsBundleHelper.swift in Sources */,

+ 2 - 2
iOSClient/AppDelegate.swift

@@ -134,7 +134,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
             NCBrandColor.shared.settingThemingColor(account: activeAccount.account)
 
-            DispatchQueue.global().async { NCMediaManager.shared.createCache(account: self.account) }
+            DispatchQueue.global().async { NCMediaCache.shared.createCache(account: self.account) }
 
         } else {
 
@@ -604,7 +604,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Initialize Auto upload with \(items) uploads")
         }
 
-        DispatchQueue.global().async { NCMediaManager.shared.createCache(account: account) }
+        DispatchQueue.global().async { NCMediaCache.shared.createCache(account: account) }
 
         NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeUser)
     }

+ 58 - 3
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -26,6 +26,7 @@ import Realm
 import NextcloudKit
 import EasyTipView
 import JGProgressHUD
+import Queuer
 
 class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, NCListCellDelegate, NCGridCellDelegate, NCSectionHeaderMenuDelegate, NCSectionFooterDelegate, UIAdaptivePresentationControllerDelegate, NCEmptyDataSetDelegate, UIContextMenuInteractionDelegate, NCAccountRequestDelegate, NCSelectableNavigationView {
 
@@ -1207,8 +1208,8 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
                         (cell as? NCCellProtocol)?.filePreviewImageView?.image = UIImage(named: metadata.iconName)
                     }
                     if metadata.hasPreview && metadata.status == NCGlobal.shared.metadataStatusNormal && (!CCUtility.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag)) {
-                        for case let operation as NCOperationDownloadThumbnail in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId { return }
-                        appDelegate.downloadThumbnailQueue.addOperation(NCOperationDownloadThumbnail(metadata: metadata, cell: (cell as? NCCellProtocol), view: view))
+                        for case let operation as NCCollecionViewCommonDownloadThumbnail in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId { return }
+                        appDelegate.downloadThumbnailQueue.addOperation(NCCollecionViewCommonDownloadThumbnail(metadata: metadata, cell: (cell as? NCCellProtocol), view: view, forItemAt: indexPath))
                     }
                 }
             } else {
@@ -1256,7 +1257,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
     func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
         if !collectionView.indexPathsForVisibleItems.contains(indexPath) {
             guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return }
-            for case let operation as NCOperationDownloadThumbnail in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId {
+            for case let operation as NCCollecionViewCommonDownloadThumbnail in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId {
                 operation.cancel()
             }
         }
@@ -1704,3 +1705,57 @@ extension NCCollectionViewCommon: EasyTipViewDelegate {
         self.tipView?.dismiss()
     }
 }
+
+class NCCollecionViewCommonDownloadThumbnail: ConcurrentOperation {
+
+    var metadata: tableMetadata
+        var cell: NCCellProtocol?
+        var view: UIView?
+        var fileNamePath: String
+        var fileNamePreviewLocalPath: String
+        var fileNameIconLocalPath: String
+
+    init(metadata: tableMetadata, cell: NCCellProtocol?, view: UIView?, forItemAt indexPath: IndexPath) {
+        self.metadata = tableMetadata.init(value: metadata)
+        self.cell = cell
+        self.view = view
+        self.fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId, account: metadata.account)!
+        self.fileNamePreviewLocalPath = CCUtility.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)!
+        self.fileNameIconLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)!
+    }
+
+    override func start() {
+
+        guard !isCancelled else { return self.finish() }
+
+        var etagResource: String?
+        if FileManager.default.fileExists(atPath: fileNameIconLocalPath) && FileManager.default.fileExists(atPath: fileNamePreviewLocalPath) {
+            etagResource = metadata.etagResource
+        }
+
+        NextcloudKit.shared.downloadPreview(
+            fileNamePathOrFileId: fileNamePath,
+            fileNamePreviewLocalPath: fileNamePreviewLocalPath,
+            widthPreview: NCGlobal.shared.sizePreview,
+            heightPreview: NCGlobal.shared.sizePreview,
+            fileNameIconLocalPath: fileNameIconLocalPath,
+            sizeIcon: NCGlobal.shared.sizeIcon,
+            etag: etagResource,
+            options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, _, imageIcon, _, etag, error in
+
+            if error == .success, let image = imageIcon {
+                NCManageDatabase.shared.setMetadataEtagResource(ocId: self.metadata.ocId, etagResource: etag)
+                DispatchQueue.main.async {
+                    if self.metadata.ocId == self.cell?.fileObjectId, let filePreviewImageView = self.cell?.filePreviewImageView {
+                        UIView.transition(with: filePreviewImageView,
+                                          duration: 0.75,
+                                          options: .transitionCrossDissolve,
+                                          animations: { filePreviewImageView.image = image },
+                                          completion: nil)
+                    }
+                }
+            }
+            self.finish()
+        }
+    }
+}

+ 2 - 2
iOSClient/Media/NCMedia.swift

@@ -370,14 +370,14 @@ extension NCMedia: UICollectionViewDataSource {
     func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
         guard let cell = (cell as? NCGridMediaCell), indexPath.row < self.metadatas.count else { return }
         let metadata = self.metadatas[indexPath.row]
-        if let image = NCMediaManager.shared.getImage(ocId: metadata.ocId) {
+        if let image = NCMediaCache.shared.getImage(ocId: metadata.ocId) {
             cell.imageItem.backgroundColor = nil
             cell.imageItem.image = image
         } else if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
             if let image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
                 cell.imageItem.backgroundColor = nil
                 cell.imageItem.image = image
-                NCMediaManager.shared.setImage(ocId: metadata.ocId, image: image)
+                NCMediaCache.shared.setImage(ocId: metadata.ocId, image: image)
             }
         } else {
             if metadata.hasPreview && metadata.status == NCGlobal.shared.metadataStatusNormal && (!CCUtility.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag)) {

+ 4 - 4
iOSClient/Media/NCMediaManager.swift → iOSClient/Media/NCMediaCache.swift

@@ -1,5 +1,5 @@
 //
-//  NCMediaManager.swift
+//  NCMediaCache.swift
 //  Nextcloud
 //
 //  Created by Milen on 10.10.23.
@@ -10,10 +10,10 @@ import UIKit
 import LRUCache
 import NextcloudKit
 
-@objc class NCMediaManager: NSObject {
+@objc class NCMediaCache: NSObject {
 
-    @objc public static let shared: NCMediaManager = {
-        let instance = NCMediaManager()
+    @objc public static let shared: NCMediaCache = {
+        let instance = NCMediaCache()
         return instance
     }()
 

+ 0 - 2
iOSClient/NCGlobal.swift

@@ -379,8 +379,6 @@ class NCGlobal: NSObject {
     let notificationCenterMenuSearchTextPDF                     = "menuSearchTextPDF"
     let notificationCenterMenuGotToPageInPDF                    = "menuGotToPageInPDF"
 
-    let notificationCenterDownloadedThumbnail                   = "DownloadedThumbnail"             // userInfo: ocId
-
     let notificationCenterOpenMediaDetail                       = "openMediaDetail"                 // userInfo: ocId
 
     let notificationCenterDismissScanDocument                   = "dismissScanDocument"

+ 0 - 2
iOSClient/Networking/NCOperationQueue.swift

@@ -172,9 +172,7 @@ class NCOperationDownloadThumbnail: ConcurrentOperation {
                             (self.view as? UITableView)?.reloadData()
                         }
                     }
-                    NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadedThumbnail, userInfo: ["ocId": self.metadata.ocId])
                 }
-                NCMediaManager.shared.setImage(ocId: self.metadata.ocId, image: image)
             }
             self.finish()
         }

+ 2 - 2
iOSClient/Settings/CCAdvanced.m

@@ -162,7 +162,7 @@
                 [[[NextcloudKit shared] nkCommonInstance] writeLog:[NSString stringWithFormat:@"[INFO] Clear log with level %lu %@", (unsigned long)logLevel, versionNextcloudiOS]];
             }
 
-            [[NCMediaManager shared] createCacheWithAccount:appDelegate.account];
+            [[NCMediaCache shared] createCacheWithAccount:appDelegate.account];
         };
         [section addFormRow:row];
         
@@ -388,7 +388,7 @@
 
         [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
 
-        [[NCMediaManager shared] clearCache];
+        [[NCMediaCache shared] clearCache];
 
         [[NCActivityIndicator shared] stop];
         [self calculateSize];