|
@@ -137,9 +137,8 @@ class NCShareExtension: UIViewController {
|
|
|
}
|
|
|
|
|
|
// HUD
|
|
|
- IHProgressHUD.set(viewForExtension: self.collectionView)
|
|
|
+ IHProgressHUD.set(viewForExtension: self.view)
|
|
|
IHProgressHUD.set(defaultMaskType: .clear)
|
|
|
- IHProgressHUD.set(minimumDismiss: 0)
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(triggerProgressTask(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object: nil)
|
|
|
}
|
|
@@ -150,13 +149,13 @@ class NCShareExtension: UIViewController {
|
|
|
|
|
|
guard let activeAccount = NCManageDatabase.shared.getActiveAccount() else {
|
|
|
return showAlert(description: "_no_active_account_") {
|
|
|
- self.cancel(with: NCShareExtensionError.noAccount)
|
|
|
+ self.cancel(with: .noAccount)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
accountRequestChangeAccount(account: activeAccount.account)
|
|
|
guard let inputItems = extensionContext?.inputItems as? [NSExtensionItem] else {
|
|
|
- cancel(with: NCShareExtensionError.noFiles)
|
|
|
+ cancel(with: .noFiles)
|
|
|
return
|
|
|
}
|
|
|
NCFilesExtensionHandler(items: inputItems) { fileNames in
|
|
@@ -178,16 +177,23 @@ class NCShareExtension: UIViewController {
|
|
|
tableView.reloadData()
|
|
|
}
|
|
|
|
|
|
+ override func viewWillDisappear(_ animated: Bool) {
|
|
|
+ super.viewWillDisappear(animated)
|
|
|
+ // remove all metadata in queue
|
|
|
+ for metadata in uploadMetadata {
|
|
|
+ let filePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
|
|
|
+ let path = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId)!
|
|
|
+ NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
+ NCNetworking.shared.uploadRequest[filePath]?.tasks.forEach({ $0.cancel() })
|
|
|
+ NCUtilityFileSystem.shared.deleteFile(filePath: path)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: -
|
|
|
|
|
|
func cancel(with error: NCShareExtensionError) {
|
|
|
// make sure no uploads are continued
|
|
|
uploadStarted = false
|
|
|
- let metadata = uploadMetadata[counterUploaded]
|
|
|
- let filePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
|
|
|
-
|
|
|
- NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
- NCNetworking.shared.uploadRequest[filePath]?.tasks.forEach({ $0.cancel() })
|
|
|
extensionContext?.cancelRequest(withError: error)
|
|
|
}
|
|
|
|
|
@@ -269,7 +275,7 @@ class NCShareExtension: UIViewController {
|
|
|
|
|
|
func setCommandView() {
|
|
|
guard !filesName.isEmpty else {
|
|
|
- cancel(with: NCShareExtensionError.noFiles)
|
|
|
+ cancel(with: .noFiles)
|
|
|
return
|
|
|
}
|
|
|
let counter = min(CGFloat(filesName.count), 3)
|
|
@@ -288,7 +294,7 @@ class NCShareExtension: UIViewController {
|
|
|
// MARK: ACTION
|
|
|
|
|
|
@IBAction func actionCancel(_ sender: UIBarButtonItem) {
|
|
|
- cancel(with: NCShareExtensionError.cancel)
|
|
|
+ cancel(with: .cancel)
|
|
|
}
|
|
|
|
|
|
@objc func actionCreateFolder() {
|
|
@@ -370,6 +376,11 @@ extension NCShareExtension {
|
|
|
// CHUNCK
|
|
|
metadata.chunk = chunckSize != 0 && metadata.size > chunckSize
|
|
|
|
|
|
+ if counterUploaded == 0 {
|
|
|
+ let status = NSLocalizedString("_upload_file_", comment: "") + " \(counterUploaded + 1) " + NSLocalizedString("_of_", comment: "") + " \(filesName.count)"
|
|
|
+ IHProgressHUD.show(withStatus: status)
|
|
|
+ }
|
|
|
+
|
|
|
NCNetworking.shared.upload(metadata: metadata) { } completion: { errorCode, _ in
|
|
|
if errorCode == 0 {
|
|
|
self.counterUploaded += 1
|