diff --git a/iOSClient/Menu/NCTrash+Menu.swift b/iOSClient/Menu/NCTrash+Menu.swift index faf37f86ea..eab0d422e3 100644 --- a/iOSClient/Menu/NCTrash+Menu.swift +++ b/iOSClient/Menu/NCTrash+Menu.swift @@ -29,26 +29,19 @@ import NextcloudKit extension NCTrash { var selectActions: [NCMenuAction] { - [ - NCMenuAction( - title: NSLocalizedString("_cancel_", comment: ""), - icon: utility.loadImage(named: "xmark"), - action: { _ in - self.tapSelect() - } - ), - NCMenuAction( - title: NSLocalizedString("_select_all_", comment: ""), - icon: utility.loadImage(named: "checkmark.circle.fill"), - action: { _ in - self.selectOcId = self.datasource.map { $0.fileId } - self.collectionView.reloadData() - } - ), - NCMenuAction.seperator(), + var actions = [NCMenuAction]() + actions.append(.cancelAction { + self.tapSelect() + }) + if selectOcId.count != selectableDataSource.count { + actions.append(.selectAllAction(action: collectionViewSelectAll)) + } + + guard !selectOcId.isEmpty else { return actions } + actions.append(contentsOf: [ NCMenuAction( title: NSLocalizedString("_trash_restore_selected_", comment: ""), - icon: utility.loadImage(named: "restore"), + icon: utility.loadImage(named: "restore").image(color: NCBrandColor.shared.iconColor, size: 50), action: { _ in self.selectOcId.forEach(self.restoreItem) self.tapSelect() @@ -56,7 +49,7 @@ extension NCTrash { ), NCMenuAction( title: NSLocalizedString("_trash_delete_selected_", comment: ""), - icon: utility.loadImage(named: "trash"), + icon: utility.loadImage(named: "trash").image(color: NCBrandColor.shared.iconColor, size: 50), action: { _ in let alert = UIAlertController(title: NSLocalizedString("_trash_delete_selected_", comment: ""), message: "", preferredStyle: .alert) alert.addAction(UIAlertAction(title: NSLocalizedString("_delete_", comment: ""), style: .destructive, handler: { _ in @@ -67,7 +60,8 @@ extension NCTrash { self.present(alert, animated: true, completion: nil) } ) - ] + ]) + return actions } func toggleMenuMoreHeader() { @@ -77,7 +71,7 @@ extension NCTrash { actions.append( NCMenuAction( title: NSLocalizedString("_trash_restore_all_", comment: ""), - icon: utility.loadImage(named: "restore"), + icon: utility.loadImage(named: "restore").image(color: NCBrandColor.shared.iconColor, size: 50), action: { _ in self.datasource.forEach({ self.restoreItem(with: $0.fileId) }) } @@ -87,7 +81,7 @@ extension NCTrash { actions.append( NCMenuAction( title: NSLocalizedString("_trash_delete_all_", comment: ""), - icon: utility.loadImage(named: "trash"), + icon: utility.loadImage(named: "trash").image(color: NCBrandColor.shared.iconColor, size: 50), action: { _ in let alert = UIAlertController(title: NSLocalizedString("_trash_delete_all_description_", comment: ""), message: "", preferredStyle: .alert) alert.addAction(UIAlertAction(title: NSLocalizedString("_trash_delete_all_", comment: ""), style: .destructive, handler: { _ in @@ -125,7 +119,7 @@ extension NCTrash { iconHeader = icon } else { if tableTrash.directory { - iconHeader = UIImage(named: "folder")!.image(color: UIColor.systemGray, size: 50) + iconHeader = UIImage(named: "folder") } else { iconHeader = UIImage(named: tableTrash.iconName) } @@ -142,7 +136,7 @@ extension NCTrash { actions.append( NCMenuAction( title: NSLocalizedString("_restore_", comment: ""), - icon: UIImage(named: "restore")!.image(color: UIColor.systemGray, size: 50), + icon: UIImage(named: "restore")!.image(color: NCBrandColor.shared.iconColor, size: 50), action: { _ in self.restoreItem(with: objectId) } @@ -152,7 +146,7 @@ extension NCTrash { actions.append( NCMenuAction( title: NSLocalizedString("_delete_", comment: ""), - icon: utility.loadImage(named: "trash"), + icon: utility.loadImage(named: "trash").image(color: NCBrandColor.shared.iconColor, size: 50), action: { _ in self.deleteItem(with: objectId) } diff --git a/iOSClient/Trash/Cell/NCTrashGridCell.swift b/iOSClient/Trash/Cell/NCTrashGridCell.swift new file mode 100644 index 0000000000..77e798f02a --- /dev/null +++ b/iOSClient/Trash/Cell/NCTrashGridCell.swift @@ -0,0 +1,181 @@ +// +// NCTrashGridCell.swift +// Nextcloud +// +// Created by A200073704 on 27/06/23. +// Copyright © 2023 Marino Faggiana. All rights reserved. +// + +import UIKit + +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 buttonMore: UIButton! + @IBOutlet weak var imageVisualEffect: UIVisualEffectView! + @IBOutlet weak var progressView: UIProgressView! + + internal var objectId = "" + var indexPath = IndexPath() + private var user = "" + + weak var delegate: NCGridCellDelegate? + 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() + + // use entire cell as accessibility element + accessibilityHint = nil + accessibilityLabel = nil + accessibilityValue = nil + isAccessibilityElement = true + + imageItem.layer.cornerRadius = 6 + imageItem.layer.masksToBounds = true + + imageVisualEffect.layer.cornerRadius = 6 + 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 = "" + labelTitle.textColor = .label + labelInfo.textColor = .systemGray + } + + override func prepareForReuse() { + super.prepareForReuse() + imageItem.backgroundColor = nil + accessibilityHint = nil + accessibilityLabel = nil + accessibilityValue = nil + } + + override func snapshotView(afterScreenUpdates afterUpdates: Bool) -> UIView? { + return nil + } + + @IBAction func touchUpInsideMore(_ sender: Any) { + delegate?.tapMoreGridItem(with: objectId, namedButtonMore: namedButtonMore, image: imageItem.image, indexPath: indexPath, sender: sender) + } + + + fileprivate func setA11yActions() { + let moreName = namedButtonMore == NCGlobal.shared.buttonMoreStop ? "_cancel_" : "_more_" + + self.accessibilityCustomActions = [ + UIAccessibilityCustomAction( + name: NSLocalizedString(moreName, comment: ""), + target: self, + selector: #selector(touchUpInsideMore)) + ] + } + + func setButtonMore(named: String, image: UIImage) { + namedButtonMore = named + buttonMore.setImage(image, for: .normal) + setA11yActions() + } + + func hideButtonMore(_ status: Bool) { + buttonMore.isHidden = status + } + + func selectMode(_ status: Bool) { + if status { + imageSelect.isHidden = false + buttonMore.isHidden = true + accessibilityCustomActions = nil + } else { + imageSelect.isHidden = true + imageVisualEffect.isHidden = true + buttonMore.isHidden = false + setA11yActions() + } + } + + func selected(_ status: Bool) { + if status { + if traitCollection.userInterfaceStyle == .dark { + imageVisualEffect.effect = UIBlurEffect(style: .dark) + imageVisualEffect.backgroundColor = .black + } else { + imageVisualEffect.effect = UIBlurEffect(style: .extraLight) + imageVisualEffect.backgroundColor = .lightGray + } + imageSelect.image = NCImageCache.images.checkedYes + imageVisualEffect.isHidden = false + } else { + imageSelect.image = NCImageCache.images.checkedNo + imageVisualEffect.isHidden = true + } + } + + func writeInfoDateSize(date: NSDate, size: Int64) { + + let dateFormatter = DateFormatter() + dateFormatter.dateStyle = .short + dateFormatter.timeStyle = .none + dateFormatter.locale = Locale.current + + labelInfo.text = dateFormatter.string(from: date as Date) + " · " + NCUtilityFileSystem().transformedSize(size) + } + + func setAccessibility(label: String, value: String) { + accessibilityLabel = label + accessibilityValue = value + } +} diff --git a/iOSClient/Trash/Cell/NCTrashGridCell.xib b/iOSClient/Trash/Cell/NCTrashGridCell.xib new file mode 100644 index 0000000000..91bd5f805d --- /dev/null +++ b/iOSClient/Trash/Cell/NCTrashGridCell.xib @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSClient/Trash/NCTrash+CollectionView.swift b/iOSClient/Trash/NCTrash+CollectionView.swift index 45f39b20da..41634979b2 100644 --- a/iOSClient/Trash/NCTrash+CollectionView.swift +++ b/iOSClient/Trash/NCTrash+CollectionView.swift @@ -84,7 +84,7 @@ extension NCTrash: UICollectionViewDataSource { cell = listCell } else { // GRID - guard let gridCell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as? NCGridCell else { return UICollectionViewCell() } + guard let gridCell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as? NCTrashGridCell else { return UICollectionViewCell() } gridCell.setButtonMore(named: NCGlobal.shared.buttonMoreMore, image: NCImageCache.images.buttonMore) gridCell.delegate = self cell = gridCell diff --git a/iOSClient/Trash/NCTrash.swift b/iOSClient/Trash/NCTrash.swift index 33d2b77dbc..56ea97b7fa 100644 --- a/iOSClient/Trash/NCTrash.swift +++ b/iOSClient/Trash/NCTrash.swift @@ -62,7 +62,7 @@ class NCTrash: UIViewController, NCSelectableNavigationView, NCTrashListCellDele // Cell collectionView.register(UINib(nibName: "NCTrashListCell", bundle: nil), forCellWithReuseIdentifier: "listCell") - collectionView.register(UINib(nibName: "NCGridCell", bundle: nil), forCellWithReuseIdentifier: "gridCell") + collectionView.register(UINib(nibName: "NCTrashGridCell", bundle: nil), forCellWithReuseIdentifier: "gridCell") // Header - Footer collectionView.register(UINib(nibName: "NCSectionHeaderMenu", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "sectionHeaderMenu")