Browse Source

dev trash

Marino Faggiana 6 năm trước cách đây
mục cha
commit
dd8bf737bd
2 tập tin đã thay đổi với 47 bổ sung6 xóa
  1. 15 5
      iOSClient/Trash/NCTrash.swift
  2. 32 1
      iOSClient/Trash/NCTrashListCell.swift

+ 15 - 5
iOSClient/Trash/NCTrash.swift

@@ -9,7 +9,7 @@
 import Foundation
  
 
-class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDelegate {
+class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDelegate, UIGestureRecognizerDelegate, NCTrashListDelegate {
     
     @IBOutlet fileprivate weak var collectionView: UICollectionView!
     
@@ -58,11 +58,12 @@ class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDe
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         
         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! NCTrashListCell
-        
+        cell.delegate = self
+
         let tableTrash = datasource[indexPath.item]
         
         if tableTrash.directory {
-            cell.configure(with: CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), multiplier: 3, color: NCBrandColor.sharedInstance.brandElement), title: tableTrash.trashbinFileName, info: CCUtility.dateDiff(tableTrash.date as Date))
+            cell.configure(with: tableTrash.fileID ,image: CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), multiplier: 3, color: NCBrandColor.sharedInstance.brandElement), title: tableTrash.trashbinFileName, info: CCUtility.dateDiff(tableTrash.date as Date))
         } else {
             
             var image: UIImage?
@@ -72,9 +73,9 @@ class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDe
                 image = UIImage.init(named: "file")
             }
             
-            cell.configure(with: image, title: tableTrash.trashbinFileName, info: CCUtility.dateDiff(tableTrash.date as Date) + " " + CCUtility.transformedSize(tableTrash.size))
+            cell.configure(with: tableTrash.fileID, image: image, title: tableTrash.trashbinFileName, info: CCUtility.dateDiff(tableTrash.date as Date) + " " + CCUtility.transformedSize(tableTrash.size))
         }
-        
+                
         return cell
     }
     
@@ -82,6 +83,15 @@ class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDe
         super.viewWillTransition(to: size, with: coordinator)
         collectionView.collectionViewLayout.invalidateLayout()
     }
+    
+    // MARK: tap cell
+    func tapRestoreDelegate(with fileID: String) {
+        
+    }
+    
+    func tapMoreDelegate(with fileID: String) {
+    
+    }
 }
 
 class ListLayout: UICollectionViewFlowLayout {

+ 32 - 1
iOSClient/Trash/NCTrashListCell.swift

@@ -16,12 +16,31 @@ class NCTrashListCell: UICollectionViewCell {
     @IBOutlet weak var labelInfo: UILabel!
     @IBOutlet weak var restore: UIImageView!
     @IBOutlet weak var more: UIImageView!
+    
+    var delegate: NCTrashListDelegate?
+    
+    var fileID = ""
 
     override func awakeFromNib() {
         super.awakeFromNib()
+       
+        let tapGestureRestore = UITapGestureRecognizer(target: self, action: #selector(NCTrashListCell.tapRestore(sender:)))
+        addGestureRecognizer(tapGestureRestore)
+        tapGestureRestore.numberOfTapsRequired = 1
+        restore.isUserInteractionEnabled = true
+        restore.addGestureRecognizer(tapGestureRestore)
+        
+        let tapGestureMore = UITapGestureRecognizer(target: self, action: #selector(NCTrashListCell.tapMore(sender:)))
+        addGestureRecognizer(tapGestureMore)
+        tapGestureMore.numberOfTapsRequired = 1
+        more.isUserInteractionEnabled = true
+        more.addGestureRecognizer(tapGestureMore)
     }
     
-    public func configure(with image: UIImage?, title: String, info: String) {
+    public func configure(with fileID: String, image: UIImage?, title: String, info: String) {
+
+        self.fileID = fileID
+
         imageView.image = image
         labelTitle.text = title
         labelInfo.text = info
@@ -29,4 +48,16 @@ class NCTrashListCell: UICollectionViewCell {
         restore.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "restore"), multiplier: 2, color: NCBrandColor.sharedInstance.icon)
         more.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "more"), multiplier: 2, color: NCBrandColor.sharedInstance.icon)
     }
+    
+    @objc func tapRestore(sender: UITapGestureRecognizer) {
+        delegate?.tapRestoreDelegate(with: fileID)
+    }
+    @objc func tapMore(sender: UITapGestureRecognizer) {
+        delegate?.tapMoreDelegate(with: fileID)
+    }
+}
+
+protocol NCTrashListDelegate {
+    func tapRestoreDelegate(with fileID: String)
+    func tapMoreDelegate(with fileID: String)
 }