// // NCTrash.swift // Nextcloud // // Created by Marino Faggiana on 02/10/2018. // Copyright © 2018 Marino Faggiana. All rights reserved. // import Foundation class NCTrash: UIViewController , UICollectionViewDataSource, UICollectionViewDelegate { @IBOutlet fileprivate weak var collectionView: UICollectionView! let appDelegate = UIApplication.shared.delegate as! AppDelegate var path = "" var itemHeight: CGFloat = 60 override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) if path == "" { let userID = (appDelegate.activeUserID as NSString).addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlFragmentAllowed) path = k_dav + "/trashbin/" + userID! + "/trash/" } 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]) }, failure: { (message, errorCode) in print("error " + message!) }) } // MARK: collectionView methods func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 2 } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! NCTrashListCell //let image = imagesToDisplay[indexPath.item] //cell.imageView.image = image return cell } override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) collectionView.collectionViewLayout.invalidateLayout() } } class ListLayout: UICollectionViewFlowLayout { var itemHeight: CGFloat = 60 init(itemHeight: CGFloat) { super.init() minimumLineSpacing = 1 minimumInteritemSpacing = 1 self.itemHeight = itemHeight } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override var itemSize: CGSize { get { if let collectionView = collectionView { let itemWidth: CGFloat = collectionView.frame.width return CGSize(width: itemWidth, height: self.itemHeight) } // Default fallback return CGSize(width: 100, height: 100) } set { super.itemSize = newValue } } override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint { return proposedContentOffset } }