Skip to content

Commit

Permalink
- update SDK to gain OCAppIdentity convenience URL schemes property
Browse files Browse the repository at this point in the history
- CancelLabelViewController: allow customizing the button label and use a proper type for the cancelAction
- DocumentActionViewController:
	- refactor to allow custom button label and custom action
	- show message and open app if no account has been set up in the app yet
  • Loading branch information
felix-schwarz committed Nov 28, 2023
1 parent dab3ab4 commit 3f78084
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ios-sdk
8 changes: 5 additions & 3 deletions ownCloud File Provider UI/CancelLabelViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class CancelLabelViewController: UIViewController {
@IBOutlet var label : UILabel!
@IBOutlet var button : ThemeButton!

var cancelAction: (() -> Void)?
typealias CancelAction = (() -> Void)

func updateCancelLabels(with message: String) {
var cancelAction: CancelAction?

func updateCancelLabels(with message: String, buttonLabel: String? = nil) {
let collection = Theme.shared.activeCollection

view.cssSelector = .toolbar
Expand All @@ -38,7 +40,7 @@ class CancelLabelViewController: UIViewController {
label.apply(css: collection.css, properties: [.stroke])

self.label.text = message
self.button.setTitle("Cancel".localized, for: .normal)
self.button.setTitle(buttonLabel ?? "Cancel".localized, for: .normal)
}

@IBAction func cancelScreen() {
Expand Down
44 changes: 32 additions & 12 deletions ownCloud File Provider UI/DocumentActionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class DocumentActionViewController: FPUIActionExtensionViewController {

prepareNavigationController()

showCancelLabel(with: "Connecting…".localized)
showMessage(with: "Connecting…".localized)

var actionTypeLabel = ""
var actionExtensionType : ActionExtensionType = .undefined
Expand Down Expand Up @@ -139,7 +139,7 @@ class DocumentActionViewController: FPUIActionExtensionViewController {

OnMainThread {
if actionExtensionType == .sharing, core.connection.capabilities?.sharingAPIEnabled == false || item.isShareable == false {
self.showCancelLabel(with: String(format: "%@ is not available for this item.".localized, actionTypeLabel))
self.showMessage(with: String(format: "%@ is not available for this item.".localized, actionTypeLabel))
} else if core.connectionStatus == .online {
self.coreConnectionStatusObservation?.invalidate()
self.coreConnectionStatusObservation = nil
Expand All @@ -157,18 +157,18 @@ class DocumentActionViewController: FPUIActionExtensionViewController {
}
} else if core.connectionStatus == .connecting {
triedConnecting = true
self.showCancelLabel(with: "Connecting…".localized)
self.showMessage(with: "Connecting…".localized)
} else if core.connectionStatus == .offline || core.connectionStatus == .unavailable {
// Display error if `.connecting` isn't reached within 2 seconds
OnMainThread(after: 2) {
if !triedConnecting {
self.showCancelLabel(with: String(format: "%@ is not available, when this account is offline. Please open the app and log into your account before you can do this action.".localized, actionTypeLabel))
self.showMessage(with: String(format: "%@ is not available, when this account is offline. Please open the app and log into your account before you can do this action.".localized, actionTypeLabel))
}
}

// Display error if `.connecting` has already been reached
if triedConnecting {
self.showCancelLabel(with: String(format: "%@ is not available, when this account is offline. Please open the app and log into your account before you can do this action.".localized, actionTypeLabel))
self.showMessage(with: String(format: "%@ is not available, when this account is offline. Please open the app and log into your account before you can do this action.".localized, actionTypeLabel))
}
}
}
Expand All @@ -180,7 +180,18 @@ class DocumentActionViewController: FPUIActionExtensionViewController {
override func prepare(forError error: Error) {
if !OCFileProviderSettings.browseable {
prepareNavigationController()
showCancelLabel(with: "File Provider access has been disabled by the administrator.\n\nPlease use the app to access your files.".localized)
showMessage(with: "File Provider access has been disabled by the administrator.\n\nPlease use the app to access your files.".localized)
return
}

if OCBookmarkManager.shared.bookmarks.count == 0 {
prepareNavigationController()
showMessage(with: "No account has been set up in the {{app.name}} app yet.".localized, buttonLabel: "Open app".localized, action: { [weak self] in
if let appURLScheme = OCAppIdentity.shared.appURLSchemes?.first {
self?.extensionContext.open(URL(string: "\(appURLScheme)://fp-no-account")!)
}
self?.complete()
})
return
}

Expand All @@ -197,20 +208,29 @@ class DocumentActionViewController: FPUIActionExtensionViewController {
AppLockManager.shared.showLockscreenIfNeeded()
} else {
prepareNavigationController()
showCancelLabel(with: "Passcode protection is not supported on this device.\nPlease disable passcode lock in the app settings.".localized)
showMessage(with: "Passcode protection is not supported on this device.\nPlease disable passcode lock in the app settings.".localized)
}
}

func showCancelLabel(with message: String) {
func showMessage(with message: String, buttonLabel: String? = nil, action: CancelLabelViewController.CancelAction? = nil) {
OnMainThread {
var messageController: CancelLabelViewController?

if let currentController = self.themeNavigationController?.viewControllers.first as? CancelLabelViewController {
currentController.updateCancelLabels(with: message)
messageController = currentController
} else if let cancelLabelViewController = UIStoryboard.init(name: "MainInterface", bundle: nil).instantiateViewController(withIdentifier: "CancelLabelViewController") as? CancelLabelViewController {
cancelLabelViewController.updateCancelLabels(with: message)
cancelLabelViewController.cancelAction = { [weak self] in
messageController = cancelLabelViewController
}

if let messageController {
messageController.updateCancelLabels(with: message, buttonLabel: buttonLabel)
messageController.cancelAction = action ?? { [weak self] in
self?.complete(cancelWith: NSError(domain: FPUIErrorDomain, code: Int(FPUIExtensionErrorCode.userCancelled.rawValue), userInfo: nil))
}
self.themeNavigationController?.viewControllers = [ cancelLabelViewController ]

if self.themeNavigationController?.viewControllers.first != messageController {
self.themeNavigationController?.viewControllers = [ messageController ]
}
}
}
}
Expand Down

0 comments on commit 3f78084

Please sign in to comment.