Browse Source

Refactor & fix NCTrash listing issues

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 years ago
parent
commit
a07d37f4b8

+ 2 - 4
.swiftlint.yml

@@ -11,7 +11,8 @@ empty_count:
 
 line_length:
   # warning: 120
-  warning: 200
+  warning: 250
+  error: 250
 
 type_body_length:
   # error: 350
@@ -117,9 +118,6 @@ excluded:
   - iOSClient/Shares/NCShares.swift
   - iOSClient/Transfers/NCTransferCell.swift
   - iOSClient/Transfers/NCTransfers.swift
-  - iOSClient/Trash/Cell/NCTrashListCell.swift
-  - iOSClient/Trash/NCTrash.swift
-  - iOSClient/Trash/Section/NCTrashSectionHeaderFooter.swift
   - iOSClient/UserStatus/NCUserStatus.swift
   - iOSClient/Utility/NCAskAuthorization.swift
   - iOSClient/Utility/NCContentPresenter.swift

+ 6 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -27,6 +27,8 @@
 		AF22B218277D196700DAB0CC /* NCShareExtension+Files.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF22B216277D196700DAB0CC /* NCShareExtension+Files.swift */; };
 		AF2D7C7C2742556F00ADF566 /* NCShareLinkCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF2D7C7B2742556F00ADF566 /* NCShareLinkCell.swift */; };
 		AF2D7C7E2742559100ADF566 /* NCShareUserCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF2D7C7D2742559100ADF566 /* NCShareUserCell.swift */; };
+		AF3FDCC22796ECC300710F60 /* NCTrash+CollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF3FDCC12796ECC300710F60 /* NCTrash+CollectionView.swift */; };
+		AF3FDCC32796F3FB00710F60 /* NCTrashListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78ACD4821903F850088454D /* NCTrashListCell.swift */; };
 		AF4BF614275629E20081CEEF /* NCManageDatabase+Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF4BF613275629E20081CEEF /* NCManageDatabase+Account.swift */; };
 		AF4BF615275629E20081CEEF /* NCManageDatabase+Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF4BF613275629E20081CEEF /* NCManageDatabase+Account.swift */; };
 		AF4BF616275629E20081CEEF /* NCManageDatabase+Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF4BF613275629E20081CEEF /* NCManageDatabase+Account.swift */; };
@@ -461,6 +463,7 @@
 		AF22B216277D196700DAB0CC /* NCShareExtension+Files.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NCShareExtension+Files.swift"; sourceTree = "<group>"; };
 		AF2D7C7B2742556F00ADF566 /* NCShareLinkCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareLinkCell.swift; sourceTree = "<group>"; };
 		AF2D7C7D2742559100ADF566 /* NCShareUserCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareUserCell.swift; sourceTree = "<group>"; };
+		AF3FDCC12796ECC300710F60 /* NCTrash+CollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCTrash+CollectionView.swift"; sourceTree = "<group>"; };
 		AF4BF613275629E20081CEEF /* NCManageDatabase+Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCManageDatabase+Account.swift"; sourceTree = "<group>"; };
 		AF4BF61827562A4B0081CEEF /* NCManageDatabse+Metadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCManageDatabse+Metadata.swift"; sourceTree = "<group>"; };
 		AF4BF61D27562B3F0081CEEF /* NCManageDatabase+Activity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCManageDatabase+Activity.swift"; sourceTree = "<group>"; };
@@ -1267,6 +1270,7 @@
 				F7632FC32183667400721B71 /* Section */,
 				F78F74332163757000C2ADAD /* NCTrash.storyboard */,
 				F78F74352163781100C2ADAD /* NCTrash.swift */,
+				AF3FDCC12796ECC300710F60 /* NCTrash+CollectionView.swift */,
 			);
 			path = Trash;
 			sourceTree = "<group>";
@@ -2272,6 +2276,7 @@
 				AF4BF61A27562A4B0081CEEF /* NCManageDatabse+Metadata.swift in Sources */,
 				AF4BF615275629E20081CEEF /* NCManageDatabase+Account.swift in Sources */,
 				F798F0E225880608000DAFFD /* UIColor+Extensions.swift in Sources */,
+				AF3FDCC32796F3FB00710F60 /* NCTrashListCell.swift in Sources */,
 				AF817EF2274BC781009ED85B /* NCUserBaseUrl.swift in Sources */,
 				F78295311F962EFA00A572F5 /* NCEndToEndEncryption.m in Sources */,
 				F74AF3A5247FB6AE00AC767B /* NCUtilityFileSystem.swift in Sources */,
@@ -2439,6 +2444,7 @@
 				F79B869B265E19D40085C0E0 /* NSMutableAttributedString+Extensions.swift in Sources */,
 				F7B7504B2397D38F004E13EC /* UIImage+Extensions.swift in Sources */,
 				F7EFC0CD256BF8DD00461AAD /* NCUserStatus.swift in Sources */,
+				AF3FDCC22796ECC300710F60 /* NCTrash+CollectionView.swift in Sources */,
 				F7DFB7F4219C5CA800680748 /* NCCreateFormUploadScanDocument.swift in Sources */,
 				F70D7C3725FFBF82002B9E34 /* NCCollectionViewCommon.swift in Sources */,
 				F7020FCE2233D7F700B7297D /* NCCreateFormUploadVoiceNote.swift in Sources */,

+ 1 - 1
iOSClient/Activity/NCActivityTableViewCell.swift

@@ -111,7 +111,7 @@ extension NCActivityTableViewCell: UICollectionViewDelegate {
             var responder: UIResponder? = collectionView
             while !(responder is UIViewController) {
                 responder = responder?.next
-                if nil == responder {
+                if responder == nil {
                     break
                 }
             }

+ 3 - 2
iOSClient/Main/Collection Common/NCGridCell.swift

@@ -23,7 +23,8 @@
 
 import UIKit
 
-class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProtocol {
+class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProtocol, NCTrashCell {
+    var labelInfo: UILabel?
 
     @IBOutlet weak var imageItem: UIImageView!
     @IBOutlet weak var imageSelect: UIImageView!
@@ -35,7 +36,7 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
     @IBOutlet weak var imageVisualEffect: UIVisualEffectView!
     @IBOutlet weak var progressView: UIProgressView!
 
-    private var objectId = ""
+    internal var objectId = ""
     private var user = ""
 
     weak var delegate: NCGridCellDelegate?

+ 4 - 4
iOSClient/Menu/UIViewController+Menu.swift

@@ -35,7 +35,7 @@ extension UIViewController {
                 url.scheme == "mailto",
                 let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
             else {
-                NCContentPresenter.shared.showGenericError(description: "_cannot_send_mail_error_")
+                NCContentPresenter.shared.showError(description: "_cannot_send_mail_error_")
                 return
             }
             sendEmail(to: components.path)
@@ -50,7 +50,7 @@ extension UIViewController {
 
         default:
             guard let url = action.hyperlinkUrl, UIApplication.shared.canOpenURL(url) else {
-                NCContentPresenter.shared.showGenericError(description: "_open_url_error_")
+                NCContentPresenter.shared.showError(description: "_open_url_error_")
                 return
             }
             UIApplication.shared.open(url, options: [:])
@@ -94,7 +94,7 @@ extension UIViewController {
 
     func sendEmail(to email: String) {
         guard MFMailComposeViewController.canSendMail() else {
-            NCContentPresenter.shared.showGenericError(description: "_cannot_send_mail_error_")
+            NCContentPresenter.shared.showError(description: "_cannot_send_mail_error_")
             return
         }
 
@@ -107,7 +107,7 @@ extension UIViewController {
 
     func presentMenu(with actions: [NCMenuAction]) {
         guard let menuViewController = NCMenu.makeNCMenu(with: actions) else {
-            NCContentPresenter.shared.showGenericError(description: "_internal_generic_error_")
+            NCContentPresenter.shared.showError(description: "_internal_generic_error_")
             return
         }
 

+ 27 - 2
iOSClient/Trash/Cell/NCTrashListCell.swift

@@ -23,14 +23,14 @@
 
 import UIKit
 
-class NCTrashListCell: UICollectionViewCell {
+class NCTrashListCell: UICollectionViewCell, NCTrashCell {
 
     @IBOutlet weak var imageItem: UIImageView!
     @IBOutlet weak var imageItemLeftConstraint: NSLayoutConstraint!
     @IBOutlet weak var imageSelect: UIImageView!
 
     @IBOutlet weak var labelTitle: UILabel!
-    @IBOutlet weak var labelInfo: UILabel!
+    @IBOutlet weak var labelInfo: UILabel?
 
     @IBOutlet weak var imageRestore: UIImageView!
     @IBOutlet weak var imageMore: UIImageView!
@@ -107,3 +107,28 @@ protocol NCTrashListCellDelegate: AnyObject {
     func tapRestoreListItem(with objectId: String, image: UIImage?, sender: Any)
     func tapMoreListItem(with objectId: String, image: UIImage?, sender: Any)
 }
+
+protocol NCTrashCell {
+    var objectId: String { get set }
+    var labelTitle: UILabel! { get set }
+    var labelInfo: UILabel? { get set }
+    var imageItem: UIImageView! { get set }
+
+    func selectMode(_ status: Bool)
+    func selected(_ status: Bool)
+}
+extension NCTrashCell {
+    mutating func setupCellUI(tableTrash: tableTrash, image: UIImage?) {
+        self.objectId = tableTrash.fileId
+        self.labelTitle.text = tableTrash.trashbinFileName
+        self.labelTitle.textColor = NCBrandColor.shared.label
+
+        if tableTrash.directory {
+            self.imageItem.image = NCBrandColor.cacheImages.folder
+            self.labelInfo?.text = CCUtility.dateDiff(tableTrash.date as Date)
+        } else {
+            self.imageItem.image = image
+            self.labelInfo?.text = CCUtility.dateDiff(tableTrash.date as Date) + ", " + CCUtility.transformedSize(tableTrash.size)
+        }
+    }
+}

+ 126 - 0
iOSClient/Trash/NCTrash+CollectionView.swift

@@ -0,0 +1,126 @@
+//
+//  NCTrash+CollectionView.swift
+//  Nextcloud
+//
+//  Created by Henrik Storch on 18.01.22.
+//  Copyright © 2022 Marino Faggiana. All rights reserved.
+//
+
+import Foundation
+
+// MARK: UICollectionViewDelegate
+extension NCTrash {
+
+    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
+
+        let tableTrash = datasource[indexPath.item]
+
+        guard !isEditMode else {
+            if let index = selectOcId.firstIndex(of: tableTrash.fileId) {
+                selectOcId.remove(at: index)
+            } else {
+                selectOcId.append(tableTrash.fileId)
+            }
+            collectionView.reloadItems(at: [indexPath])
+            self.navigationItem.title = NSLocalizedString("_selected_", comment: "") + " : \(selectOcId.count)" + " / \(datasource.count)"
+            return
+        }
+
+        if tableTrash.directory,
+           let ncTrash: NCTrash = UIStoryboard(name: "NCTrash", bundle: nil).instantiateInitialViewController() as? NCTrash {
+            ncTrash.trashPath = tableTrash.filePath + tableTrash.fileName
+            ncTrash.titleCurrentFolder = tableTrash.trashbinFileName
+            self.navigationController?.pushViewController(ncTrash, animated: true)
+        }
+    }
+}
+
+// MARK: UICollectionViewDataSource
+extension NCTrash {
+
+    override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
+
+        if kind == UICollectionView.elementKindSectionHeader {
+
+            guard let trashHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeaderMenu", for: indexPath) as? NCTrashSectionHeaderMenu
+            else { return UICollectionReusableView() }
+
+            if collectionView.collectionViewLayout == gridLayout {
+                trashHeader.buttonSwitch.setImage(UIImage(named: "switchList")?.image(color: NCBrandColor.shared.gray, size: 25), for: .normal)
+            } else {
+                trashHeader.buttonSwitch.setImage(UIImage(named: "switchGrid")?.image(color: NCBrandColor.shared.gray, size: 25), for: .normal)
+            }
+
+            trashHeader.delegate = self
+            trashHeader.backgroundColor = NCBrandColor.shared.systemBackground
+            trashHeader.separator.backgroundColor = NCBrandColor.shared.separator
+            trashHeader.setStatusButton(datasource: datasource)
+            trashHeader.setTitleSorted(datasourceTitleButton: layoutForView?.titleButtonHeader ?? "")
+
+            return trashHeader
+
+        } else {
+            guard let trashFooter = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as? NCTrashSectionFooter
+            else { return UICollectionReusableView() }
+            trashFooter.setTitleLabelFooter(datasource: datasource)
+            return trashFooter
+        }
+    }
+
+    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
+        emptyDataSet?.numberOfItemsInSection(datasource.count, section: section)
+        return datasource.count
+    }
+
+    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
+
+        let tableTrash = datasource[indexPath.item]
+        var image: UIImage?
+
+        if tableTrash.iconName.isEmpty {
+            image = UIImage(named: "file")
+        } else {
+            image = UIImage(named: tableTrash.iconName)
+        }
+
+        if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
+            image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName))
+        } else {
+            if tableTrash.hasPreview && !CCUtility.fileProviderStoragePreviewIconExists(tableTrash.fileId, etag: tableTrash.fileName) {
+                downloadThumbnail(with: tableTrash, indexPath: indexPath)
+            }
+        }
+
+        var cell: NCTrashCell & UICollectionViewCell
+
+        if collectionView.collectionViewLayout == listLayout {
+            guard let listCell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as? NCTrashListCell else { return UICollectionViewCell() }
+            cell = listCell
+        } else {
+            // GRID
+            guard let gridCell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as? NCGridCell else { return UICollectionViewCell() }
+            gridCell.setButtonMore(named: NCGlobal.shared.buttonMoreMore, image: NCBrandColor.cacheImages.buttonMore)
+            cell = gridCell
+        }
+
+        cell.setupCellUI(tableTrash: tableTrash, image: image)
+        cell.selectMode(isEditMode)
+        if isEditMode {
+            cell.selected(selectOcId.contains(tableTrash.fileId))
+        }
+
+        return cell
+    }
+}
+
+// MARK: UICollectionViewDelegateFlowLayout
+extension NCTrash {
+
+    override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
+        return CGSize(width: collectionView.frame.width, height: highHeader)
+    }
+
+    override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
+        return CGSize(width: collectionView.frame.width, height: highHeader)
+    }
+}

+ 44 - 210
iOSClient/Trash/NCTrash.swift

@@ -30,7 +30,7 @@ class NCTrash: NCCollectionViewCommon, NCTrashListCellDelegate, NCTrashSectionHe
     var blinkFileId: String?
 
     var datasource: [tableTrash] = []
-    private let highHeader: CGFloat = 50
+    let highHeader: CGFloat = 50
 
     // MARK: - View Life Cycle
 
@@ -83,7 +83,7 @@ class NCTrash: NCCollectionViewCommon, NCTrashListCellDelegate, NCTrashSectionHe
             collectionView.collectionViewLayout = gridLayout
         }
 
-        if trashPath == "" {
+        if trashPath.isEmpty {
             guard let userId = (appDelegate.userId as NSString).addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlFragmentAllowed) else { return }
             trashPath = appDelegate.urlBase + "/" + NCUtilityFileSystem.shared.getWebDAV(account: appDelegate.account) + "/trashbin/" + userId + "/trash/"
         }
@@ -93,7 +93,6 @@ class NCTrash: NCCollectionViewCommon, NCTrashListCellDelegate, NCTrashSectionHe
 
     override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
-
         loadListingTrash()
     }
 
@@ -112,7 +111,6 @@ class NCTrash: NCCollectionViewCommon, NCTrashListCellDelegate, NCTrashSectionHe
     // MARK: - Empty
 
     override func emptyDataSetView(_ view: NCEmptyView) {
-
         view.emptyImage.image = UIImage(named: "trash")?.image(color: .gray, size: UIScreen.main.bounds.width)
         view.emptyTitle.text = NSLocalizedString("_trash_no_trash_", comment: "")
         view.emptyDescription.text = NSLocalizedString("_trash_no_trash_description_", comment: "")
@@ -146,13 +144,11 @@ class NCTrash: NCCollectionViewCommon, NCTrashListCellDelegate, NCTrashSectionHe
     }
 
     func tapOrderHeaderMenu(sender: Any) {
-
         let sortMenu = NCSortMenu()
         sortMenu.toggleMenu(viewController: self, key: NCGlobal.shared.layoutViewTrash, sortButton: sender as? UIButton, serverUrl: "", hideDirectoryOnTop: true)
     }
 
     func tapMoreHeaderMenu(sender: Any) {
-
         toggleMenuMoreHeader()
     }
 
@@ -160,33 +156,33 @@ class NCTrash: NCCollectionViewCommon, NCTrashListCellDelegate, NCTrashSectionHe
 
         if !isEditMode {
             restoreItem(with: ocId)
-        } else {
-            let buttonPosition: CGPoint = (sender as! UIButton).convert(CGPoint.zero, to: collectionView)
+        } else if let button = sender as? UIView {
+            let buttonPosition = button.convert(CGPoint.zero, to: collectionView)
             let indexPath = collectionView.indexPathForItem(at: buttonPosition)
             collectionView(self.collectionView, didSelectItemAt: indexPath!)
-        }
+        } // else: undefined sender
     }
 
     func tapMoreListItem(with objectId: String, image: UIImage?, sender: Any) {
 
         if !isEditMode {
             toggleMenuMoreList(with: objectId, image: image)
-        } else {
-            let buttonPosition: CGPoint = (sender as! UIButton).convert(CGPoint.zero, to: collectionView)
+        } else if let button = sender as? UIView {
+            let buttonPosition = button.convert(CGPoint.zero, to: collectionView)
             let indexPath = collectionView.indexPathForItem(at: buttonPosition)
             collectionView(self.collectionView, didSelectItemAt: indexPath!)
-        }
+        } // else: undefined sender
     }
 
     override func tapMoreGridItem(with objectId: String, namedButtonMore: String, image: UIImage?, sender: Any) {
 
         if !isEditMode {
             toggleMenuMoreGrid(with: objectId, namedButtonMore: namedButtonMore, image: image)
-        } else {
-            let buttonPosition: CGPoint = (sender as! UIButton).convert(CGPoint.zero, to: collectionView)
+        } else if let button = sender as? UIView {
+            let buttonPosition = button.convert(CGPoint.zero, to: collectionView)
             let indexPath = collectionView.indexPathForItem(at: buttonPosition)
             collectionView(self.collectionView, didSelectItemAt: indexPath!)
-        }
+        } // else: undefined sender
     }
 
     override func longPressGridItem(with objectId: String, gestureRecognizer: UILongPressGestureRecognizer) {
@@ -202,7 +198,7 @@ class NCTrash: NCCollectionViewCommon, NCTrashListCellDelegate, NCTrashSectionHe
     }
 
     @objc func reloadTrashDataSource() { self.reloadDataSource() }
-    
+
     @objc override func reloadDataSource() {
 
         layoutForView = NCUtility.shared.getLayoutForView(key: NCGlobal.shared.layoutViewTrash, serverUrl: "")
@@ -215,23 +211,18 @@ class NCTrash: NCCollectionViewCommon, NCTrashListCellDelegate, NCTrashSectionHe
 
         datasource = tashItems
         collectionView.reloadData()
-
-        if self.blinkFileId != nil {
-            for item in 0...self.datasource.count-1 {
-                if self.datasource[item].fileId.contains(self.blinkFileId!) {
-                    let indexPath = IndexPath(item: item, section: 0)
-                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
-                        UIView.animate(withDuration: 0.3) {
-                            self.collectionView.scrollToItem(at: indexPath, at: .centeredVertically, animated: false)
-                        } completion: { _ in
-                            if let cell = self.collectionView.cellForItem(at: indexPath) {
-                                cell.backgroundColor = .darkGray
-                                UIView.animate(withDuration: 2) {
-                                    cell.backgroundColor = .clear
-                                    self.blinkFileId = nil
-                                }
-                            }
-                        }
+        guard let blinkFileId = blinkFileId else { return }
+        for itemIx in 0..<self.datasource.count where self.datasource[itemIx].fileId.contains(blinkFileId) {
+            let indexPath = IndexPath(item: itemIx, section: 0)
+            DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
+                UIView.animate(withDuration: 0.3) {
+                    self.collectionView.scrollToItem(at: indexPath, at: .centeredVertically, animated: false)
+                } completion: { _ in
+                    guard let cell = self.collectionView.cellForItem(at: indexPath) else { return }
+                    cell.backgroundColor = .darkGray
+                    UIView.animate(withDuration: 2) {
+                        cell.backgroundColor = .clear
+                        self.blinkFileId = nil
                     }
                 }
             }
@@ -239,168 +230,6 @@ class NCTrash: NCCollectionViewCommon, NCTrashListCellDelegate, NCTrashSectionHe
     }
 }
 
-// MARK: - Collection View
-
-extension NCTrash {
-
-    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-
-        let tableTrash = datasource[indexPath.item]
-
-        guard !isEditMode else {
-            if let index = selectOcId.firstIndex(of: tableTrash.fileId) {
-                selectOcId.remove(at: index)
-            } else {
-                selectOcId.append(tableTrash.fileId)
-            }
-            collectionView.reloadItems(at: [indexPath])
-            self.navigationItem.title = NSLocalizedString("_selected_", comment: "") + " : \(selectOcId.count)" + " / \(datasource.count)"
-            return
-        }
-
-        if tableTrash.directory {
-
-            let ncTrash: NCTrash = UIStoryboard(name: "NCTrash", bundle: nil).instantiateInitialViewController() as! NCTrash
-
-            ncTrash.trashPath = tableTrash.filePath + tableTrash.fileName
-            ncTrash.titleCurrentFolder = tableTrash.trashbinFileName
-
-            self.navigationController?.pushViewController(ncTrash, animated: true)
-        }
-    }
-}
-
-extension NCTrash {
-
-    override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
-
-        if kind == UICollectionView.elementKindSectionHeader {
-
-            let trashHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeaderMenu", for: indexPath) as! NCTrashSectionHeaderMenu
-
-            if collectionView.collectionViewLayout == gridLayout {
-                trashHeader.buttonSwitch.setImage(UIImage(named: "switchList")?.image(color: NCBrandColor.shared.gray, size: 25), for: .normal)
-            } else {
-                trashHeader.buttonSwitch.setImage(UIImage(named: "switchGrid")?.image(color: NCBrandColor.shared.gray, size: 25), for: .normal)
-            }
-
-            trashHeader.delegate = self
-            trashHeader.backgroundColor = NCBrandColor.shared.systemBackground
-            trashHeader.separator.backgroundColor = NCBrandColor.shared.separator
-            trashHeader.setStatusButton(datasource: datasource)
-            trashHeader.setTitleSorted(datasourceTitleButton: layoutForView?.titleButtonHeader ?? "")
-
-            return trashHeader
-
-        } else {
-
-            let trashFooter = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as! NCTrashSectionFooter
-
-            trashFooter.setTitleLabelFooter(datasource: datasource)
-
-            return trashFooter
-        }
-    }
-
-    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        emptyDataSet?.numberOfItemsInSection(datasource.count, section: section)
-        return datasource.count
-    }
-
-    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-
-        let tableTrash = datasource[indexPath.item]
-        var image: UIImage?
-
-        if tableTrash.iconName.count > 0 {
-            image = UIImage(named: tableTrash.iconName)
-        } else {
-            image = UIImage(named: "file")
-        }
-
-        if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
-            image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName))
-        } else {
-            if tableTrash.hasPreview && !CCUtility.fileProviderStoragePreviewIconExists(tableTrash.fileId, etag: tableTrash.fileName) {
-                downloadThumbnail(with: tableTrash, indexPath: indexPath)
-            }
-        }
-
-        if collectionView.collectionViewLayout == listLayout {
-
-            // LIST
-            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCTrashListCell
-            cell.delegate = self
-
-            cell.objectId = tableTrash.fileId
-            cell.labelTitle.text = tableTrash.trashbinFileName
-            cell.labelTitle.textColor = NCBrandColor.shared.label
-
-            if tableTrash.directory {
-                cell.imageItem.image = NCBrandColor.cacheImages.folder
-                cell.labelInfo.text = CCUtility.dateDiff(tableTrash.date as Date)
-            } else {
-                cell.imageItem.image = image
-                cell.labelInfo.text = CCUtility.dateDiff(tableTrash.date as Date) + ", " + CCUtility.transformedSize(tableTrash.size)
-            }
-
-            if isEditMode {
-                cell.selectMode(true)
-                if selectOcId.contains(tableTrash.fileId) {
-                    cell.selected(true)
-                } else {
-                    cell.selected(false)
-                }
-            } else {
-                cell.selectMode(false)
-            }
-
-            return cell
-
-        } else {
-
-            // GRID
-            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
-            cell.delegate = self
-
-            cell.fileObjectId = tableTrash.fileId
-            cell.labelTitle.text = tableTrash.trashbinFileName
-            cell.labelTitle.textColor = NCBrandColor.shared.label
-            cell.setButtonMore(named: NCGlobal.shared.buttonMoreMore, image: NCBrandColor.cacheImages.buttonMore)
-
-            if tableTrash.directory {
-                cell.imageItem.image = NCBrandColor.cacheImages.folder
-            } else {
-                cell.imageItem.image = image
-            }
-
-            if isEditMode {
-                cell.imageSelect.isHidden = false
-                if selectOcId.contains(tableTrash.fileId) {
-                    cell.selected(true)
-                } else {
-                    cell.selected(false)
-                }
-            } else {
-                cell.imageSelect.isHidden = true
-                cell.backgroundView = nil
-            }
-            return cell
-        }
-    }
-}
-
-extension NCTrash {
-
-    override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
-        return CGSize(width: collectionView.frame.width, height: highHeader)
-    }
-
-    override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
-        return CGSize(width: collectionView.frame.width, height: highHeader)
-    }
-}
-
 // MARK: - NC API & Algorithm
 
 extension NCTrash {
@@ -413,7 +242,7 @@ extension NCTrash {
                 NCManageDatabase.shared.deleteTrash(filePath: self.trashPath, account: self.appDelegate.account)
                 NCManageDatabase.shared.addTrash(account: account, items: items)
             } else if errorCode != 0 {
-                NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                NCContentPresenter.shared.showError(description: errorDescription, errorCode: errorCode)
             } else {
                 print("[LOG] It has been changed user during networking process, error.")
             }
@@ -439,7 +268,7 @@ extension NCTrash {
                 NCManageDatabase.shared.deleteTrash(fileId: fileId, account: account)
                 self.reloadDataSource()
             } else if errorCode != 0 {
-                NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                NCContentPresenter.shared.showError(description: errorDescription, errorCode: errorCode)
             } else {
                 print("[LOG] It has been changed user during networking process, error.")
             }
@@ -454,7 +283,7 @@ extension NCTrash {
             if errorCode == 0 && account == self.appDelegate.account {
                 NCManageDatabase.shared.deleteTrash(fileId: nil, account: self.appDelegate.account)
             } else if errorCode != 0 {
-                NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                NCContentPresenter.shared.showError(description: errorDescription, errorCode: errorCode)
             } else {
                 print("[LOG] It has been changed user during networking process, error.")
             }
@@ -475,7 +304,7 @@ extension NCTrash {
                 NCManageDatabase.shared.deleteTrash(fileId: fileId, account: account)
                 self.reloadDataSource()
             } else if errorCode != 0 {
-                NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                NCContentPresenter.shared.showError(description: errorDescription, errorCode: errorCode)
             } else {
                 print("[LOG] It has been changed user during networking process, error.")
             }
@@ -487,17 +316,22 @@ extension NCTrash {
         let fileNamePreviewLocalPath = CCUtility.getDirectoryProviderStoragePreviewOcId(tableTrash.fileId, etag: tableTrash.fileName)!
         let fileNameIconLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)!
 
-        NCCommunication.shared.downloadPreview(fileNamePathOrFileId: tableTrash.fileId, fileNamePreviewLocalPath: fileNamePreviewLocalPath, widthPreview: NCGlobal.shared.sizePreview, heightPreview: NCGlobal.shared.sizePreview, fileNameIconLocalPath: fileNameIconLocalPath, sizeIcon: NCGlobal.shared.sizeIcon, etag: nil, endpointTrashbin: true) { account, _, imageIcon, _, _, errorCode, _ in
-
-            if errorCode == 0 && imageIcon != nil && account == self.appDelegate.account {
-                if let cell = self.collectionView.cellForItem(at: indexPath) {
-                    if cell is NCTrashListCell {
-                        (cell as! NCTrashListCell).imageItem.image = imageIcon
-                    } else if cell is NCGridCell {
-                        (cell as! NCGridCell).imageItem.image = imageIcon
-                    }
-                }
+        NCCommunication.shared.downloadPreview(
+            fileNamePathOrFileId: tableTrash.fileId,
+            fileNamePreviewLocalPath: fileNamePreviewLocalPath,
+            widthPreview: NCGlobal.shared.sizePreview,
+            heightPreview: NCGlobal.shared.sizePreview,
+            fileNameIconLocalPath: fileNameIconLocalPath,
+            sizeIcon: NCGlobal.shared.sizeIcon,
+            etag: nil,
+            endpointTrashbin: true) { account, _, imageIcon, _, _, errorCode, _ in
+                guard errorCode == 0, let imageIcon = imageIcon, account == self.appDelegate.account,
+                      let cell = self.collectionView.cellForItem(at: indexPath) else { return }
+                if let cell = cell as? NCTrashListCell {
+                    cell.imageItem.image = imageIcon
+                } else if let cell = cell as? NCGridCell {
+                    cell.imageItem.image = imageIcon
+                } // else: undefined cell
             }
-        }
     }
 }

+ 3 - 3
iOSClient/Trash/Section/NCTrashSectionHeaderFooter.swift

@@ -61,7 +61,7 @@ class NCTrashSectionHeaderMenu: UICollectionReusableView {
 
     func setStatusButton(datasource: [tableTrash]) {
 
-        if datasource.count == 0 {
+        if datasource.isEmpty {
             buttonSwitch.isEnabled = false
             buttonOrder.isEnabled = false
             buttonMore.isEnabled = false
@@ -128,9 +128,9 @@ class NCTrashSectionFooter: UICollectionReusableView {
             filesText = "1 " + NSLocalizedString("_file_", comment: "") + " " + CCUtility.transformedSize(size)
         }
 
-        if foldersText == "" {
+        if foldersText.isEmpty {
             labelFooter.text = filesText
-        } else if filesText == "" {
+        } else if filesText.isEmpty {
             labelFooter.text = foldersText
         } else {
             labelFooter.text = foldersText + ", " + filesText

+ 2 - 2
iOSClient/Utility/NCContentPresenter.swift

@@ -62,12 +62,12 @@ class NCContentPresenter: NSObject {
 
     // MARK: - Message
 
-    @objc func showGenericError(description: String) {
+    @objc func showError(description: String, errorCode: Int = NCGlobal.shared.errorGeneric) {
         messageNotification(
             "_error_", description: description,
             delay: NCGlobal.shared.dismissAfterSecond,
             type: .error,
-            errorCode: NCGlobal.shared.errorGeneric)
+            errorCode: errorCode)
     }
 
     @objc func messageNotification(_ title: String, description: String?, delay: TimeInterval, type: messageType, errorCode: Int) {