12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import UIKit
- import NextcloudKit
- protocol NCShareCellDelegate: AnyObject {
- var uploadStarted: Bool { get }
- func removeFile(named fileName: String)
- func renameFile(named fileName: String)
- }
- class NCShareCell: UITableViewCell {
- @IBOutlet weak var imageCell: UIImageView!
- @IBOutlet weak var fileNameCell: UILabel!
- @IBOutlet weak var moreButton: UIButton!
- @IBOutlet weak var sizeCell: UILabel!
- weak var delegate: (NCShareCellDelegate & UIViewController)?
- var fileName = ""
- func setup(fileName: String) {
- self.fileName = fileName
- let resultInternalType = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: fileName, mimeType: "", directory: false)
- backgroundColor = .systemBackground
- imageCell?.layer.cornerRadius = 6
- imageCell?.layer.masksToBounds = true
- if let image = UIImage.downsample(imageAt: URL(fileURLWithPath: NSTemporaryDirectory() + fileName), to: CGSize(width: 80, height: 80)) {
- imageCell.image = image
- } else {
- if !resultInternalType.iconName.isEmpty {
- imageCell?.image = UIImage(named: resultInternalType.iconName)
- } else {
- imageCell?.image = NCBrandColor.cacheImages.file
- }
- }
- fileNameCell?.text = fileName
- let fileSize = NCUtilityFileSystem.shared.getFileSize(filePath: (NSTemporaryDirectory() + fileName))
- sizeCell?.text = CCUtility.transformedSize(fileSize)
- moreButton?.setImage(NCUtility.shared.loadImage(named: "more").image(color: .label, size: 15), for: .normal)
- }
- @IBAction func buttonTapped(_ sender: Any) {
- guard !fileName.isEmpty, delegate?.uploadStarted != true else { return }
- let alertController = UIAlertController(title: "", message: fileName, preferredStyle: .alert)
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_rename_file_", comment: ""), style: .default) { _ in
- self.delegate?.renameFile(named: self.fileName)
- })
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_file_", comment: ""), style: .default) { _ in
- self.delegate?.removeFile(named: self.fileName)
- })
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { _ in })
- delegate?.present(alertController, animated: true, completion: nil)
- }
- }
|