|
@@ -4,7 +4,9 @@
|
|
//
|
|
//
|
|
// Created by Marino Faggiana on 02/10/2018.
|
|
// Created by Marino Faggiana on 02/10/2018.
|
|
// Copyright © 2018 Marino Faggiana. All rights reserved.
|
|
// Copyright © 2018 Marino Faggiana. All rights reserved.
|
|
|
|
+// Copyright © 2022 Henrik Storch. All rights reserved.
|
|
//
|
|
//
|
|
|
|
+// Author Henrik Storch <henrik.storch@nextcloud.com>
|
|
// Author Marino Faggiana <marino.faggiana@nextcloud.com>
|
|
// Author Marino Faggiana <marino.faggiana@nextcloud.com>
|
|
//
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// This program is free software: you can redistribute it and/or modify
|
|
@@ -21,10 +23,13 @@
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
//
|
|
//
|
|
|
|
|
|
|
|
+import Realm
|
|
import UIKit
|
|
import UIKit
|
|
import NCCommunication
|
|
import NCCommunication
|
|
|
|
|
|
-class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDelegate, NCGridCellDelegate, NCTrashSectionHeaderMenuDelegate, NCEmptyDataSetDelegate {
|
|
|
|
|
|
+class NCTrash: UIViewController, NCSelectableNavigationView, NCTrashListCellDelegate, NCTrashSectionHeaderMenuDelegate, NCEmptyDataSetDelegate, NCGridCellDelegate {
|
|
|
|
+
|
|
|
|
+ var selectableDataSource: [RealmSwiftObject] { datasource }
|
|
|
|
|
|
@IBOutlet weak var collectionView: UICollectionView!
|
|
@IBOutlet weak var collectionView: UICollectionView!
|
|
|
|
|
|
@@ -33,22 +38,21 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
|
|
var blinkFileId: String?
|
|
var blinkFileId: String?
|
|
var emptyDataSet: NCEmptyDataSet?
|
|
var emptyDataSet: NCEmptyDataSet?
|
|
|
|
|
|
- internal let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
|
|
|
+ internal let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
|
|
|
|
|
|
internal var isEditMode = false
|
|
internal var isEditMode = false
|
|
internal var selectOcId: [String] = []
|
|
internal var selectOcId: [String] = []
|
|
|
|
|
|
- private var datasource: [tableTrash] = []
|
|
|
|
- private var layoutForView: NCGlobal.layoutForViewType?
|
|
|
|
- private var listLayout: NCListLayout!
|
|
|
|
- private var gridLayout: NCGridLayout!
|
|
|
|
- private let highHeader: CGFloat = 50
|
|
|
|
|
|
+ var datasource: [tableTrash] = []
|
|
|
|
+ var layoutForView: NCGlobal.layoutForViewType?
|
|
|
|
+ var listLayout: NCListLayout!
|
|
|
|
+ var gridLayout: NCGridLayout!
|
|
|
|
+ let highHeader: CGFloat = 50
|
|
private let refreshControl = UIRefreshControl()
|
|
private let refreshControl = UIRefreshControl()
|
|
|
|
|
|
// MARK: - View Life Cycle
|
|
// MARK: - View Life Cycle
|
|
|
|
|
|
override func viewDidLoad() {
|
|
override func viewDidLoad() {
|
|
- super.viewDidLoad()
|
|
|
|
|
|
|
|
view.backgroundColor = NCBrandColor.shared.systemBackground
|
|
view.backgroundColor = NCBrandColor.shared.systemBackground
|
|
self.navigationController?.navigationBar.prefersLargeTitles = true
|
|
self.navigationController?.navigationBar.prefersLargeTitles = true
|
|
@@ -82,7 +86,6 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
|
|
}
|
|
}
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
- super.viewWillAppear(animated)
|
|
|
|
|
|
|
|
appDelegate.activeViewController = self
|
|
appDelegate.activeViewController = self
|
|
|
|
|
|
@@ -97,16 +100,16 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
|
|
collectionView.collectionViewLayout = gridLayout
|
|
collectionView.collectionViewLayout = gridLayout
|
|
}
|
|
}
|
|
|
|
|
|
- if trashPath == "" {
|
|
|
|
|
|
+ if trashPath.isEmpty {
|
|
guard let userId = (appDelegate.userId as NSString).addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlFragmentAllowed) else { return }
|
|
guard let userId = (appDelegate.userId as NSString).addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlFragmentAllowed) else { return }
|
|
trashPath = appDelegate.urlBase + "/" + NCUtilityFileSystem.shared.getWebDAV(account: appDelegate.account) + "/trashbin/" + userId + "/trash/"
|
|
trashPath = appDelegate.urlBase + "/" + NCUtilityFileSystem.shared.getWebDAV(account: appDelegate.account) + "/trashbin/" + userId + "/trash/"
|
|
}
|
|
}
|
|
|
|
+ setNavigationItem()
|
|
reloadDataSource()
|
|
reloadDataSource()
|
|
}
|
|
}
|
|
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
super.viewDidAppear(animated)
|
|
super.viewDidAppear(animated)
|
|
-
|
|
|
|
loadListingTrash()
|
|
loadListingTrash()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -125,7 +128,6 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
|
|
// MARK: - Empty
|
|
// MARK: - Empty
|
|
|
|
|
|
func emptyDataSetView(_ view: NCEmptyView) {
|
|
func emptyDataSetView(_ view: NCEmptyView) {
|
|
-
|
|
|
|
view.emptyImage.image = UIImage(named: "trash")?.image(color: .gray, size: UIScreen.main.bounds.width)
|
|
view.emptyImage.image = UIImage(named: "trash")?.image(color: .gray, size: UIScreen.main.bounds.width)
|
|
view.emptyTitle.text = NSLocalizedString("_trash_no_trash_", comment: "")
|
|
view.emptyTitle.text = NSLocalizedString("_trash_no_trash_", comment: "")
|
|
view.emptyDescription.text = NSLocalizedString("_trash_no_trash_description_", comment: "")
|
|
view.emptyDescription.text = NSLocalizedString("_trash_no_trash_description_", comment: "")
|
|
@@ -159,13 +161,11 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
|
|
}
|
|
}
|
|
|
|
|
|
func tapOrderHeaderMenu(sender: Any) {
|
|
func tapOrderHeaderMenu(sender: Any) {
|
|
-
|
|
|
|
let sortMenu = NCSortMenu()
|
|
let sortMenu = NCSortMenu()
|
|
sortMenu.toggleMenu(viewController: self, key: NCGlobal.shared.layoutViewTrash, sortButton: sender as? UIButton, serverUrl: "", hideDirectoryOnTop: true)
|
|
sortMenu.toggleMenu(viewController: self, key: NCGlobal.shared.layoutViewTrash, sortButton: sender as? UIButton, serverUrl: "", hideDirectoryOnTop: true)
|
|
}
|
|
}
|
|
|
|
|
|
func tapMoreHeaderMenu(sender: Any) {
|
|
func tapMoreHeaderMenu(sender: Any) {
|
|
-
|
|
|
|
toggleMenuMoreHeader()
|
|
toggleMenuMoreHeader()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -173,211 +173,38 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
|
|
|
|
|
|
if !isEditMode {
|
|
if !isEditMode {
|
|
restoreItem(with: ocId)
|
|
restoreItem(with: ocId)
|
|
- } else {
|
|
|
|
- let buttonPosition: CGPoint = (sender as! UIButton).convert(CGPoint.zero, to: collectionView)
|
|
|
|
|
|
+ } else if let button = sender as? UIView {
|
|
|
|
+ let buttonPosition = button.convert(CGPoint.zero, to: collectionView)
|
|
let indexPath = collectionView.indexPathForItem(at: buttonPosition)
|
|
let indexPath = collectionView.indexPathForItem(at: buttonPosition)
|
|
collectionView(self.collectionView, didSelectItemAt: indexPath!)
|
|
collectionView(self.collectionView, didSelectItemAt: indexPath!)
|
|
- }
|
|
|
|
|
|
+ } // else: undefined sender
|
|
}
|
|
}
|
|
|
|
|
|
func tapMoreListItem(with objectId: String, image: UIImage?, sender: Any) {
|
|
func tapMoreListItem(with objectId: String, image: UIImage?, sender: Any) {
|
|
|
|
|
|
if !isEditMode {
|
|
if !isEditMode {
|
|
- toggleMenuMoreList(with: objectId, image: image)
|
|
|
|
- } else {
|
|
|
|
- let buttonPosition: CGPoint = (sender as! UIButton).convert(CGPoint.zero, to: collectionView)
|
|
|
|
|
|
+ toggleMenuMore(with: objectId, image: image, isGridCell: false)
|
|
|
|
+ } else if let button = sender as? UIView {
|
|
|
|
+ let buttonPosition = button.convert(CGPoint.zero, to: collectionView)
|
|
let indexPath = collectionView.indexPathForItem(at: buttonPosition)
|
|
let indexPath = collectionView.indexPathForItem(at: buttonPosition)
|
|
collectionView(self.collectionView, didSelectItemAt: indexPath!)
|
|
collectionView(self.collectionView, didSelectItemAt: indexPath!)
|
|
- }
|
|
|
|
|
|
+ } // else: undefined sender
|
|
}
|
|
}
|
|
|
|
|
|
func tapMoreGridItem(with objectId: String, namedButtonMore: String, image: UIImage?, sender: Any) {
|
|
func tapMoreGridItem(with objectId: String, namedButtonMore: String, image: UIImage?, sender: Any) {
|
|
|
|
|
|
if !isEditMode {
|
|
if !isEditMode {
|
|
- toggleMenuMoreGrid(with: objectId, namedButtonMore: namedButtonMore, image: image)
|
|
|
|
- } else {
|
|
|
|
- let buttonPosition: CGPoint = (sender as! UIButton).convert(CGPoint.zero, to: collectionView)
|
|
|
|
|
|
+ toggleMenuMore(with: objectId, image: image, isGridCell: true)
|
|
|
|
+ } else if let button = sender as? UIView {
|
|
|
|
+ let buttonPosition = button.convert(CGPoint.zero, to: collectionView)
|
|
let indexPath = collectionView.indexPathForItem(at: buttonPosition)
|
|
let indexPath = collectionView.indexPathForItem(at: buttonPosition)
|
|
collectionView(self.collectionView, didSelectItemAt: indexPath!)
|
|
collectionView(self.collectionView, didSelectItemAt: indexPath!)
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func longPressGridItem(with objectId: String, gestureRecognizer: UILongPressGestureRecognizer) {
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func longPressMoreGridItem(with objectId: String, namedButtonMore: String, gestureRecognizer: UILongPressGestureRecognizer) {
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// MARK: - Collection View
|
|
|
|
-
|
|
|
|
-extension NCTrash: UICollectionViewDelegate {
|
|
|
|
-
|
|
|
|
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
|
-
|
|
|
|
- let tableTrash = datasource[indexPath.item]
|
|
|
|
-
|
|
|
|
- if isEditMode {
|
|
|
|
- if let index = selectOcId.firstIndex(of: tableTrash.fileId) {
|
|
|
|
- selectOcId.remove(at: index)
|
|
|
|
- } else {
|
|
|
|
- selectOcId.append(tableTrash.fileId)
|
|
|
|
- }
|
|
|
|
- collectionView.reloadItems(at: [indexPath])
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if tableTrash.directory {
|
|
|
|
-
|
|
|
|
- let ncTrash: NCTrash = UIStoryboard(name: "NCTrash", bundle: nil).instantiateInitialViewController() as! NCTrash
|
|
|
|
-
|
|
|
|
- ncTrash.trashPath = tableTrash.filePath + tableTrash.fileName
|
|
|
|
- ncTrash.titleCurrentFolder = tableTrash.trashbinFileName
|
|
|
|
-
|
|
|
|
- self.navigationController?.pushViewController(ncTrash, animated: true)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-extension NCTrash: UICollectionViewDataSource {
|
|
|
|
-
|
|
|
|
- func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
|
|
|
|
-
|
|
|
|
- if kind == UICollectionView.elementKindSectionHeader {
|
|
|
|
-
|
|
|
|
- let trashHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeaderMenu", for: indexPath) as! NCTrashSectionHeaderMenu
|
|
|
|
-
|
|
|
|
- if collectionView.collectionViewLayout == gridLayout {
|
|
|
|
- trashHeader.buttonSwitch.setImage(UIImage(named: "switchList")?.image(color: NCBrandColor.shared.gray, size: 25), for: .normal)
|
|
|
|
- } else {
|
|
|
|
- trashHeader.buttonSwitch.setImage(UIImage(named: "switchGrid")?.image(color: NCBrandColor.shared.gray, size: 25), for: .normal)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- trashHeader.delegate = self
|
|
|
|
- trashHeader.backgroundColor = NCBrandColor.shared.systemBackground
|
|
|
|
- trashHeader.separator.backgroundColor = NCBrandColor.shared.separator
|
|
|
|
- trashHeader.setStatusButton(datasource: datasource)
|
|
|
|
- trashHeader.setTitleSorted(datasourceTitleButton: layoutForView?.titleButtonHeader ?? "")
|
|
|
|
-
|
|
|
|
- return trashHeader
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- let trashFooter = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as! NCTrashSectionFooter
|
|
|
|
-
|
|
|
|
- trashFooter.setTitleLabelFooter(datasource: datasource)
|
|
|
|
-
|
|
|
|
- return trashFooter
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
|
|
- return 1
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
|
- emptyDataSet?.numberOfItemsInSection(datasource.count, section: section)
|
|
|
|
- return datasource.count
|
|
|
|
|
|
+ } // else: undefined sender
|
|
}
|
|
}
|
|
|
|
|
|
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
|
|
|
+ func longPressGridItem(with objectId: String, gestureRecognizer: UILongPressGestureRecognizer) { }
|
|
|
|
|
|
- let tableTrash = datasource[indexPath.item]
|
|
|
|
- var image: UIImage?
|
|
|
|
-
|
|
|
|
- if tableTrash.iconName.count > 0 {
|
|
|
|
- image = UIImage(named: tableTrash.iconName)
|
|
|
|
- } else {
|
|
|
|
- image = UIImage(named: "file")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
|
|
|
|
- image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName))
|
|
|
|
- } else {
|
|
|
|
- if tableTrash.hasPreview && !CCUtility.fileProviderStoragePreviewIconExists(tableTrash.fileId, etag: tableTrash.fileName) {
|
|
|
|
- downloadThumbnail(with: tableTrash, indexPath: indexPath)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if collectionView.collectionViewLayout == listLayout {
|
|
|
|
-
|
|
|
|
- // LIST
|
|
|
|
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCTrashListCell
|
|
|
|
- cell.delegate = self
|
|
|
|
-
|
|
|
|
- cell.objectId = tableTrash.fileId
|
|
|
|
- cell.indexPath = indexPath
|
|
|
|
- cell.labelTitle.text = tableTrash.trashbinFileName
|
|
|
|
- cell.labelTitle.textColor = NCBrandColor.shared.label
|
|
|
|
-
|
|
|
|
- if tableTrash.directory {
|
|
|
|
- cell.imageItem.image = NCBrandColor.cacheImages.folder
|
|
|
|
- cell.labelInfo.text = CCUtility.dateDiff(tableTrash.date as Date)
|
|
|
|
- } else {
|
|
|
|
- cell.imageItem.image = image
|
|
|
|
- cell.labelInfo.text = CCUtility.dateDiff(tableTrash.date as Date) + ", " + CCUtility.transformedSize(tableTrash.size)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if isEditMode {
|
|
|
|
- cell.selectMode(true)
|
|
|
|
- if selectOcId.contains(tableTrash.fileId) {
|
|
|
|
- cell.selected(true)
|
|
|
|
- } else {
|
|
|
|
- cell.selected(false)
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- cell.selectMode(false)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return cell
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- // GRID
|
|
|
|
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
|
|
|
|
- cell.delegate = self
|
|
|
|
-
|
|
|
|
- cell.fileObjectId = tableTrash.fileId
|
|
|
|
- cell.labelTitle.text = tableTrash.trashbinFileName
|
|
|
|
- cell.labelTitle.textColor = NCBrandColor.shared.label
|
|
|
|
- cell.setButtonMore(named: NCGlobal.shared.buttonMoreMore, image: NCBrandColor.cacheImages.buttonMore)
|
|
|
|
-
|
|
|
|
- if tableTrash.directory {
|
|
|
|
- cell.imageItem.image = NCBrandColor.cacheImages.folder
|
|
|
|
- } else {
|
|
|
|
- cell.imageItem.image = image
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if isEditMode {
|
|
|
|
- cell.imageSelect.isHidden = false
|
|
|
|
- if selectOcId.contains(tableTrash.fileId) {
|
|
|
|
- cell.selected(true)
|
|
|
|
- } else {
|
|
|
|
- cell.selected(false)
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- cell.imageSelect.isHidden = true
|
|
|
|
- cell.backgroundView = nil
|
|
|
|
- }
|
|
|
|
- return cell
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-extension NCTrash: UICollectionViewDelegateFlowLayout {
|
|
|
|
-
|
|
|
|
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
|
|
|
|
- return CGSize(width: collectionView.frame.width, height: highHeader)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
|
|
|
|
- return CGSize(width: collectionView.frame.width, height: highHeader)
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// MARK: - NC API & Algorithm
|
|
|
|
-
|
|
|
|
-extension NCTrash {
|
|
|
|
|
|
+ func longPressMoreGridItem(with objectId: String, namedButtonMore: String, gestureRecognizer: UILongPressGestureRecognizer) { }
|
|
|
|
|
|
@objc func reloadDataSource() {
|
|
@objc func reloadDataSource() {
|
|
|
|
|
|
@@ -391,28 +218,28 @@ extension NCTrash {
|
|
|
|
|
|
datasource = tashItems
|
|
datasource = tashItems
|
|
collectionView.reloadData()
|
|
collectionView.reloadData()
|
|
-
|
|
|
|
- if self.blinkFileId != nil {
|
|
|
|
- for item in 0...self.datasource.count-1 {
|
|
|
|
- if self.datasource[item].fileId.contains(self.blinkFileId!) {
|
|
|
|
- let indexPath = IndexPath(item: item, section: 0)
|
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
|
- UIView.animate(withDuration: 0.3) {
|
|
|
|
- self.collectionView.scrollToItem(at: indexPath, at: .centeredVertically, animated: false)
|
|
|
|
- } completion: { _ in
|
|
|
|
- if let cell = self.collectionView.cellForItem(at: indexPath) {
|
|
|
|
- cell.backgroundColor = .darkGray
|
|
|
|
- UIView.animate(withDuration: 2) {
|
|
|
|
- cell.backgroundColor = .clear
|
|
|
|
- self.blinkFileId = nil
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ guard let blinkFileId = blinkFileId else { return }
|
|
|
|
+ for itemIx in 0..<self.datasource.count where self.datasource[itemIx].fileId.contains(blinkFileId) {
|
|
|
|
+ let indexPath = IndexPath(item: itemIx, section: 0)
|
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
|
+ UIView.animate(withDuration: 0.3) {
|
|
|
|
+ self.collectionView.scrollToItem(at: indexPath, at: .centeredVertically, animated: false)
|
|
|
|
+ } completion: { _ in
|
|
|
|
+ guard let cell = self.collectionView.cellForItem(at: indexPath) else { return }
|
|
|
|
+ cell.backgroundColor = .darkGray
|
|
|
|
+ UIView.animate(withDuration: 2) {
|
|
|
|
+ cell.backgroundColor = .clear
|
|
|
|
+ self.blinkFileId = nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// MARK: - NC API & Algorithm
|
|
|
|
+
|
|
|
|
+extension NCTrash {
|
|
|
|
|
|
@objc func loadListingTrash() {
|
|
@objc func loadListingTrash() {
|
|
|
|
|
|
@@ -422,7 +249,7 @@ extension NCTrash {
|
|
NCManageDatabase.shared.deleteTrash(filePath: self.trashPath, account: self.appDelegate.account)
|
|
NCManageDatabase.shared.deleteTrash(filePath: self.trashPath, account: self.appDelegate.account)
|
|
NCManageDatabase.shared.addTrash(account: account, items: items)
|
|
NCManageDatabase.shared.addTrash(account: account, items: items)
|
|
} else if errorCode != 0 {
|
|
} else if errorCode != 0 {
|
|
- NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
|
|
|
|
|
|
+ NCContentPresenter.shared.showError(description: errorDescription, errorCode: errorCode)
|
|
} else {
|
|
} else {
|
|
print("[LOG] It has been changed user during networking process, error.")
|
|
print("[LOG] It has been changed user during networking process, error.")
|
|
}
|
|
}
|
|
@@ -448,7 +275,7 @@ extension NCTrash {
|
|
NCManageDatabase.shared.deleteTrash(fileId: fileId, account: account)
|
|
NCManageDatabase.shared.deleteTrash(fileId: fileId, account: account)
|
|
self.reloadDataSource()
|
|
self.reloadDataSource()
|
|
} else if errorCode != 0 {
|
|
} else if errorCode != 0 {
|
|
- NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
|
|
|
|
|
|
+ NCContentPresenter.shared.showError(description: errorDescription, errorCode: errorCode)
|
|
} else {
|
|
} else {
|
|
print("[LOG] It has been changed user during networking process, error.")
|
|
print("[LOG] It has been changed user during networking process, error.")
|
|
}
|
|
}
|
|
@@ -463,7 +290,7 @@ extension NCTrash {
|
|
if errorCode == 0 && account == self.appDelegate.account {
|
|
if errorCode == 0 && account == self.appDelegate.account {
|
|
NCManageDatabase.shared.deleteTrash(fileId: nil, account: self.appDelegate.account)
|
|
NCManageDatabase.shared.deleteTrash(fileId: nil, account: self.appDelegate.account)
|
|
} else if errorCode != 0 {
|
|
} else if errorCode != 0 {
|
|
- NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
|
|
|
|
|
|
+ NCContentPresenter.shared.showError(description: errorDescription, errorCode: errorCode)
|
|
} else {
|
|
} else {
|
|
print("[LOG] It has been changed user during networking process, error.")
|
|
print("[LOG] It has been changed user during networking process, error.")
|
|
}
|
|
}
|
|
@@ -484,7 +311,7 @@ extension NCTrash {
|
|
NCManageDatabase.shared.deleteTrash(fileId: fileId, account: account)
|
|
NCManageDatabase.shared.deleteTrash(fileId: fileId, account: account)
|
|
self.reloadDataSource()
|
|
self.reloadDataSource()
|
|
} else if errorCode != 0 {
|
|
} else if errorCode != 0 {
|
|
- NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
|
|
|
|
|
|
+ NCContentPresenter.shared.showError(description: errorDescription, errorCode: errorCode)
|
|
} else {
|
|
} else {
|
|
print("[LOG] It has been changed user during networking process, error.")
|
|
print("[LOG] It has been changed user during networking process, error.")
|
|
}
|
|
}
|
|
@@ -496,17 +323,22 @@ extension NCTrash {
|
|
let fileNamePreviewLocalPath = CCUtility.getDirectoryProviderStoragePreviewOcId(tableTrash.fileId, etag: tableTrash.fileName)!
|
|
let fileNamePreviewLocalPath = CCUtility.getDirectoryProviderStoragePreviewOcId(tableTrash.fileId, etag: tableTrash.fileName)!
|
|
let fileNameIconLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)!
|
|
let fileNameIconLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)!
|
|
|
|
|
|
- NCCommunication.shared.downloadPreview(fileNamePathOrFileId: tableTrash.fileId, fileNamePreviewLocalPath: fileNamePreviewLocalPath, widthPreview: NCGlobal.shared.sizePreview, heightPreview: NCGlobal.shared.sizePreview, fileNameIconLocalPath: fileNameIconLocalPath, sizeIcon: NCGlobal.shared.sizeIcon, etag: nil, endpointTrashbin: true) { account, _, imageIcon, _, _, errorCode, _ in
|
|
|
|
-
|
|
|
|
- if errorCode == 0 && imageIcon != nil && account == self.appDelegate.account {
|
|
|
|
- if let cell = self.collectionView.cellForItem(at: indexPath) {
|
|
|
|
- if cell is NCTrashListCell {
|
|
|
|
- (cell as! NCTrashListCell).imageItem.image = imageIcon
|
|
|
|
- } else if cell is NCGridCell {
|
|
|
|
- (cell as! NCGridCell).imageItem.image = imageIcon
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ NCCommunication.shared.downloadPreview(
|
|
|
|
+ fileNamePathOrFileId: tableTrash.fileId,
|
|
|
|
+ fileNamePreviewLocalPath: fileNamePreviewLocalPath,
|
|
|
|
+ widthPreview: NCGlobal.shared.sizePreview,
|
|
|
|
+ heightPreview: NCGlobal.shared.sizePreview,
|
|
|
|
+ fileNameIconLocalPath: fileNameIconLocalPath,
|
|
|
|
+ sizeIcon: NCGlobal.shared.sizeIcon,
|
|
|
|
+ etag: nil,
|
|
|
|
+ endpointTrashbin: true) { account, _, imageIcon, _, _, errorCode, _ in
|
|
|
|
+ guard errorCode == 0, let imageIcon = imageIcon, account == self.appDelegate.account,
|
|
|
|
+ let cell = self.collectionView.cellForItem(at: indexPath) else { return }
|
|
|
|
+ if let cell = cell as? NCTrashListCell {
|
|
|
|
+ cell.imageItem.image = imageIcon
|
|
|
|
+ } else if let cell = cell as? NCGridCell {
|
|
|
|
+ cell.imageItem.image = imageIcon
|
|
|
|
+ } // else: undefined cell
|
|
}
|
|
}
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|