123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- //
- // NCPhotoCell.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 13/07/2024.
- // Copyright © 2024 Marino Faggiana. All rights reserved.
- //
- // Author Marino Faggiana <marino.faggiana@nextcloud.com>
- //
- // 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 <http://www.gnu.org/licenses/>.
- //
- 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)
- }
|