NCTrash.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // NCTrash.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 02/10/2018.
  6. // Copyright © 2018 Marino Faggiana. All rights reserved.
  7. //
  8. import Foundation
  9. class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDelegate {
  10. @IBOutlet fileprivate weak var collectionView: UICollectionView!
  11. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  12. var path = ""
  13. var itemHeight: CGFloat = 60
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. }
  17. override func viewWillAppear(_ animated: Bool) {
  18. super.viewWillAppear(animated)
  19. if path == "" {
  20. let userID = (appDelegate.activeUserID as NSString).addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlFragmentAllowed)
  21. path = k_dav + "/trashbin/" + userID! + "/trash/"
  22. }
  23. let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: appDelegate.activeUser, withUserID: appDelegate.activeUserID, withPassword: appDelegate.activePassword, withUrl: appDelegate.activeUrl)
  24. ocNetworking?.listingTrash(appDelegate.activeUrl, path:path, account: appDelegate.activeAccount, success: { (item) in
  25. NCManageDatabase.sharedInstance.deleteTrash(filePath: self.path)
  26. _ = NCManageDatabase.sharedInstance.addTrashs(item as! [tableTrash])
  27. }, failure: { (message, errorCode) in
  28. print("error " + message!)
  29. })
  30. }
  31. // MARK: collectionView methods
  32. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  33. return 2
  34. }
  35. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  36. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! NCTrashListCell
  37. //let image = imagesToDisplay[indexPath.item]
  38. //cell.imageView.image = image
  39. return cell
  40. }
  41. override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
  42. super.viewWillTransition(to: size, with: coordinator)
  43. collectionView.collectionViewLayout.invalidateLayout()
  44. }
  45. }
  46. class ListLayout: UICollectionViewFlowLayout {
  47. var itemHeight: CGFloat = 60
  48. init(itemHeight: CGFloat) {
  49. super.init()
  50. minimumLineSpacing = 1
  51. minimumInteritemSpacing = 1
  52. self.itemHeight = itemHeight
  53. }
  54. required init?(coder aDecoder: NSCoder) {
  55. fatalError("init(coder:) has not been implemented")
  56. }
  57. override var itemSize: CGSize {
  58. get {
  59. if let collectionView = collectionView {
  60. let itemWidth: CGFloat = collectionView.frame.width
  61. return CGSize(width: itemWidth, height: self.itemHeight)
  62. }
  63. // Default fallback
  64. return CGSize(width: 100, height: 100)
  65. }
  66. set {
  67. super.itemSize = newValue
  68. }
  69. }
  70. override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  71. return proposedContentOffset
  72. }
  73. }