Skip to content
Merged

banner #3955

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions Share/NCShareExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,12 @@ class NCShareExtension: UIViewController {

// MARK: -

func cancel(with error: NCShareExtensionError) {
// make sure no uploads are continued
extensionContext?.cancelRequest(withError: error)
func cancel(with error: NCShareExtensionError? = nil) {
if let error {
extensionContext?.cancelRequest(withError: error)
} else {
self.extensionContext?.completeRequest(returningItems: self.extensionContext?.inputItems, completionHandler: nil)
}
}

func showAlert(title: String = "_error_", description: String, onDismiss: (() -> Void)? = nil) {
Expand Down Expand Up @@ -264,15 +267,15 @@ class NCShareExtension: UIViewController {
// MARK: ACTION

@IBAction func actionCancel(_ sender: UIBarButtonItem) {
cancel(with: .cancel)
cancel()
}

@objc func actionCreateFolder(_ sender: Any?) {
let session = NCShareExtensionData.shared.getSession()
guard let capabilities = NCNetworking.shared.capabilities[session.account] else {
return
}
let alertController = UIAlertController.createFolder(serverUrl: serverUrl, session: session, capabilities: capabilities) { error in
let alertController = UIAlertController.createFolder(serverUrl: serverUrl, session: session, capabilities: capabilities, scene: self.view.window?.windowScene) { error in
if error == .success {
Task {
await self.loadFolder()
Expand Down Expand Up @@ -368,15 +371,17 @@ extension NCShareExtension {
@MainActor
func uploadAndExit() async {
var error: NKError?
let payload = LucidBannerPayload(backgroundColor: Color(.systemBackground),
let payload = LucidBannerPayload(stage: .button,
backgroundColor: Color(.systemBackground),
vPosition: .center,
verticalMargin: 0,
blocksTouches: true,
draggable: false)
horizontalMargin: 20,
blocksTouches: true)
token = showUploadBanner(scene: self.view.window?.windowScene,
payload: payload,
allowMinimizeOnTap: false
)
allowMinimizeOnTap: false,
onButtonTap: {
self.cancel()
})

for metadata in self.uploadMetadata {
// BANNER
Expand Down Expand Up @@ -405,7 +410,7 @@ extension NCShareExtension {
}

LucidBanner.shared.dismiss(after: 2) {
self.extensionContext?.completeRequest(returningItems: self.extensionContext?.inputItems, completionHandler: nil)
self.cancel()
}
}

Expand Down Expand Up @@ -447,8 +452,7 @@ extension NCShareExtension {
let task = Task { () -> (account: String, file: NKFile?, error: NKError) in
let results = await NCNetworking.shared.uploadChunkFile(metadata: metadata) { total, counter in
Task {@MainActor in
let progress = Double(counter) / Double(total)
LucidBanner.shared.update(payload: LucidBannerPayload.Update(progress: progress), for: self.token)
LucidBanner.shared.update(payload: LucidBannerPayload.Update(progress: Double(counter) / Double(total)), for: self.token)
}
} uploadStart: { _ in
Task {@MainActor in
Expand All @@ -460,10 +464,7 @@ extension NCShareExtension {
}
} uploadProgressHandler: { _, _, progress in
Task {@MainActor in
LucidBanner.shared.update(
payload: LucidBannerPayload.Update(progress: progress),
for: self.token)
LucidBanner.shared.update(payload: payload, for: self.token)
LucidBanner.shared.update(payload: LucidBannerPayload.Update(progress: progress), for: self.token)
}
} assembling: {
Task {@MainActor in
Expand Down
5 changes: 3 additions & 2 deletions iOSClient/Extensions/UIAlertController+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extension UIAlertController {
markE2ee: Bool = false,
sceneIdentifier: String? = nil,
capabilities: NKCapabilities.Capabilities,
scene: UIWindowScene? = nil,
completion: ((_ error: NKError) -> Void)? = nil) -> UIAlertController {
let alertController = UIAlertController(title: NSLocalizedString("_create_folder_", comment: ""), message: nil, preferredStyle: .alert)
let isDirectoryEncrypted = NCUtilityFileSystem().isDirectoryE2EE(serverUrl: serverUrl, urlBase: session.urlBase, userId: session.userId, account: session.account)
Expand All @@ -61,10 +62,10 @@ extension UIAlertController {
if createFolderResults.error == .success {
let error = await NCNetworkingE2EEMarkFolder().markFolderE2ee(account: session.account, serverUrlFileName: serverUrlFileName, userId: session.userId)
if error != .success {
NCContentPresenter().showError(error: error)
await showErrorBanner(scene: scene, text: error.errorDescription)
}
} else {
NCContentPresenter().showError(error: createFolderResults.error)
await showErrorBanner(scene: scene, text: createFolderResults.error.errorDescription)
}
}
} else if isDirectoryEncrypted {
Expand Down
7 changes: 7 additions & 0 deletions iOSClient/Extensions/UIApplication+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@ extension UIApplication {
requestSceneSessionDestruction(windowScene.session, options: options, errorHandler: nil)
}
}

/// Returns all foreground-active window scenes.
var foregroundActiveScenes: [UIWindowScene] {
connectedScenes
.compactMap { $0 as? UIWindowScene }
.filter { $0.activationState == .foregroundActive }
}
}
108 changes: 66 additions & 42 deletions iOSClient/GUI/Lucid Banner/BannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@ import SwiftUI
import LucidBanner

// MARK: - Show Banner
#if !EXTENSION
@MainActor
func showBannerActiveScenes(title: String?,
subtitle: String? = nil,
footnote: String? = nil,
textColor: UIColor,
image: String?,
imageAnimation: LucidBanner.LucidBannerAnimationStyle,
imageColor: UIColor,
vPosition: LucidBanner.VerticalPosition = .top,
backgroundColor: UIColor) async {
for scene in UIApplication.shared.foregroundActiveScenes {
await showBanner(scene: scene,
title: title,
subtitle: subtitle,
footnote: footnote,
textColor: textColor,
image: image,
imageAnimation: imageAnimation,
imageColor: imageColor,
vPosition: vPosition,
backgroundColor: backgroundColor)
}
}
#endif

@MainActor
func showBanner(scene: UIWindowScene?,
Expand All @@ -19,10 +44,7 @@ func showBanner(scene: UIWindowScene?,
vPosition: LucidBanner.VerticalPosition = .top,
backgroundColor: UIColor) async {
#if !EXTENSION
var scene = scene
if scene == nil {
scene = UIApplication.shared.mainAppWindow?.windowScene
}
let scene = scene ?? UIApplication.shared.mainAppWindow?.windowScene
#endif
let payload = LucidBannerPayload(
title: NSLocalizedString(title ?? "", comment: ""),
Expand All @@ -48,6 +70,22 @@ func showBanner(scene: UIWindowScene?,
// MARK: - Show Info

#if !EXTENSION
@MainActor
func showInfoBannerActiveScenes(title: String = "_error_",
text: String,
footnote: String? = nil,
foregroundColor: UIColor = .label,
backgroundColor: UIColor = .systemBackground) async {
for scene in UIApplication.shared.foregroundActiveScenes {
await showInfoBanner(scene: scene,
title: title,
text: text,
footnote: footnote,
foregroundColor: foregroundColor,
backgroundColor: backgroundColor)
}
}

@MainActor
func showInfoBanner(controller: UITabBarController?,
title: String = "_info_",
Expand Down Expand Up @@ -80,20 +118,6 @@ func showInfoBanner(sceneIdentifier: String?,

#endif

@MainActor
func showInfoBanner(title: String = "_error_",
text: String,
footnote: String? = nil,
foregroundColor: UIColor = .label,
backgroundColor: UIColor = .systemBackground) async {
await showInfoBanner(scene: nil,
title: title,
text: text,
footnote: footnote,
foregroundColor: foregroundColor,
backgroundColor: backgroundColor)
}

@MainActor
func showInfoBanner(scene: UIWindowScene?,
title: String = "_info_",
Expand All @@ -102,10 +126,7 @@ func showInfoBanner(scene: UIWindowScene?,
foregroundColor: UIColor = .label,
backgroundColor: UIColor = .systemBackground) async {
#if !EXTENSION
var scene = scene
if scene == nil {
scene = UIApplication.shared.mainAppWindow?.windowScene
}
let scene = scene ?? UIApplication.shared.mainAppWindow?.windowScene
#endif

let payload = LucidBannerPayload(
Expand All @@ -117,6 +138,8 @@ func showInfoBanner(scene: UIWindowScene?,
textColor: Color(uiColor: foregroundColor),
imageColor: Color(uiColor: NCBrandColor.shared.customer),
vPosition: .top,
horizontalMargin: 20,
verticalMargin: 10,
autoDismissAfter: NCGlobal.shared.dismissAfterSecond,
swipeToDismiss: true,
)
Expand All @@ -130,6 +153,24 @@ func showInfoBanner(scene: UIWindowScene?,
// MARK: - Show Error

#if !EXTENSION
@MainActor
func showErrorBannerActiveScenes(title: String = "_error_",
text: String,
footnote: String? = nil,
foregroundColor: UIColor = .white,
backgroundColor: UIColor = .red,
sleepBefore: Double = 1) async {
for scene in UIApplication.shared.foregroundActiveScenes {
await showErrorBanner(scene: scene,
title: title,
text: text,
footnote: footnote,
foregroundColor: foregroundColor,
backgroundColor: backgroundColor,
sleepBefore: sleepBefore)
}
}

@MainActor
func showErrorBanner(controller: UITabBarController?,
title: String = "_error_",
Expand Down Expand Up @@ -166,22 +207,6 @@ func showErrorBanner(sceneIdentifier: String?,

#endif

@MainActor
func showErrorBanner(title: String = "_error_",
text: String,
footnote: String? = nil,
foregroundColor: UIColor = .white,
backgroundColor: UIColor = .red,
sleepBefore: Double = 1) async {
await showErrorBanner(scene: nil,
title: title,
text: text,
footnote: footnote,
foregroundColor: foregroundColor,
backgroundColor: backgroundColor,
sleepBefore: sleepBefore)
}

@MainActor
func showErrorBanner(scene: UIWindowScene?,
title: String = "_error_",
Expand All @@ -192,10 +217,7 @@ func showErrorBanner(scene: UIWindowScene?,
sleepBefore: Double = 1) async {
try? await Task.sleep(nanoseconds: UInt64(sleepBefore * 1e9))
#if !EXTENSION
var scene = scene
if scene == nil {
scene = UIApplication.shared.mainAppWindow?.windowScene
}
let scene = scene ?? UIApplication.shared.mainAppWindow?.windowScene
#endif

let payload = LucidBannerPayload(
Expand All @@ -207,6 +229,8 @@ func showErrorBanner(scene: UIWindowScene?,
textColor: Color(uiColor: foregroundColor),
imageColor: .white,
vPosition: .top,
horizontalMargin: 20,
verticalMargin: 10,
autoDismissAfter: NCGlobal.shared.dismissAfterSecond,
swipeToDismiss: true,
)
Expand Down
1 change: 1 addition & 0 deletions iOSClient/GUI/Lucid Banner/UploadBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ struct UploadBannerView: View {
.tint(.accentColor)
.opacity(state.payload.progress == nil ? 0 : 1)
.animation(.easeInOut(duration: 0.2), value: state.payload.progress == nil)
.padding(.horizontal, 5)

if isButton {
VStack {
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/Main/NCDragDrop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ class NCDragDrop: NSObject {

let payload = LucidBannerPayload(stage: nil,
backgroundColor: Color(.systemBackground),
vPosition: .bottom,
verticalMargin: 55,
vPosition: .center,
horizontalMargin: 20,
blocksTouches: false,
draggable: false)
let token = showUploadBanner(scene: scene,
Expand Down
19 changes: 15 additions & 4 deletions iOSClient/Main/NCMainNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,12 @@ class NCMainNavigationController: UINavigationController, UINavigationController
menuActionElement.append(UIAction(title: titleCreateFolder,
image: imageCreateFolder) { _ in
DispatchQueue.main.async {
let alertController = UIAlertController.createFolder(serverUrl: serverUrl, session: session, sceneIdentifier: controller.sceneIdentifier, capabilities: capabilities)
let alertController = UIAlertController.createFolder(
serverUrl: serverUrl,
session: session,
sceneIdentifier: controller.sceneIdentifier,
capabilities: capabilities,
scene: SceneManager.shared.getWindow(controller: self.controller)?.windowScene)
controller.present(alertController, animated: true, completion: nil)
}
})
Expand All @@ -307,7 +312,13 @@ class NCMainNavigationController: UINavigationController, UINavigationController
menuE2EEElement.append(UIAction(title: NSLocalizedString("_create_folder_e2ee_", comment: ""),
image: NCImageCache.shared.getFolderEncrypted(account: session.account)) { _ in
DispatchQueue.main.async {
let alertController = UIAlertController.createFolder(serverUrl: serverUrl, session: session, markE2ee: true, sceneIdentifier: controller.sceneIdentifier, capabilities: capabilities)
let alertController = UIAlertController.createFolder(
serverUrl: serverUrl,
session: session,
markE2ee: true,
sceneIdentifier: controller.sceneIdentifier,
capabilities: capabilities,
scene: SceneManager.shared.getWindow(controller: self.controller)?.windowScene)
controller.present(alertController, animated: true, completion: nil)
}
})
Expand All @@ -329,9 +340,9 @@ class NCMainNavigationController: UINavigationController, UINavigationController
session.account,
serverUrl,
NCGlobal.shared.fileNameRichWorkspace.lowercased())) == nil {
richWorkspaceCommon.createViewerNextcloudText(serverUrl: serverUrl, viewController: viewController, session: session)
richWorkspaceCommon.createViewerNextcloudText(serverUrl: serverUrl, viewController: viewController, controller: self.controller, session: session)
} else {
richWorkspaceCommon.openViewerNextcloudText(serverUrl: serverUrl, viewController: viewController, session: session)
richWorkspaceCommon.openViewerNextcloudText(serverUrl: serverUrl, viewController: viewController, controller: controller, session: session)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions iOSClient/Media/NCMediaNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class NCMediaNavigationController: NCMainNavigationController {
viewController.typeOfCommandView = .select
viewController.type = "mediaFolder"
viewController.session = self.session
viewController.controller = self.controller
self.present(navigationController, animated: true)
})
])
Expand Down
18 changes: 9 additions & 9 deletions iOSClient/Networking/NCNetworking+NextcloudKitDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ extension NCNetworking {
lastReachability = true
} else {
if lastReachability {
let scene = SceneManager.shared.getWindow(sceneIdentifier: sceneIdentifier)?.windowScene
Task {
await showBanner(scene: scene,
title: NSLocalizedString("_info_", comment: ""),
subtitle: NSLocalizedString("_network_not_available_", comment: ""),
textColor: .white,
image: "wifi.exclamationmark.circle",
imageAnimation: .bounce,
imageColor: .white,
backgroundColor: UIColor.lightGray.withAlphaComponent(0.75))
await showBannerActiveScenes(
title: NSLocalizedString("_info_", comment: ""),
subtitle: NSLocalizedString("_network_not_available_", comment: ""),
textColor: .white,
image: "wifi.exclamationmark.circle",
imageAnimation: .bounce,
imageColor: .white,
backgroundColor: UIColor.lightGray.withAlphaComponent(0.75)
)
}
}
lastReachability = false
Expand Down
Loading
Loading