|
@@ -27,7 +27,7 @@ import UIKit
|
|
|
import NCCommunication
|
|
|
import IHProgressHUD
|
|
|
|
|
|
-class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDelegate, NCRenameFileDelegate, NCAccountRequestDelegate {
|
|
|
+class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDelegate, NCAccountRequestDelegate {
|
|
|
|
|
|
@IBOutlet weak var collectionView: UICollectionView!
|
|
|
@IBOutlet weak var tableView: UITableView!
|
|
@@ -493,16 +493,6 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func rename(fileName: String, fileNameNew: String) {
|
|
|
- guard let fileIx = self.filesName.firstIndex(where: { $0 == fileName }),
|
|
|
- !self.filesName.contains(fileNameNew),
|
|
|
- NCUtilityFileSystem.shared.moveFile(atPath: (NSTemporaryDirectory() + fileName), toPath: (NSTemporaryDirectory() + fileNameNew))
|
|
|
- else { return }
|
|
|
-
|
|
|
- filesName[fileIx] = fileNameNew
|
|
|
- tableView.reloadData()
|
|
|
- }
|
|
|
-
|
|
|
func accountRequestChangeAccount(account: String) {
|
|
|
setAccount(account: account)
|
|
|
}
|
|
@@ -651,6 +641,18 @@ extension NCShareExtension: UITableViewDelegate {
|
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
+ let fileName = filesName[indexPath.row]
|
|
|
+
|
|
|
+ guard let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile else { return }
|
|
|
+
|
|
|
+ let resultInternalType = NCCommunicationCommon.shared.getInternalType(fileName: fileName, mimeType: "", directory: false)
|
|
|
+ vcRename.delegate = self
|
|
|
+ vcRename.fileName = fileName
|
|
|
+ let img = UIImage(contentsOfFile: (NSTemporaryDirectory() + fileName)) ?? UIImage(named: resultInternalType.iconName) ?? NCBrandColor.cacheImages.file
|
|
|
+ vcRename.imagePreview = img
|
|
|
+ let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height)
|
|
|
+
|
|
|
+ self.present(popup, animated: true)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -662,77 +664,36 @@ extension NCShareExtension: UITableViewDataSource {
|
|
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
|
|
|
- let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
|
|
|
- cell.backgroundColor = NCBrandColor.shared.systemBackground
|
|
|
-
|
|
|
- let imageCell = cell.viewWithTag(10) as? UIImageView
|
|
|
- let fileNameCell = cell.viewWithTag(20) as? UILabel
|
|
|
- let moreButton = cell.viewWithTag(30) as? NCShareExtensionButtonWithIndexPath
|
|
|
- let sizeCell = cell.viewWithTag(40) as? UILabel
|
|
|
-
|
|
|
- imageCell?.layer.cornerRadius = 6
|
|
|
- imageCell?.layer.masksToBounds = true
|
|
|
-
|
|
|
+ guard let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as? NCShareCell else { return UITableViewCell() }
|
|
|
let fileName = filesName[indexPath.row]
|
|
|
- let resultInternalType = NCCommunicationCommon.shared.getInternalType(fileName: fileName, mimeType: "", directory: false)
|
|
|
+ cell.setup(fileName: fileName)
|
|
|
+ cell.delegate = self
|
|
|
+ cell.moreButton?.isHidden = filesName.count < 2
|
|
|
+
|
|
|
+ return cell
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- if let image = UIImage(contentsOfFile: (NSTemporaryDirectory() + fileName)) {
|
|
|
- imageCell?.image = image.resizeImage(size: CGSize(width: 80, height: 80), isAspectRation: true)
|
|
|
+extension NCShareExtension: NCShareCellDelegate, NCRenameFileDelegate {
|
|
|
+ func removeFile(named fileName: String) {
|
|
|
+ print(#line, self.filesName.firstIndex(of: fileName), fileName)
|
|
|
+ guard let index = self.filesName.firstIndex(of: fileName) else { return }
|
|
|
+ self.filesName.remove(at: index)
|
|
|
+ if self.filesName.count == 0 {
|
|
|
+ self.extensionContext?.completeRequest(returningItems: self.extensionContext?.inputItems, completionHandler: nil)
|
|
|
} else {
|
|
|
- if resultInternalType.iconName.count > 0 {
|
|
|
- imageCell?.image = UIImage(named: resultInternalType.iconName)
|
|
|
- } else {
|
|
|
- imageCell?.image = NCBrandColor.cacheImages.file
|
|
|
- }
|
|
|
+ self.setCommandView()
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- 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: NCBrandColor.shared.label, size: 15), for: .normal)
|
|
|
- moreButton?.indexPath = indexPath
|
|
|
- moreButton?.fileName = fileName
|
|
|
- moreButton?.image = imageCell?.image
|
|
|
- moreButton?.action(for: .touchUpInside, { sender in
|
|
|
-
|
|
|
- if let fileName = (sender as! NCShareExtensionButtonWithIndexPath).fileName {
|
|
|
- let alertController = UIAlertController(title: "", message: fileName, preferredStyle: .alert)
|
|
|
-
|
|
|
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_delete_file_", comment: ""), style: .default) { (_: UIAlertAction) in
|
|
|
- if let index = self.filesName.firstIndex(of: fileName) {
|
|
|
-
|
|
|
- self.filesName.remove(at: index)
|
|
|
- if self.filesName.count == 0 {
|
|
|
- self.extensionContext?.completeRequest(returningItems: self.extensionContext?.inputItems, completionHandler: nil)
|
|
|
- } else {
|
|
|
- self.setCommandView()
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_rename_file_", comment: ""), style: .default) { (_: UIAlertAction) in
|
|
|
-
|
|
|
- if let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile {
|
|
|
-
|
|
|
- vcRename.delegate = self
|
|
|
- vcRename.fileName = fileName
|
|
|
- vcRename.imagePreview = (sender as! NCShareExtensionButtonWithIndexPath).image
|
|
|
-
|
|
|
- let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height)
|
|
|
-
|
|
|
- self.present(popup, animated: true)
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { (_: UIAlertAction) in })
|
|
|
-
|
|
|
- self.present(alertController, animated: true, completion: nil)
|
|
|
- }
|
|
|
- })
|
|
|
+ func rename(fileName: String, fileNameNew: String) {
|
|
|
+ guard let fileIx = self.filesName.firstIndex(of: fileName),
|
|
|
+ !self.filesName.contains(fileNameNew),
|
|
|
+ NCUtilityFileSystem.shared.moveFile(atPath: (NSTemporaryDirectory() + fileName), toPath: (NSTemporaryDirectory() + fileNameNew))
|
|
|
+ else { return }
|
|
|
|
|
|
- return cell
|
|
|
+ filesName[fileIx] = fileNameNew
|
|
|
+ tableView.reloadData()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -968,60 +929,6 @@ extension NCShareExtension {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
-let task = URLSession.shared.downloadTask(with: urlitem) { localURL, urlResponse, error in
|
|
|
-
|
|
|
- if let localURL = localURL {
|
|
|
-
|
|
|
- if fileNameOriginal != nil {
|
|
|
- fileName = fileNameOriginal!
|
|
|
- } else {
|
|
|
- let ext = url.pathExtension
|
|
|
- fileName = "\(dateFormatter.string(from: Date()))\(conuter)." + ext
|
|
|
- }
|
|
|
-
|
|
|
- let filenamePath = NSTemporaryDirectory() + fileName
|
|
|
-
|
|
|
- do {
|
|
|
- try FileManager.default.removeItem(atPath: filenamePath)
|
|
|
- }
|
|
|
- catch { }
|
|
|
-
|
|
|
- do {
|
|
|
- try FileManager.default.copyItem(atPath: localURL.path, toPath:filenamePath)
|
|
|
-
|
|
|
- do {
|
|
|
- let attr : NSDictionary? = try FileManager.default.attributesOfItem(atPath: filenamePath) as NSDictionary?
|
|
|
-
|
|
|
- if let _attr = attr {
|
|
|
- if _attr.fileSize() > 0 {
|
|
|
-
|
|
|
- filesName.append(fileName)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } catch let error {
|
|
|
- outError = error
|
|
|
- }
|
|
|
-
|
|
|
- } catch let error {
|
|
|
- outError = error
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if index + 1 == attachments.count {
|
|
|
- completion(filesName, outError)
|
|
|
- }
|
|
|
-}
|
|
|
-task.resume()
|
|
|
-*/
|
|
|
-
|
|
|
-class NCShareExtensionButtonWithIndexPath: UIButton {
|
|
|
- var indexPath: IndexPath?
|
|
|
- var fileName: String?
|
|
|
- var image: UIImage?
|
|
|
-}
|
|
|
-
|
|
|
extension NCShareExtension: NCCreateFormUploadConflictDelegate {
|
|
|
func dismissCreateFormUploadConflict(metadatas: [tableMetadata]?) {
|
|
|
metadatas?.forEach { self.upload($0) }
|