Marino Faggiana 6 years ago
parent
commit
765576f979
2 changed files with 55 additions and 20 deletions
  1. 16 0
      iOSClient/Database/NCManageDatabase.swift
  2. 39 20
      iOSClient/Trash/NCTrash.swift

+ 16 - 0
iOSClient/Database/NCManageDatabase.swift

@@ -2538,5 +2538,21 @@ class NCManageDatabase: NSObject {
         return Array(results.map { tableTrash.init(value:$0) })
     }
     
+    @objc func getTrashItem(fileID: String) -> tableTrash? {
+        
+        guard let tableAccount = self.getAccountActive() else {
+            return nil
+        }
+        
+        let realm = try! Realm()
+        realm.refresh()
+        
+        guard let result = realm.objects(tableTrash.self).filter("account = %@ AND fileID = %@", tableAccount.account, fileID).first else {
+            return nil
+        }
+        
+        return tableTrash.init(value: result)
+    }
+    
     //MARK: -
 }

+ 39 - 20
iOSClient/Trash/NCTrash.swift

@@ -54,23 +54,7 @@ class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDe
             collectionView.reloadData()
         }
         
-        let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: appDelegate.activeUser, withUserID: appDelegate.activeUserID, withPassword: appDelegate.activePassword, withUrl: appDelegate.activeUrl)
-        
-        ocNetworking?.listingTrash(appDelegate.activeUrl, path:path, account: appDelegate.activeAccount, success: { (item) in
-            
-            NCManageDatabase.sharedInstance.deleteTrash(filePath: self.path)
-            NCManageDatabase.sharedInstance.addTrashs(item as! [tableTrash])
-            
-            let results = NCManageDatabase.sharedInstance.getTrash(filePath: self.path, sorted: "fileName", ascending: true)
-            if (results != nil) {
-                self.datasource = results!
-                self.collectionView.reloadData()
-            }
-            
-        }, failure: { (message, errorCode) in
-            
-            print("error " + message!)
-        })
+        loadListingTrash()
     }
     
     override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
@@ -84,7 +68,7 @@ class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDe
     // MARK: tap
     
     func tapRestoreItem(with fileID: String) {
-        print("tap item restore")
+        restoreItem(with: fileID)
     }
     
     func tapMoreItem(with fileID: String) {
@@ -117,7 +101,43 @@ class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDe
     func tapMoreHeaderMenu() {
         print("tap header more")
     }
-
+    
+    func loadListingTrash() {
+        
+        let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: appDelegate.activeUser, withUserID: appDelegate.activeUserID, withPassword: appDelegate.activePassword, withUrl: appDelegate.activeUrl)
+        
+        ocNetworking?.listingTrash(appDelegate.activeUrl, path:path, account: appDelegate.activeAccount, success: { (item) in
+            
+            NCManageDatabase.sharedInstance.deleteTrash(filePath: self.path)
+            NCManageDatabase.sharedInstance.addTrashs(item as! [tableTrash])
+            
+            let results = NCManageDatabase.sharedInstance.getTrash(filePath: self.path, sorted: "fileName", ascending: true)
+            if (results != nil) {
+                self.datasource = results!
+                self.collectionView.reloadData()
+            }
+            
+        }, failure: { (message, errorCode) in
+            
+            print("error " + message!)
+        })
+    }
+    
+    func restoreItem(with fileID: String) {
+        
+        guard let tableTrash = NCManageDatabase.sharedInstance.getTrashItem(fileID: fileID) else {
+            return
+        }
+        
+        let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: appDelegate.activeUser, withUserID: appDelegate.activeUserID, withPassword: appDelegate.activePassword, withUrl: appDelegate.activeUrl)
+        
+        ocNetworking?.moveFileOrFolder("fileName", fileNameTo: "fileNameTo", success: {
+            
+        }, failure: { (message, errorCode) in
+            
+        })
+    }
+    
     // MARK: collectionView methods
     
     func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
@@ -140,7 +160,6 @@ class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDe
         return CGSize(width: collectionView.frame.width, height: 50)
     }
     
-    
     func numberOfSections(in collectionView: UICollectionView) -> Int {
         return 1
     }