Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/ios.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/Share
diff options
context:
space:
mode:
authorHenrik Storch <henrik.storch@nextcloud.com>2022-01-12 11:08:45 +0300
committerHenrik Storch <henrik.storch@nextcloud.com>2022-01-12 11:08:55 +0300
commitf116f0d990865d8239b602b918265b7b5d6c025a (patch)
tree6d69a00ce77c25c37b6163c623e4a90723c2056c /Share
parentb10287be7e286bb5fb1b1afb6adddec39d18dd79 (diff)
Refactor Share ext. cancel
Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Diffstat (limited to 'Share')
-rw-r--r--Share/NCShareExtension+NCDelegate.swift6
-rw-r--r--Share/NCShareExtension.swift29
2 files changed, 16 insertions, 19 deletions
diff --git a/Share/NCShareExtension+NCDelegate.swift b/Share/NCShareExtension+NCDelegate.swift
index 4576438d5..17f6e379a 100644
--- a/Share/NCShareExtension+NCDelegate.swift
+++ b/Share/NCShareExtension+NCDelegate.swift
@@ -71,8 +71,7 @@ extension NCShareExtension: NCEmptyDataSetDelegate, NCAccountRequestDelegate {
func accountRequestChangeAccount(account: String) {
guard let activeAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else {
- uploadStarted = false
- extensionContext?.cancelRequest(withError: NCShareExtensionError.noAccount)
+ cancel(with: NCShareExtensionError.noAccount)
return
}
self.activeAccount = activeAccount
@@ -110,8 +109,7 @@ extension NCShareExtension: NCShareCellDelegate, NCRenameFileDelegate, NCListCel
}
self.filesName.remove(at: index)
if self.filesName.isEmpty {
- uploadStarted = false
- self.extensionContext?.cancelRequest(withError: NCShareExtensionError.noFiles)
+ cancel(with: NCShareExtensionError.noFiles)
} else {
self.setCommandView()
}
diff --git a/Share/NCShareExtension.swift b/Share/NCShareExtension.swift
index b25578143..fe9857402 100644
--- a/Share/NCShareExtension.swift
+++ b/Share/NCShareExtension.swift
@@ -63,8 +63,8 @@ class NCShareExtension: UIViewController {
var layoutForView: NCGlobal.layoutForViewType?
- var heightRowTableView: CGFloat = 50
- private var heightCommandView: CGFloat = 170
+ let heightRowTableView: CGFloat = 50
+ private let heightCommandView: CGFloat = 170
var autoUploadFileName = ""
var autoUploadDirectory = ""
@@ -74,8 +74,8 @@ class NCShareExtension: UIViewController {
private let chunckSize = CCUtility.getChunkSize() * 1000000
private var counterUploaded: Int = 0
- var uploadMetadata: [tableMetadata] = []
private var uploadErrors: [tableMetadata] = []
+ var uploadMetadata: [tableMetadata] = []
var uploadStarted = false
// MARK: - View Life Cycle
@@ -149,16 +149,14 @@ class NCShareExtension: UIViewController {
guard serverUrl.isEmpty else { return }
guard let activeAccount = NCManageDatabase.shared.getActiveAccount() else {
- self.uploadStarted = false
return showAlert(description: "_no_active_account_") {
- self.extensionContext?.cancelRequest(withError: NCShareExtensionError.noAccount)
+ self.cancel(with: NCShareExtensionError.noAccount)
}
}
accountRequestChangeAccount(account: activeAccount.account)
guard let inputItems = extensionContext?.inputItems as? [NSExtensionItem] else {
- uploadStarted = false
- self.extensionContext?.cancelRequest(withError: NCShareExtensionError.noFiles)
+ cancel(with: NCShareExtensionError.noFiles)
return
}
NCFilesExtensionHandler(items: inputItems) { fileNames in
@@ -182,6 +180,12 @@ class NCShareExtension: UIViewController {
// MARK: -
+ func cancel(with error: NCShareExtensionError) {
+ // make sure no uploads are continued
+ uploadStarted = false
+ extensionContext?.cancelRequest(withError: error)
+ }
+
func showAlert(title: String = "_error_", description: String, onDismiss: (() -> Void)? = nil) {
let alertController = UIAlertController(title: NSLocalizedString(title, comment: ""), message: NSLocalizedString(description, comment: ""), preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in
@@ -260,8 +264,7 @@ class NCShareExtension: UIViewController {
func setCommandView() {
guard !filesName.isEmpty else {
- uploadStarted = false
- self.extensionContext?.cancelRequest(withError: NCShareExtensionError.noFiles)
+ cancel(with: NCShareExtensionError.noFiles)
return
}
let counter = min(CGFloat(filesName.count), 3)
@@ -280,9 +283,7 @@ class NCShareExtension: UIViewController {
// MARK: ACTION
@IBAction func actionCancel(_ sender: UIBarButtonItem) {
- // make sure no uploads are continued
- uploadStarted = false
- extensionContext?.cancelRequest(withError: NCShareExtensionError.cancel)
+ cancel(with: NCShareExtensionError.cancel)
}
@objc func actionCreateFolder() {
@@ -366,9 +367,7 @@ extension NCShareExtension {
metadata.chunk = true
}
- NCNetworking.shared.upload(metadata: metadata) {
-
- } completion: { errorCode, _ in
+ NCNetworking.shared.upload(metadata: metadata) { } completion: { errorCode, _ in
if errorCode == 0 {
self.counterUploaded += 1
// next