// // NCPhotoCell.swift // Nextcloud // // Created by Marino Faggiana on 13/07/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 . // import UIKit class NCPhotoCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProtocol { @IBOutlet weak var imageItem: UIImageView! @IBOutlet weak var imageSelect: UIImageView! @IBOutlet weak var imageStatus: UIImageView! @IBOutlet weak var buttonMore: UIButton! @IBOutlet weak var imageVisualEffect: UIVisualEffectView! var ocId = "" var ocIdTransfer = "" var user = "" weak var photoCellDelegate: NCPhotoCellDelegate? var fileOcId: String? { get { return ocId } set { ocId = newValue ?? "" } } var fileOcIdTransfer: String? { get { return ocIdTransfer } set { ocIdTransfer = newValue ?? "" } } var filePreviewImageView: UIImageView? { get { return imageItem } set { imageItem = newValue } } var fileUser: String? { get { return user } set { user = newValue ?? "" } } var fileStatusImage: UIImageView? { get { return imageStatus } set { imageStatus = newValue } } override func awakeFromNib() { super.awakeFromNib() initCell() } override func prepareForReuse() { super.prepareForReuse() initCell() } func initCell() { accessibilityHint = nil accessibilityLabel = nil accessibilityValue = nil imageItem.image = nil imageSelect.isHidden = true imageSelect.image = NCImageCache.shared.getImageCheckedYes() imageStatus.image = nil imageVisualEffect.clipsToBounds = true imageVisualEffect.alpha = 0.5 let longPressedGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPress(gestureRecognizer:))) longPressedGesture.minimumPressDuration = 0.5 longPressedGesture.delegate = self longPressedGesture.delaysTouchesBegan = true self.addGestureRecognizer(longPressedGesture) } override func snapshotView(afterScreenUpdates afterUpdates: Bool) -> UIView? { return nil } @IBAction func touchUpInsideMore(_ sender: Any) { photoCellDelegate?.tapMorePhotoItem(with: ocId, ocIdTransfer: ocIdTransfer, image: imageItem.image, sender: sender) } @objc func longPress(gestureRecognizer: UILongPressGestureRecognizer) { photoCellDelegate?.longPressPhotoItem(with: ocId, ocIdTransfer: ocIdTransfer, gestureRecognizer: gestureRecognizer) } fileprivate func setA11yActions() { self.accessibilityCustomActions = [ UIAccessibilityCustomAction( name: NSLocalizedString("_more_", comment: ""), target: self, selector: #selector(touchUpInsideMore)) ] } func setButtonMore(image: UIImage) { buttonMore.setImage(image, for: .normal) setA11yActions() } func hideButtonMore(_ status: Bool) { buttonMore.isHidden = status } func hideImageStatus(_ status: Bool) { imageStatus.isHidden = status } func selected(_ status: Bool, isEditMode: Bool) { if status { imageSelect.isHidden = false imageVisualEffect.isHidden = false imageSelect.image = NCImageCache.shared.getImageCheckedYes() } else { imageSelect.isHidden = true imageVisualEffect.isHidden = true } } func setAccessibility(label: String, value: String) { accessibilityLabel = label accessibilityValue = value } } protocol NCPhotoCellDelegate: AnyObject { func tapMorePhotoItem(with ocId: String, ocIdTransfer: String, image: UIImage?, sender: Any) func longPressPhotoItem(with objectId: String, ocIdTransfer: String, gestureRecognizer: UILongPressGestureRecognizer) }