diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index cbbd8c1e3f..78810095db 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -152,6 +152,7 @@ final class NCGlobal: Sendable { // let buttonMoreMore = "more" let buttonMoreLock = "moreLock" + let buttonMoreStop = "stop" // Text - OnlyOffice - Collabora - QuickLook // diff --git a/iOSClient/Trash/Cell/NCTrashGridCell.swift b/iOSClient/Trash/Cell/NCTrashGridCell.swift index 81743c6653..ad14721e09 100644 --- a/iOSClient/Trash/Cell/NCTrashGridCell.swift +++ b/iOSClient/Trash/Cell/NCTrashGridCell.swift @@ -2,23 +2,8 @@ // NCTrashGridCell.swift // Nextcloud // -// Created by Marino Faggiana on 19/03/2024. -// Copyright © 2024 Marino Faggiana. All rights reserved. -// -// Author Marino Faggiana -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . +// Created by A200073704 on 27/06/23. +// Copyright © 2023 Marino Faggiana. All rights reserved. // import UIKit @@ -31,18 +16,64 @@ class NCTrashGridCell: UICollectionViewCell, NCTrashCellProtocol { @IBOutlet weak var imageItem: UIImageView! @IBOutlet weak var imageSelect: UIImageView! + @IBOutlet weak var imageStatus: UIImageView! + @IBOutlet weak var imageFavorite: UIImageView! + @IBOutlet weak var imageLocal: UIImageView! @IBOutlet weak var labelTitle: UILabel! @IBOutlet weak var labelInfo: UILabel! - @IBOutlet weak var labelSubinfo: UILabel! @IBOutlet weak var buttonMore: UIButton! @IBOutlet weak var imageVisualEffect: UIVisualEffectView! + @IBOutlet weak var progressView: UIProgressView! - weak var delegate: NCTrashGridCellDelegate? - var objectId = "" + internal var objectId = "" var indexPath = IndexPath() var account = "" var user = "" + weak var delegate: NCTrashGridCellDelegate? + var namedButtonMore = "" + + var fileObjectId: String? { + get { return objectId } + set { objectId = newValue ?? "" } + } + var filePreviewImageView: UIImageView? { + get { return imageItem } + set { imageItem = newValue } + } + var fileUser: String? { + get { return user } + set { user = newValue ?? "" } + } + var fileTitleLabel: UILabel? { + get { return labelTitle } + set { labelTitle = newValue } + } + var fileInfoLabel: UILabel? { + get { return labelInfo } + set { labelInfo = newValue } + } + var fileProgressView: UIProgressView? { + get { return progressView } + set { progressView = newValue } + } + var fileSelectImage: UIImageView? { + get { return imageSelect } + set { imageSelect = newValue } + } + var fileStatusImage: UIImageView? { + get { return imageStatus } + set { imageStatus = newValue } + } + var fileLocalImage: UIImageView? { + get { return imageLocal } + set { imageLocal = newValue } + } + var fileFavoriteImage: UIImageView? { + get { return imageFavorite } + set { imageFavorite = newValue } + } + override func awakeFromNib() { super.awakeFromNib() initCell() @@ -66,9 +97,14 @@ class NCTrashGridCell: UICollectionViewCell, NCTrashCellProtocol { imageVisualEffect.clipsToBounds = true imageVisualEffect.alpha = 0.5 + progressView.tintColor = NCBrandColor.shared.brandElement + progressView.transform = CGAffineTransform(scaleX: 1.0, y: 0.5) + progressView.trackTintColor = .clear + labelTitle.text = "" labelInfo.text = "" - labelSubinfo.text = "" + labelTitle.textColor = .label + labelInfo.textColor = .systemGray } override func snapshotView(afterScreenUpdates afterUpdates: Bool) -> UIView? { @@ -79,16 +115,20 @@ class NCTrashGridCell: UICollectionViewCell, NCTrashCellProtocol { delegate?.tapMoreGridItem(with: objectId, image: imageItem.image, sender: sender) } + fileprivate func setA11yActions() { + let moreName = namedButtonMore == NCGlobal.shared.buttonMoreStop ? "_cancel_" : "_more_" + self.accessibilityCustomActions = [ UIAccessibilityCustomAction( - name: NSLocalizedString("_more_", comment: ""), + name: NSLocalizedString(moreName, comment: ""), target: self, selector: #selector(touchUpInsideMore)) ] } - func setButtonMore(image: UIImage) { + func setButtonMore(named: String, image: UIImage) { + namedButtonMore = named buttonMore.setImage(image, for: .normal) setA11yActions() } @@ -99,19 +139,23 @@ class NCTrashGridCell: UICollectionViewCell, NCTrashCellProtocol { func selected(_ status: Bool, isEditMode: Bool, account: String) { if isEditMode { + imageSelect.isHidden = false buttonMore.isHidden = true accessibilityCustomActions = nil } else { + imageSelect.isHidden = true buttonMore.isHidden = false + imageVisualEffect.isHidden = true setA11yActions() } if status { + let traitCollectionUserInterfaceStyleDark = traitCollection.userInterfaceStyle == .dark + imageVisualEffect.effect = UIBlurEffect(style: traitCollectionUserInterfaceStyleDark ? .dark : .extraLight) + imageVisualEffect.backgroundColor = traitCollectionUserInterfaceStyleDark ? .black : .lightGray imageSelect.image = NCImageCache.shared.getImageCheckedYes() - imageSelect.isHidden = false imageVisualEffect.isHidden = false } else { - imageSelect.isHidden = true - imageVisualEffect.isHidden = true + imageSelect.image = NCImageCache.shared.getImageCheckedNo() } } @@ -121,8 +165,7 @@ class NCTrashGridCell: UICollectionViewCell, NCTrashCellProtocol { dateFormatter.timeStyle = .none dateFormatter.locale = Locale.current - labelInfo.text = dateFormatter.string(from: date as Date) - labelSubinfo.text = NCUtilityFileSystem().transformedSize(size) + labelInfo.text = dateFormatter.string(from: date as Date) + " · " + NCUtilityFileSystem().transformedSize(size) } func setAccessibility(label: String, value: String) { @@ -130,59 +173,3 @@ class NCTrashGridCell: UICollectionViewCell, NCTrashCellProtocol { accessibilityValue = value } } - -// MARK: - Grid Layout - -class NCTrashGridLayout: UICollectionViewFlowLayout { - - var heightLabelPlusButton: CGFloat = 60 - var marginLeftRight: CGFloat = 10 - var itemForLine: CGFloat = 3 - var itemWidthDefault: CGFloat = 140 - - // MARK: - View Life Cycle - - override init() { - super.init() - - sectionHeadersPinToVisibleBounds = false - - minimumInteritemSpacing = 1 - minimumLineSpacing = marginLeftRight - - self.scrollDirection = .vertical - self.sectionInset = UIEdgeInsets(top: 10, left: marginLeftRight, bottom: 0, right: marginLeftRight) - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override var itemSize: CGSize { - get { - if let collectionView = collectionView { - - if collectionView.frame.width < 400 { - itemForLine = 3 - } else { - itemForLine = collectionView.frame.width / itemWidthDefault - } - - let itemWidth: CGFloat = (collectionView.frame.width - marginLeftRight * 2 - marginLeftRight * (itemForLine - 1)) / itemForLine - let itemHeight: CGFloat = itemWidth + heightLabelPlusButton - - return CGSize(width: itemWidth, height: itemHeight) - } - - // Default fallback - return CGSize(width: itemWidthDefault, height: itemWidthDefault) - } - set { - super.itemSize = newValue - } - } - - override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint { - return proposedContentOffset - } -} diff --git a/iOSClient/Trash/Cell/NCTrashGridCell.xib b/iOSClient/Trash/Cell/NCTrashGridCell.xib index 607f2744c6..91bd5f805d 100644 --- a/iOSClient/Trash/Cell/NCTrashGridCell.xib +++ b/iOSClient/Trash/Cell/NCTrashGridCell.xib @@ -1,9 +1,9 @@ - - + + - + @@ -11,140 +11,130 @@ - - + + - + - - + + - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + - - - - - - - + + + + + + + + + + - + - - + - - - - - - - + diff --git a/iOSClient/Trash/Cell/NCTrashListCell.swift b/iOSClient/Trash/Cell/NCTrashListCell.swift index 56cf6fa63c..84da207e68 100644 --- a/iOSClient/Trash/Cell/NCTrashListCell.swift +++ b/iOSClient/Trash/Cell/NCTrashListCell.swift @@ -46,6 +46,8 @@ class NCTrashListCell: UICollectionViewCell, NCTrashCellProtocol { weak var delegate: NCTrashListCellDelegate? var objectId = "" var account = "" + var indexPath = IndexPath() + let utility = NCUtility() override func awakeFromNib() { super.awakeFromNib() @@ -72,8 +74,11 @@ class NCTrashListCell: UICollectionViewCell, NCTrashCellProtocol { ] - imageRestore.image = NCUtility().loadImage(named: "arrow.circlepath", colors: [NCBrandColor.shared.iconImageColor]) - imageMore.image = NCUtility().loadImage(named: "trash", colors: [.red]) + imageRestore.image = utility.loadImage(named: "restore", colors: [NCBrandColor.shared.iconColor]) + + imageMore.image = UIImage(systemName: "trash") + imageMore.tintColor = NCBrandColor.shared.iconColor + imageItem.layer.cornerRadius = 6 imageItem.layer.masksToBounds = true @@ -108,8 +113,11 @@ class NCTrashListCell: UICollectionViewCell, NCTrashCellProtocol { } if status { var blurEffectView: UIView? - blurEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterial)) - blurEffectView?.backgroundColor = .lightGray + var blurEffect: UIVisualEffect? + let traitCollectionUserInterfaceStyleDark = traitCollection.userInterfaceStyle == .dark + blurEffect = UIBlurEffect(style: traitCollectionUserInterfaceStyleDark ? .dark : .extraLight) + blurEffectView = UIVisualEffectView(effect: blurEffect) + blurEffectView?.backgroundColor = traitCollectionUserInterfaceStyleDark ? .black : .lightGray blurEffectView?.frame = self.bounds blurEffectView?.autoresizingMask = [.flexibleWidth, .flexibleHeight] imageSelect.image = NCImageCache.shared.getImageCheckedYes() diff --git a/iOSClient/Trash/NCTrash+CollectionView.swift b/iOSClient/Trash/NCTrash+CollectionView.swift index d784f776a8..0b82a3f95d 100644 --- a/iOSClient/Trash/NCTrash+CollectionView.swift +++ b/iOSClient/Trash/NCTrash+CollectionView.swift @@ -23,19 +23,23 @@ import UIKit import RealmSwift +import Foundation // MARK: UICollectionViewDelegate extension NCTrash: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - guard let resultTableTrash = datasource?[indexPath.item] else { return } + let resultTableTrash = datasource[indexPath.item] + guard !isEditMode else { - if let index = selectOcId.firstIndex(of: resultTableTrash.fileId) { - selectOcId.remove(at: index) + if let index = fileSelect.firstIndex(of: resultTableTrash.fileId) { + fileSelect.remove(at: index) } else { - selectOcId.append(resultTableTrash.fileId) + fileSelect.append(resultTableTrash.fileId) } collectionView.reloadItems(at: [indexPath]) - tabBarSelect.update(selectOcId: selectOcId) + tabBarSelect.update(selectOcId: fileSelect) + setNavigationRightItems() return } @@ -51,8 +55,12 @@ extension NCTrash: UICollectionViewDelegate { // MARK: UICollectionViewDataSource extension NCTrash: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return datasource?.count ?? 0 + let numberOfItems = datasource.count + emptyDataSet?.numberOfItemsInSection(numberOfItems, section: section) + setNavigationRightItems() + return numberOfItems } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { @@ -65,18 +73,18 @@ extension NCTrash: UICollectionViewDataSource { cell = listCell } else { let gridCell = (collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as? NCTrashGridCell)! - gridCell.setButtonMore(image: NCImageCache.shared.getImageButtonMore()) + gridCell.setButtonMore(named: NCGlobal.shared.buttonMoreMore, image: NCImageCache.shared.getImageButtonMore()) gridCell.delegate = self cell = gridCell } - guard let resultTableTrash = datasource?[indexPath.item] else { return cell } - + + let resultTableTrash = datasource[indexPath.item] cell.imageItem.contentMode = .scaleAspectFit if resultTableTrash.iconName.isEmpty { image = NCImageCache.shared.getImageFile() } else { - image = NCUtility().loadImage(named: resultTableTrash.iconName, useTypeIconFile: true, account: resultTableTrash.account) + image = UIImage(named: resultTableTrash.iconName) } if let imageIcon = utility.getImage(ocId: resultTableTrash.fileId, etag: resultTableTrash.fileName, ext: NCGlobal.shared.previewExt512) { @@ -89,16 +97,14 @@ extension NCTrash: UICollectionViewDataSource { } } } - cell.account = resultTableTrash.account cell.objectId = resultTableTrash.fileId cell.setupCellUI(tableTrash: resultTableTrash, image: image) cell.selected(selectOcId.contains(resultTableTrash.fileId), isEditMode: isEditMode, account: resultTableTrash.account) - return cell } - func setTextFooter(datasource: Results) -> String { + func setTextFooter(datasource: [tableTrash]) -> String { var folders: Int = 0, foldersText = "" var files: Int = 0, filesText = "" var size: Int64 = 0 @@ -138,19 +144,34 @@ extension NCTrash: UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { if kind == UICollectionView.elementKindSectionHeader { - guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFirstHeaderEmptyData", for: indexPath) as? NCSectionFirstHeaderEmptyData - else { return NCSectionFirstHeaderEmptyData() } - header.emptyImage.image = utility.loadImage(named: "trash", colors: [NCBrandColor.shared.getElement(account: session.account)]) - header.emptyTitle.text = NSLocalizedString("_trash_no_trash_", comment: "") - header.emptyDescription.text = NSLocalizedString("_trash_no_trash_description_", comment: "") + + guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeaderMenu", for: indexPath) as? NCSectionHeaderMenu + else { return UICollectionReusableView() } + + if layoutForView?.layout == NCGlobal.shared.layoutGrid { + header.setImageSwitchList() + header.buttonSwitch.accessibilityLabel = NSLocalizedString("_list_view_", comment: "") + } else { + header.setImageSwitchGrid() + header.buttonSwitch.accessibilityLabel = NSLocalizedString("_grid_view_", comment: "") + } + + header.delegate = self + header.setStatusButtonsView(enable: !datasource.isEmpty) + header.setSortedTitle(layoutForView?.titleButtonHeader ?? "") + header.setButtonsView(height: NCGlobal.shared.heightButtonsView) + header.setRichWorkspaceHeight(0) + header.setSectionHeight(0) + header.setViewTransfer(isHidden: true) + return header + } else { guard let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as? NCSectionFooter - else { return NCSectionFooter() } - if let datasource { - footer.setTitleLabel(setTextFooter(datasource: datasource)) - footer.separatorIsHidden(true) - } + else { return UICollectionReusableView() } + footer.setTitleLabel(setTextFooter(datasource: datasource)) + footer.separatorIsHidden(true) + return footer } } @@ -158,13 +179,15 @@ extension NCTrash: UICollectionViewDataSource { // MARK: UICollectionViewDelegateFlowLayout extension NCTrash: UICollectionViewDelegateFlowLayout { + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { - var height: Double = 0 - if let datasource, datasource.isEmpty { - height = utility.getHeightHeaderEmptyData(view: view, portraitOffset: 0, landscapeOffset: 0) + if datasource.isEmpty { + let height = utility.getHeightHeaderEmptyData(view: view, portraitOffset: 0, landscapeOffset: -20) + return CGSize(width: collectionView.frame.width, height: height) } - return CGSize(width: collectionView.frame.width, height: height) + return CGSize(width: collectionView.frame.width, height: NCGlobal.shared.heightButtonsView) } + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize { return CGSize(width: collectionView.frame.width, height: 85) } diff --git a/iOSClient/Trash/NCTrash.swift b/iOSClient/Trash/NCTrash.swift index a899cf7ceb..bd2a57d4d7 100644 --- a/iOSClient/Trash/NCTrash.swift +++ b/iOSClient/Trash/NCTrash.swift @@ -27,7 +27,7 @@ import UIKit import NextcloudKit import RealmSwift -class NCTrash: UIViewController, NCTrashListCellDelegate, NCTrashGridCellDelegate { +class NCTrash: UIViewController, NCTrashListCellDelegate, NCTrashGridCellDelegate, NCSectionHeaderMenuDelegate, NCEmptyDataSetDelegate { @IBOutlet weak var collectionView: UICollectionView! var filePath = "" @@ -38,18 +38,24 @@ class NCTrash: UIViewController, NCTrashListCellDelegate, NCTrashGridCellDelegat let database = NCManageDatabase.shared let utility = NCUtility() var isEditMode = false - var selectOcId: [String] = [] + var fileSelect: [String] = [] var tabBarSelect: NCTrashSelectTabBar! - var datasource: Results? + var datasource: [tableTrash] = [] var layoutForView: NCDBLayoutForView? var listLayout: NCListLayout! var gridLayout: NCGridLayout! var layoutKey = NCGlobal.shared.layoutViewTrash + var layoutType = NCGlobal.shared.layoutList let refreshControl = UIRefreshControl() var filename: String? var session: NCSession.Session { NCSession.shared.getSession(controller: tabBarController) } + + var serverUrl = "" + var selectableDataSource: [RealmSwiftObject] { datasource } + private let appDelegate = (UIApplication.shared.delegate as? AppDelegate)! + var emptyDataSet: NCEmptyDataSet? // MARK: - View Life Cycle @@ -57,6 +63,7 @@ class NCTrash: UIViewController, NCTrashListCellDelegate, NCTrashGridCellDelegat super.viewDidLoad() tabBarSelect = NCTrashSelectTabBar(tabBarController: tabBarController, delegate: self) + serverUrl = utilityFileSystem.getHomeServer(session: session) view.backgroundColor = .systemBackground self.navigationController?.navigationBar.prefersLargeTitles = true @@ -64,7 +71,7 @@ class NCTrash: UIViewController, NCTrashListCellDelegate, NCTrashGridCellDelegat collectionView.register(UINib(nibName: "NCTrashListCell", bundle: nil), forCellWithReuseIdentifier: "listCell") collectionView.register(UINib(nibName: "NCTrashGridCell", bundle: nil), forCellWithReuseIdentifier: "gridCell") - collectionView.register(UINib(nibName: "NCSectionFirstHeaderEmptyData", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "sectionFirstHeaderEmptyData") + collectionView.register(UINib(nibName: "NCSectionHeaderMenu", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "sectionHeaderMenu") collectionView.register(UINib(nibName: "NCSectionFooter", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "sectionFooter") collectionView.alwaysBounceVertical = true @@ -75,19 +82,26 @@ class NCTrash: UIViewController, NCTrashListCellDelegate, NCTrashGridCellDelegat // Add Refresh Control collectionView.refreshControl = refreshControl - refreshControl.tintColor = NCBrandColor.shared.textColor2 + refreshControl.tintColor = .gray refreshControl.addTarget(self, action: #selector(loadListingTrash), for: .valueChanged) + // Empty + emptyDataSet = NCEmptyDataSet(view: collectionView, offset: NCGlobal.shared.heightButtonsView, delegate: self) + NotificationCenter.default.addObserver(self, selector: #selector(reloadDataSource), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterReloadDataSource), object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(changeLayout(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeLayout), object: nil) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) + appDelegate.activeViewController = self + navigationController?.setNavigationBarAppearance() navigationItem.title = titleCurrentFolder layoutForView = self.database.getLayoutForView(account: session.account, key: NCGlobal.shared.layoutViewTrash, serverUrl: "") + gridLayout.column = CGFloat(layoutForView?.columnGrid ?? 3) if layoutForView?.layout == NCGlobal.shared.layoutList { collectionView.collectionViewLayout = listLayout @@ -100,6 +114,9 @@ class NCTrash: UIViewController, NCTrashListCellDelegate, NCTrashGridCellDelegat reloadDataSource() loadListingTrash() + + AnalyticsHelper.shared.trackEvent(eventName: .SCREEN_EVENT__DELETED_FILES) + } override func viewWillDisappear(_ animated: Bool) { @@ -108,6 +125,7 @@ class NCTrash: UIViewController, NCTrashListCellDelegate, NCTrashGridCellDelegat // Cancel Queue & Retrieves Properties NCNetworking.shared.downloadThumbnailTrashQueue.cancelAll() dataSourceTask?.cancel() + isEditMode = false } override func viewWillLayoutSubviews() { @@ -119,41 +137,40 @@ class NCTrash: UIViewController, NCTrashListCellDelegate, NCTrashGridCellDelegat } // MARK: - Layout + + @objc func changeLayout(_ notification: NSNotification) { + guard let userInfo = notification.userInfo as NSDictionary?, + let account = userInfo["account"] as? String, + let serverUrl = userInfo["serverUrl"] as? String, + let layoutForView = userInfo["layoutForView"] as? NCDBLayoutForView, + account == session.account, + serverUrl == self.serverUrl + else { return } + + self.layoutForView = self.database.setLayoutForView(layoutForView: layoutForView) + layoutForView.layout = layoutForView.layout + self.layoutType = layoutForView.layout +// self.reloadDataSource() + collectionView.reloadData() - func setNavigationRightItems() { - func createMenuActions() -> [UIMenuElement] { - guard let layoutForView = self.database.getLayoutForView(account: session.account, key: layoutKey, serverUrl: ""), - let datasource else { return [] } - let select = UIAction(title: NSLocalizedString("_select_", comment: ""), image: utility.loadImage(named: "checkmark.circle", colors: [NCBrandColor.shared.iconImageColor]), attributes: datasource.isEmpty ? .disabled : []) { _ in - self.setEditMode(true) - } - let list = UIAction(title: NSLocalizedString("_list_", comment: ""), image: utility.loadImage(named: "list.bullet", colors: [NCBrandColor.shared.iconImageColor]), state: layoutForView.layout == NCGlobal.shared.layoutList ? .on : .off) { _ in - self.onListSelected() - self.setNavigationRightItems() - } - let grid = UIAction(title: NSLocalizedString("_icons_", comment: ""), image: utility.loadImage(named: "square.grid.2x2", colors: [NCBrandColor.shared.iconImageColor]), state: layoutForView.layout == NCGlobal.shared.layoutGrid ? .on : .off) { _ in - self.onGridSelected() - self.setNavigationRightItems() - } - let viewStyleSubmenu = UIMenu(title: "", options: .displayInline, children: [list, grid]) - - return [select, viewStyleSubmenu] + switch layoutForView.layout { + case NCGlobal.shared.layoutList: + self.collectionView.setCollectionViewLayout(self.listLayout, animated: true) + case NCGlobal.shared.layoutGrid: + self.collectionView.setCollectionViewLayout(self.gridLayout, animated: true) + default: + break } - if isEditMode { - tabBarSelect.update(selectOcId: selectOcId) - tabBarSelect.show() - let select = UIBarButtonItem(title: NSLocalizedString("_cancel_", comment: ""), style: .done) { - self.setEditMode(false) - } - navigationItem.rightBarButtonItems = [select] - } else if navigationItem.rightBarButtonItems == nil || (!isEditMode && !tabBarSelect.isHidden()) { - tabBarSelect.hide() - let menu = UIBarButtonItem(image: utility.loadImage(named: "ellipsis.circle", colors: [NCBrandColor.shared.iconImageColor]), menu: UIMenu(children: createMenuActions())) - navigationItem.rightBarButtonItems = [menu] - } else { - navigationItem.rightBarButtonItems?.first?.menu = navigationItem.rightBarButtonItems?.first?.menu?.replacingChildren(createMenuActions()) - } + self.collectionView.collectionViewLayout.invalidateLayout() + } + + // MARK: - Empty + + func emptyDataSetView(_ view: NCEmptyView) { + view.emptyImage.image = UIImage(named: "trash")?.image(color: .gray, size: UIScreen.main.bounds.width) + view.emptyTitle.text = NSLocalizedString("_trash_no_trash_", comment: "") + view.emptyDescription.text = NSLocalizedString("_trash_no_trash_description_", comment: "") } // MARK: TAP EVENT @@ -188,6 +205,20 @@ class NCTrash: UIViewController, NCTrashListCellDelegate, NCTrashGridCellDelegat } } + func tapButtonSwitch(_ sender: Any) { + if layoutForView?.layout == NCGlobal.shared.layoutGrid { + onListSelected() + } else { + onGridSelected() + } + } + + func tapButtonOrder(_ sender: Any) { + + let sortMenu = NCSortMenu() + sortMenu.toggleMenu(viewController: self, account: session.account, key: layoutKey, sortButton: sender as? UIButton, serverUrl: serverUrl) + } + func longPressGridItem(with objectId: String, gestureRecognizer: UILongPressGestureRecognizer) { } func longPressMoreGridItem(with objectId: String, gestureRecognizer: UILongPressGestureRecognizer) { } @@ -195,11 +226,20 @@ class NCTrash: UIViewController, NCTrashListCellDelegate, NCTrashGridCellDelegat // MARK: - DataSource @objc func reloadDataSource(withQueryDB: Bool = true) { - datasource = self.database.getResultsTrash(filePath: getFilePath(), account: session.account) + datasource.removeAll() + guard var trashItems = NCManageDatabase.shared.getTrash(filePath: getFilePath(), sort: layoutForView?.sort, ascending: layoutForView?.ascending, account: session.account) else { + return + } + if layoutForView?.directoryOnTop ?? true { + trashItems = trashItems.sorted { + return $0.directory && !$1.directory + } + } + datasource = trashItems collectionView.reloadData() setNavigationRightItems() - guard let blinkFileId, let datasource else { return } + guard let blinkFileId = blinkFileId else { return } for itemIx in 0..