Browse Source

Fix NCTrash select issues

- navigationTitle
- reset edit mode after action
- fix selected cell UI

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 năm trước cách đây
mục cha
commit
dda4081546

+ 6 - 6
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -937,6 +937,12 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         }
     }
 
+    func collectionViewSelectAll() {
+        selectOcId = dataSource.metadatas.map({ $0.ocId })
+        navigationItem.title = NSLocalizedString("_selected_", comment: "") + " : \(selectOcId.count)" + " / \(dataSource.metadatas.count)"
+        collectionView.reloadData()
+    }
+
     // MARK: - DataSource + NC Endpoint
 
     @objc func reloadDataSource() {
@@ -1245,12 +1251,6 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
         navigationController?.pushViewController(viewController, animated: true)
     }
 
-    func collectionViewSelectAll() {
-        selectOcId = dataSource.metadatas.map({ $0.ocId })
-        navigationItem.title = NSLocalizedString("_selected_", comment: "") + " : \(selectOcId.count)" + " / \(dataSource.metadatas.count)"
-        collectionView.reloadData()
-    }
-
     @available(iOS 13.0, *)
     func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
 

+ 3 - 6
iOSClient/Menu/NCCollectionViewCommon+Menu.swift

@@ -469,6 +469,7 @@ extension NCCollectionViewCommon {
                     icon: NCUtility.shared.loadImage(named: "restore"),
                     action: { _ in
                         self.selectOcId.forEach(trash.restoreItem)
+                        self.tapSelect(sender: self)
                     }
                 )
             )
@@ -479,12 +480,8 @@ extension NCCollectionViewCommon {
                     action: { _ in
                         let alert = UIAlertController(title: NSLocalizedString("_trash_delete_selected_", comment: ""), message: "", preferredStyle: .alert)
                         alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .destructive, handler: { _ in
-                            for ocId in self.selectOcId {
-                                trash.deleteItem(with: ocId)
-                            }
-                            self.isEditMode = false
-                            self.selectOcId.removeAll()
-                            self.collectionView.reloadData()
+                            self.selectOcId.forEach(trash.deleteItem)
+                            self.tapSelect(sender: self)
                         }))
                         alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
                         }))

+ 3 - 4
iOSClient/Menu/NCTrash+Menu.swift

@@ -30,10 +30,10 @@ extension NCTrash {
     func toggleMenuMoreHeader() {
 
         var actions: [NCMenuAction] = []
-        
+
         actions.append(
             NCMenuAction(
-                title: NSLocalizedString("_trash_restore_all_", comment: "")
+                title: NSLocalizedString("_trash_restore_all_", comment: ""),
                 icon: NCUtility.shared.loadImage(named: "restore"),
                 action: { _ in
                     self.datasource.forEach({ self.restoreItem(with: $0.fileId) })
@@ -50,8 +50,7 @@ extension NCTrash {
                     alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .destructive, handler: { _ in
                         self.emptyTrash()
                     }))
-                    alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
-                    }))
+                    alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel))
                     self.present(alert, animated: true, completion: nil)
                 }
             )

+ 15 - 8
iOSClient/Trash/Cell/NCTrashListCell.swift

@@ -44,7 +44,6 @@ class NCTrashListCell: UICollectionViewCell {
     weak var delegate: NCTrashListCellDelegate?
 
     var objectId = ""
-    var indexPath = IndexPath()
 
     override func awakeFromNib() {
         super.awakeFromNib()
@@ -80,18 +79,26 @@ class NCTrashListCell: UICollectionViewCell {
 
     func selected(_ status: Bool) {
         if status {
+            var blurEffect: UIVisualEffect?
+            var blurEffectView: UIView?
             imageSelect.image = NCBrandColor.cacheImages.checkedYes
-
-            let blurEffect = UIBlurEffect(style: .extraLight)
-            let blurEffectView = UIVisualEffectView(effect: blurEffect)
-            blurEffectView.frame = self.bounds
-            blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
-            blurEffectView.backgroundColor = NCBrandColor.shared.brandElement.withAlphaComponent(0.2)
+            if traitCollection.userInterfaceStyle == .dark {
+                blurEffect = UIBlurEffect(style: .dark)
+                blurEffectView = UIVisualEffectView(effect: blurEffect)
+                blurEffectView?.backgroundColor = .black
+            } else {
+                blurEffect = UIBlurEffect(style: .extraLight)
+                blurEffectView = UIVisualEffectView(effect: blurEffect)
+                blurEffectView?.backgroundColor = .lightGray
+            }
+            blurEffectView?.frame = self.bounds
+            blurEffectView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
             backgroundView = blurEffectView
-
+            separator.isHidden = true
         } else {
             imageSelect.image = NCBrandColor.cacheImages.checkedNo
             backgroundView = nil
+            separator.isHidden = false
         }
     }
 }

+ 11 - 4
iOSClient/Trash/NCTrash.swift

@@ -29,7 +29,7 @@ class NCTrash: NCCollectionViewCommon, NCTrashListCellDelegate, NCTrashSectionHe
     var trashPath = ""
     var blinkFileId: String?
 
-    private var datasource: [tableTrash] = []
+    var datasource: [tableTrash] = []
     private let highHeader: CGFloat = 50
 
     // MARK: - View Life Cycle
@@ -38,6 +38,7 @@ class NCTrash: NCCollectionViewCommon, NCTrashListCellDelegate, NCTrashSectionHe
 
         view.backgroundColor = NCBrandColor.shared.systemBackground
         self.navigationController?.navigationBar.prefersLargeTitles = true
+        titleCurrentFolder = titleCurrentFolder.isEmpty ? NSLocalizedString("_trash_view_", comment: "") : titleCurrentFolder
 
         // Cell
         collectionView.register(UINib(nibName: "NCTrashListCell", bundle: nil), forCellWithReuseIdentifier: "listCell")
@@ -193,7 +194,13 @@ class NCTrash: NCCollectionViewCommon, NCTrashListCellDelegate, NCTrashSectionHe
 
     override func longPressMoreGridItem(with objectId: String, namedButtonMore: String, gestureRecognizer: UILongPressGestureRecognizer) {
     }
-    
+
+    override func collectionViewSelectAll() {
+        selectOcId = datasource.map({ $0.fileId })
+        navigationItem.title = NSLocalizedString("_selected_", comment: "") + " : \(selectOcId.count)" + " / \(datasource.count)"
+        collectionView.reloadData()
+    }
+
     @objc func reloadTrashDataSource() { self.reloadDataSource() }
     
     @objc override func reloadDataSource() {
@@ -240,13 +247,14 @@ extension NCTrash {
 
         let tableTrash = datasource[indexPath.item]
 
-        if isEditMode {
+        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
         }
 
@@ -325,7 +333,6 @@ extension NCTrash {
             cell.delegate = self
 
             cell.objectId = tableTrash.fileId
-            cell.indexPath = indexPath
             cell.labelTitle.text = tableTrash.trashbinFileName
             cell.labelTitle.textColor = NCBrandColor.shared.label