|
@@ -91,7 +91,8 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
|
|
|
tableView.separatorColor = NCBrandColor.shared.separator
|
|
|
tableView.layer.cornerRadius = 10
|
|
|
tableView.tableFooterView = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 0, height: 1)))
|
|
|
-
|
|
|
+ commandViewHeightConstraint.constant = heightCommandView
|
|
|
+
|
|
|
// Create folder
|
|
|
createFolderView.layer.cornerRadius = 10
|
|
|
createFolderImage.image = NCUtility.shared.loadImage(named: "folder.badge.plus", color: NCBrandColor.shared.label)
|
|
@@ -131,7 +132,7 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
|
|
|
if let activeAccount = NCManageDatabase.shared.getActiveAccount() {
|
|
|
|
|
|
setAccount(account: activeAccount.account)
|
|
|
- getFilesExtensionContext { (filesName, error) in
|
|
|
+ getFilesExtensionContext { (filesName) in
|
|
|
|
|
|
self.filesName = filesName
|
|
|
DispatchQueue.main.async {
|
|
@@ -288,6 +289,8 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
|
|
|
if filesName.count <= 3 {
|
|
|
self.tableView.isScrollEnabled = false
|
|
|
}
|
|
|
+ // Label upload button
|
|
|
+ uploadLabel.text = NSLocalizedString("_upload_", comment: "") + " \(filesName.count) " + NSLocalizedString("_files_", comment: "")
|
|
|
// Empty
|
|
|
emptyDataSet = NCEmptyDataSet.init(view: collectionView, offset: -50*counter, delegate: self)
|
|
|
self.tableView.reloadData()
|
|
@@ -694,9 +697,9 @@ extension NCShareExtension: UITableViewDataSource {
|
|
|
|
|
|
let fileName = filesName[indexPath.row]
|
|
|
let resultInternalType = NCCommunicationCommon.shared.getInternalType(fileName: fileName, mimeType: "", directory: false)
|
|
|
-
|
|
|
+
|
|
|
if let image = UIImage(contentsOfFile: (NSTemporaryDirectory() + fileName)) {
|
|
|
- imageCell?.image = image
|
|
|
+ imageCell?.image = image.resizeImage(size: CGSize(width: 80, height: 80), isAspectRation: true)
|
|
|
} else {
|
|
|
if resultInternalType.iconName.count > 0 {
|
|
|
imageCell?.image = UIImage.init(named: resultInternalType.iconName)
|
|
@@ -771,196 +774,225 @@ extension NCShareExtension {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func getFilesExtensionContext(completion: @escaping (_ filesName: [String], _ error: Error?)->()) {
|
|
|
+ func getFilesExtensionContext(completion: @escaping (_ filesName: [String])->()) {
|
|
|
|
|
|
+ var itemsProvider: [NSItemProvider] = []
|
|
|
var filesName: [String] = []
|
|
|
var conuter = 0
|
|
|
- var outError: Error? = nil
|
|
|
-
|
|
|
- CCUtility.emptyTemporaryDirectory()
|
|
|
+ let dateFormatter = DateFormatter()
|
|
|
+
|
|
|
+ // ----------------------------------------------------------------------------------------
|
|
|
+
|
|
|
+ // Image
|
|
|
+ func getItem(image: UIImage, fileNameOriginal: String?) {
|
|
|
+
|
|
|
+ var fileName: String = ""
|
|
|
+
|
|
|
+ if let pngImageData = image.pngData() {
|
|
|
+
|
|
|
+ if fileNameOriginal != nil {
|
|
|
+ fileName = fileNameOriginal!
|
|
|
+ } else {
|
|
|
+ fileName = "\(dateFormatter.string(from: Date()))\(conuter).png"
|
|
|
+ }
|
|
|
+
|
|
|
+ let filenamePath = NSTemporaryDirectory() + fileName
|
|
|
|
|
|
- if let inputItems : [NSExtensionItem] = extensionContext?.inputItems as? [NSExtensionItem] {
|
|
|
+ if (try? pngImageData.write(to: URL(fileURLWithPath: filenamePath), options: [.atomic])) != nil {
|
|
|
+ filesName.append(fileName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // URL
|
|
|
+ func getItem(url: NSURL, fileNameOriginal: String?) {
|
|
|
|
|
|
- for item : NSExtensionItem in inputItems {
|
|
|
+ guard let path = url.path else { return }
|
|
|
+
|
|
|
+ var fileName: String = ""
|
|
|
+
|
|
|
+ if fileNameOriginal != nil {
|
|
|
+ fileName = fileNameOriginal!
|
|
|
+ } else {
|
|
|
+ if 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: path, toPath:filenamePath)
|
|
|
|
|
|
- if let attachments = item.attachments {
|
|
|
+ do {
|
|
|
+ let attr : NSDictionary? = try FileManager.default.attributesOfItem(atPath: filenamePath) as NSDictionary?
|
|
|
|
|
|
- if attachments.isEmpty {
|
|
|
-
|
|
|
- extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
|
|
|
- completion(filesName, outError)
|
|
|
- return
|
|
|
+ if let _attr = attr {
|
|
|
+ if _attr.fileSize() > 0 {
|
|
|
+ filesName.append(fileName)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- for (index, current) in (attachments.enumerated()) {
|
|
|
+ } catch { }
|
|
|
+ } catch { }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Data
|
|
|
+ func getItem(data: Data, fileNameOriginal: String?, description: String) {
|
|
|
+
|
|
|
+ var fileName: String = ""
|
|
|
+
|
|
|
+ if data.count > 0 {
|
|
|
|
|
|
- if current.hasItemConformingToTypeIdentifier(kUTTypeItem as String) || current.hasItemConformingToTypeIdentifier("public.url") {
|
|
|
-
|
|
|
- var typeIdentifier = ""
|
|
|
- if current.hasItemConformingToTypeIdentifier(kUTTypeItem as String) { typeIdentifier = kUTTypeItem as String }
|
|
|
- if current.hasItemConformingToTypeIdentifier("public.url") { typeIdentifier = "public.url" }
|
|
|
-
|
|
|
- current.loadItem(forTypeIdentifier: typeIdentifier, options: nil, completionHandler: {(item, error) -> Void in
|
|
|
-
|
|
|
- var fileNameOriginal: String?
|
|
|
- var fileName: String = ""
|
|
|
-
|
|
|
- let dateFormatter = DateFormatter()
|
|
|
- dateFormatter.dateFormat = "yyyy-MM-dd HH-mm-ss-"
|
|
|
- conuter += 1
|
|
|
-
|
|
|
- if let url = item as? NSURL {
|
|
|
- if FileManager.default.fileExists(atPath: url.path ?? "") {
|
|
|
- fileNameOriginal = url.lastPathComponent!
|
|
|
- } else if url.scheme?.lowercased().contains("http") == true {
|
|
|
- fileNameOriginal = "\(dateFormatter.string(from: Date()))\(conuter).html"
|
|
|
- } else {
|
|
|
- fileNameOriginal = "\(dateFormatter.string(from: Date()))\(conuter)"
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if error == nil {
|
|
|
-
|
|
|
- if let image = item as? UIImage {
|
|
|
-
|
|
|
- print("item as UIImage")
|
|
|
-
|
|
|
- if let pngImageData = image.pngData() {
|
|
|
-
|
|
|
- if fileNameOriginal != nil {
|
|
|
- fileName = fileNameOriginal!
|
|
|
- } else {
|
|
|
- fileName = "\(dateFormatter.string(from: Date()))\(conuter).png"
|
|
|
- }
|
|
|
-
|
|
|
- let filenamePath = NSTemporaryDirectory() + fileName
|
|
|
-
|
|
|
- let result = (try? pngImageData.write(to: URL(fileURLWithPath: filenamePath), options: [.atomic])) != nil
|
|
|
-
|
|
|
- if result {
|
|
|
- filesName.append(fileName)
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- print("Error image nil")
|
|
|
- }
|
|
|
-
|
|
|
- if index + 1 == attachments.count {
|
|
|
- completion(filesName, outError)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if let url = item as? URL {
|
|
|
-
|
|
|
- let task = URLSession.shared.downloadTask(with: url) { 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()
|
|
|
- }
|
|
|
-
|
|
|
- if let data = item as? Data {
|
|
|
-
|
|
|
- if data.count > 0 {
|
|
|
-
|
|
|
- print("item as NSdata")
|
|
|
-
|
|
|
- if fileNameOriginal != nil {
|
|
|
- fileName = fileNameOriginal!
|
|
|
- } else {
|
|
|
- let description = current.description
|
|
|
- let fullNameArr = description.components(separatedBy: "\"")
|
|
|
- let fileExtArr = fullNameArr[1].components(separatedBy: ".")
|
|
|
- let pathExtention = (fileExtArr[fileExtArr.count-1]).uppercased()
|
|
|
- fileName = "\(dateFormatter.string(from: Date()))\(conuter).\(pathExtention)"
|
|
|
- }
|
|
|
-
|
|
|
- let filenamePath = NSTemporaryDirectory() + fileName
|
|
|
-
|
|
|
- FileManager.default.createFile(atPath: filenamePath, contents:data, attributes:nil)
|
|
|
-
|
|
|
- filesName.append(fileName)
|
|
|
- }
|
|
|
-
|
|
|
- if index + 1 == attachments.count {
|
|
|
- completion(filesName, outError)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if let data = item as? NSString {
|
|
|
-
|
|
|
- if data.length > 0 {
|
|
|
-
|
|
|
- print("item as NSString")
|
|
|
-
|
|
|
- let fileName = "\(dateFormatter.string(from: Date()))\(conuter).txt"
|
|
|
- let filenamePath = NSTemporaryDirectory() + fileName
|
|
|
-
|
|
|
- FileManager.default.createFile(atPath: filenamePath, contents:data.data(using: String.Encoding.utf8.rawValue), attributes:nil)
|
|
|
-
|
|
|
- filesName.append(fileName)
|
|
|
- }
|
|
|
-
|
|
|
- if index + 1 == attachments.count {
|
|
|
- completion(filesName, outError)
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- completion( filesName, error)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- } // end for
|
|
|
+ if fileNameOriginal != nil {
|
|
|
+ fileName = fileNameOriginal!
|
|
|
} else {
|
|
|
- completion(filesName, outError)
|
|
|
+ let fullNameArr = description.components(separatedBy: "\"")
|
|
|
+ let fileExtArr = fullNameArr[1].components(separatedBy: ".")
|
|
|
+ let pathExtention = (fileExtArr[fileExtArr.count-1]).uppercased()
|
|
|
+ fileName = "\(dateFormatter.string(from: Date()))\(conuter).\(pathExtention)"
|
|
|
+ }
|
|
|
+
|
|
|
+ let filenamePath = NSTemporaryDirectory() + fileName
|
|
|
+ FileManager.default.createFile(atPath: filenamePath, contents:data, attributes:nil)
|
|
|
+ filesName.append(fileName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // String
|
|
|
+ func getItem(string: NSString, fileNameOriginal: String?) {
|
|
|
+
|
|
|
+ var fileName: String = ""
|
|
|
+
|
|
|
+ if string.length > 0 {
|
|
|
+
|
|
|
+ fileName = "\(dateFormatter.string(from: Date()))\(conuter).txt"
|
|
|
+ let filenamePath = NSTemporaryDirectory() + "\(dateFormatter.string(from: Date()))\(conuter).txt"
|
|
|
+ FileManager.default.createFile(atPath: filenamePath, contents:string.data(using: String.Encoding.utf8.rawValue), attributes:nil)
|
|
|
+ filesName.append(fileName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // ----------------------------------------------------------------------------------------
|
|
|
+
|
|
|
+ guard let inputItems : [NSExtensionItem] = extensionContext?.inputItems as? [NSExtensionItem] else {
|
|
|
+ return completion(filesName)
|
|
|
+ }
|
|
|
+
|
|
|
+ for item : NSExtensionItem in inputItems {
|
|
|
+ if let attachments = item.attachments {
|
|
|
+ if attachments.isEmpty { continue }
|
|
|
+ for (_, itemProvider) in (attachments.enumerated()) {
|
|
|
+ if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeItem as String) || itemProvider.hasItemConformingToTypeIdentifier("public.url") {
|
|
|
+ itemsProvider.append(itemProvider)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ CCUtility.emptyTemporaryDirectory()
|
|
|
+ dateFormatter.dateFormat = "yyyy-MM-dd HH-mm-ss-"
|
|
|
+
|
|
|
+ for itemProvider in itemsProvider {
|
|
|
+
|
|
|
+ var typeIdentifier = ""
|
|
|
+ if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeItem as String) { typeIdentifier = kUTTypeItem as String }
|
|
|
+ if itemProvider.hasItemConformingToTypeIdentifier("public.url") { typeIdentifier = "public.url" }
|
|
|
+
|
|
|
+ itemProvider.loadItem(forTypeIdentifier: typeIdentifier, options: nil, completionHandler: {(item, error) -> Void in
|
|
|
+
|
|
|
+ if error == nil {
|
|
|
+
|
|
|
+ var fileNameOriginal: String?
|
|
|
+
|
|
|
+ if let url = item as? NSURL {
|
|
|
+ if FileManager.default.fileExists(atPath: url.path ?? "") {
|
|
|
+ fileNameOriginal = url.lastPathComponent!
|
|
|
+ } else if url.scheme?.lowercased().contains("http") == true {
|
|
|
+ fileNameOriginal = "\(dateFormatter.string(from: Date()))\(conuter).html"
|
|
|
+ } else {
|
|
|
+ fileNameOriginal = "\(dateFormatter.string(from: Date()))\(conuter)"
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if let image = item as? UIImage {
|
|
|
+ getItem(image: image, fileNameOriginal: fileNameOriginal)
|
|
|
+ }
|
|
|
+
|
|
|
+ if let url = item as? URL {
|
|
|
+ getItem(url: url as NSURL, fileNameOriginal: fileNameOriginal)
|
|
|
+ }
|
|
|
+
|
|
|
+ if let data = item as? Data {
|
|
|
+ getItem(data: data, fileNameOriginal: fileNameOriginal, description: itemProvider.description)
|
|
|
+ }
|
|
|
+
|
|
|
+ if let string = item as? NSString {
|
|
|
+ getItem(string: string, fileNameOriginal: fileNameOriginal)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ conuter += 1
|
|
|
+ if conuter == itemsProvider.count {
|
|
|
+ completion(filesName)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+let task = URLSession.shared.downloadTask(with: urlitem) { localURL, urlResponse, error in
|
|
|
+
|
|
|
+ if let localURL = localURL {
|
|
|
+
|
|
|
+ if fileNameOriginal != nil {
|
|
|
+ fileName = fileNameOriginal!
|
|
|
} else {
|
|
|
- completion(filesName, outError)
|
|
|
+ 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?
|