Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions iOSClient/Menu/NCTrash+Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,27 @@ 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()
}
),
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
Expand All @@ -67,7 +60,8 @@ extension NCTrash {
self.present(alert, animated: true, completion: nil)
}
)
]
])
return actions
}

func toggleMenuMoreHeader() {
Expand All @@ -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) })
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
181 changes: 181 additions & 0 deletions iOSClient/Trash/Cell/NCTrashGridCell.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading