Skip to content

Commit 0dc9238

Browse files
Error banner (LuciBanner) integration (#4003)
1 parent 0adf9d9 commit 0dc9238

61 files changed

Lines changed: 724 additions & 990 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Nextcloud.xcodeproj/project.pbxproj

Lines changed: 1 addition & 64 deletions
Large diffs are not rendered by default.

iOSClient/Account/Account Settings/NCAccountSettingsView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ struct NCAccountSettingsView: View {
141141
// User Status
142142
if capabilities.userStatusEnabled {
143143
if let account = model.tblAccount?.account {
144-
NavigationLink(destination: NCUserStatusView(account: account)) {
144+
NavigationLink(destination: NCUserStatusView(account: account, controller: model.controller)) {
145145
HStack {
146146
Image(systemName: "moon.fill")
147147
.resizable()
@@ -160,7 +160,7 @@ struct NCAccountSettingsView: View {
160160
}
161161

162162
if let account = model.tblAccount?.account {
163-
NavigationLink(destination: NCStatusMessageView(account: account)) {
163+
NavigationLink(destination: NCStatusMessageView(account: account, controller: model.controller)) {
164164
HStack {
165165
Image(systemName: "message.fill")
166166
.resizable()

iOSClient/Extensions/UIAlertController+Extension.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import Foundation
2525
import UIKit
2626
import NextcloudKit
27+
import LucidBanner
2728

2829
extension UIAlertController {
2930
/// Creates a alert controller with a textfield, asking to create a new folder
@@ -46,7 +47,7 @@ extension UIAlertController {
4647

4748
if markE2ee {
4849
if NCNetworking.shared.isOffline {
49-
completion?(NKError(errorCode: NCGlobal.shared.errorOffline, errorDescription: "_offline_not_allowed_"))
50+
completion?(NKError(errorCode: NCGlobal.shared.errorOfflineNotAllowed, errorDescription: "_offline_not_allowed_"))
5051
return
5152
}
5253
Task {
@@ -71,7 +72,7 @@ extension UIAlertController {
7172
} else if isDirectoryEncrypted {
7273
Task {
7374
if NCNetworking.shared.isOffline {
74-
completion?(NKError(errorCode: NCGlobal.shared.errorOffline, errorDescription: "_offline_not_allowed_"))
75+
completion?(NKError(errorCode: NCGlobal.shared.errorOfflineNotAllowed, errorDescription: "_offline_not_allowed_"))
7576
return
7677
}
7778

@@ -186,31 +187,28 @@ extension UIAlertController {
186187
}, completion: completion)
187188
}
188189

189-
static func deleteFileOrFolder(titleString: String, message: String?, canDeleteServer: Bool, selectedMetadatas: [tableMetadata], sceneIdentifier: String?, completion: @escaping (_ cancelled: Bool) -> Void) -> UIAlertController {
190+
static func alertDeleteFileOrFolder(titleString: String, message: String?, canDeleteServer: Bool, metadatas: [tableMetadata], completion: @escaping (_ cancelled: Bool) -> Void) -> UIAlertController {
190191
let alertController = UIAlertController(
191192
title: titleString,
192193
message: message,
193194
preferredStyle: .alert)
194195
if canDeleteServer {
195196
alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .destructive) { (_: UIAlertAction) in
196197
Task {
197-
await NCNetworking.shared.setStatusWaitDelete(metadatas: selectedMetadatas, sceneIdentifier: sceneIdentifier)
198+
await NCNetworking.shared.setStatusWaitDelete(metadatas: metadatas)
198199
}
199200
completion(false)
200201
})
201202
}
202203

203-
#if !EXTENSION
204204
alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_local_file_", comment: ""), style: .default) { (_: UIAlertAction) in
205205
Task {
206-
var error = NKError()
207-
for metadata in selectedMetadatas where error == .success {
208-
error = await NCNetworking.shared.deleteCache(metadata, sceneIdentifier: sceneIdentifier)
206+
for metadata in metadatas {
207+
await NCNetworking.shared.deleteCache(metadata)
209208
}
210209
}
211210
completion(false)
212211
})
213-
#endif
214212

215213
alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { (_: UIAlertAction) in
216214
completion(true)

iOSClient/Files/NCFiles.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ class NCFiles: NCCollectionViewCommon {
323323
await showErrorBanner(controller: self.controller, text: error.errorDescription, errorCode: error.errorCode)
324324
}
325325
} else {
326-
// show error
327326
await showErrorBanner(controller: self.controller, text: error.errorDescription, errorCode: error.errorCode)
328327
}
329328

iOSClient/GUI/Lucid Banner/BannerView.swift

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import SwiftUI
66
import LucidBanner
7+
import NextcloudKit
78
import Alamofire
89

910
// MARK: - Show Banner
@@ -43,7 +44,10 @@ func showBanner(scene: UIWindowScene?,
4344
imageAnimation: LucidBanner.LucidBannerAnimationStyle,
4445
imageColor: UIColor,
4546
vPosition: LucidBanner.VerticalPosition = .top,
46-
backgroundColor: UIColor) async {
47+
backgroundColor: UIColor,
48+
autoDismissAfter: TimeInterval = NCGlobal.shared.dismissAfterSecond,
49+
swipeToDismiss: Bool = true,
50+
policy: LucidBanner.ShowPolicy = .enqueue) async {
4751
#if !EXTENSION
4852
let scene = scene ?? UIApplication.shared.mainAppWindow?.windowScene
4953
#endif
@@ -57,13 +61,14 @@ func showBanner(scene: UIWindowScene?,
5761
textColor: Color(uiColor: textColor),
5862
imageColor: Color(uiColor: imageColor),
5963
vPosition: vPosition,
60-
autoDismissAfter: NCGlobal.shared.dismissAfterSecond,
61-
swipeToDismiss: true
64+
autoDismissAfter: autoDismissAfter,
65+
swipeToDismiss: swipeToDismiss
6266
)
6367

6468
LucidBanner.shared.show(
6569
scene: scene,
66-
payload: payload) { state in
70+
payload: payload,
71+
policy: policy) { state in
6772
MessageBannerView(state: state)
6873
}
6974
}
@@ -192,6 +197,16 @@ func showErrorBannerActiveScenes(title: String = "_error_",
192197
}
193198
}
194199

200+
@MainActor
201+
func showErrorBanner(controller: UITabBarController?,
202+
error: NKError) async {
203+
let scene = SceneManager.shared.getWindow(controller: controller)?.windowScene
204+
await showErrorBanner(scene: scene,
205+
title: "_error_",
206+
text: error.errorDescription,
207+
errorCode: error.errorCode)
208+
}
209+
195210
@MainActor
196211
func showErrorBanner(controller: UITabBarController?,
197212
title: String = "_error_",
@@ -287,13 +302,21 @@ func showErrorBanner(scene: UIWindowScene?,
287302
}
288303

289304
// MARK: - Helper
305+
290306
#if !EXTENSION
307+
308+
// Error 401 (maintenance mode)
309+
// Error 423 (locked)
310+
// Error 507 (insufficient storage)
311+
// Error -1009 (NSURLErrorNotConnectedToInternet)
312+
// Error -1003 (NSURLError​Cannot​Find​Host)
313+
291314
func bannerContainsError(errorCode: Int?, afError: AFError? = nil) -> Bool {
292315
guard let errorCode else {
293316
return false
294317
}
295318
// List of errors not to be displayed
296-
if errorCode == -999 {
319+
if errorCode == -999 || errorCode == 423 {
297320
return true
298321
}
299322
if let afError, case .explicitlyCancelled = afError {
@@ -307,11 +330,6 @@ func bannerContainsError(errorCode: Int?, afError: AFError? = nil) -> Bool {
307330
} else {
308331
// Coalesce user-facing errors across the current foreground session.
309332
// The same error code is shown to the user only once.
310-
// Error 401 (maintenance mode)
311-
// Error 423 (locked)
312-
// Error 507 (insufficient storage)
313-
// Error -1009 (NSURLErrorNotConnectedToInternet)
314-
// Error -1003 (NSURLError​Cannot​Find​Host)
315333
if errorCode == 401 ||
316334
errorCode == 423 ||
317335
errorCode == 507 ||

iOSClient/GUI/Lucid Banner/HudBannerView.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ func showHudBanner(scene: UIWindowScene?,
1111
subtitle: String? = nil,
1212
stage: LucidBanner.Stage? = nil,
1313
onButtonTap: (() -> Void)? = nil) -> Int? {
14-
var scene = scene
15-
if scene == nil {
16-
scene = UIApplication.shared.mainAppWindow?.windowScene
17-
}
14+
let scene = scene ?? UIApplication.shared.mainAppWindow?.windowScene
15+
let localizedTitle = title.map { NSLocalizedString($0, comment: "") }
16+
let localizedSubTitle = subtitle.map { NSLocalizedString($0, comment: "") }
1817

1918
let payload = LucidBannerPayload(
20-
title: title,
21-
subtitle: subtitle,
19+
title: localizedTitle,
20+
subtitle: localizedSubTitle,
2221
stage: stage,
2322
vPosition: .center,
2423
blocksTouches: true,
@@ -42,9 +41,9 @@ func completeHudBannerSuccess(token: Int?) {
4241
}
4342

4443
@MainActor
45-
func completeHudBannerError(subtitle: String? = nil, token: Int?) {
44+
func completeHudBannerError(description: String, token: Int?) {
4645
let payload = LucidBannerPayload.Update(
47-
subtitle: subtitle,
46+
subtitle: NSLocalizedString(description, comment: ""),
4847
stage: .error,
4948
autoDismissAfter: NCGlobal.shared.dismissAfterSecond
5049
)

iOSClient/Login/NCLogin.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import UniformTypeIdentifiers
77
import UIKit
88
import NextcloudKit
9-
import SwiftEntryKit
109
import SwiftUI
1110
import SafariServices
1211

@@ -192,11 +191,13 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
192191
let title = String(format: NSLocalizedString("_apps_nextcloud_detect_", comment: ""), NCBrandOptions.shared.brand)
193192
let description = String(format: NSLocalizedString("_add_existing_account_", comment: ""), NCBrandOptions.shared.brand)
194193

194+
/*
195195
NCContentPresenter().alertAction(image: image, contentModeImage: .scaleAspectFit, sizeImage: CGSize(width: 45, height: 45), backgroundColor: backgroundColor, textColor: textColor, title: title, description: description, textCancelButton: "_cancel_", textOkButton: "_ok_", attributes: EKAttributes.topFloat) { identifier in
196196
if identifier == "ok" {
197197
self.openShareAccountsViewController(nil)
198198
}
199199
}
200+
*/
200201
}
201202
}
202203

iOSClient/Main/Collection Common/NCCollectionViewCommon+CellDelegate.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ extension NCCollectionViewCommon: NCListCellDelegate, NCGridCellDelegate {
22
func openContextMenu(with metadata: tableMetadata?, button: UIButton, sender: Any) {
33
Task {
44
guard let metadata else { return }
5-
button.menu = NCContextMenuMain(metadata: metadata, viewController: self, sceneIdentifier: self.sceneIdentifier, sender: sender).viewMenu()
5+
button.menu = NCContextMenuMain(metadata: metadata,
6+
viewController: self,
7+
controller: self.controller,
8+
sender: sender).viewMenu()
69
}
710
}
811

@@ -15,7 +18,7 @@ extension NCCollectionViewCommon: NCListCellDelegate, NCGridCellDelegate {
1518
func tapShareListItem(with metadata: tableMetadata?, button: UIButton, sender: Any) {
1619
Task {
1720
guard let metadata else { return }
18-
NCCreate().createShare(viewController: self, metadata: metadata, page: .sharing)
21+
NCCreate().createShare(viewController: self, controller: self.controller, metadata: metadata, page: .sharing)
1922
}
2023
}
2124
}

iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDelegate.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
3232
var tokenBanner: Int?
3333
await MainActor.run {
3434
tokenBanner = showHudBanner(scene: scene,
35-
title: NSLocalizedString("_download_in_progress_", comment: ""),
35+
title: "_download_in_progress_",
3636
stage: .button,
3737
onButtonTap: {
3838
if let request = downloadRequest {
@@ -115,7 +115,7 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
115115
self.navigationController?.pushViewController(vc, animated: true)
116116
}
117117
} else {
118-
await showErrorBanner(controller: controller, text: "_go_online_", errorCode: NCGlobal.shared.errorOffline)
118+
await showErrorBanner(controller: controller, text: "_go_online_", errorCode: NCGlobal.shared.errorOfflineNotAllowed)
119119
}
120120
}
121121
}
@@ -166,7 +166,7 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
166166
return UIContextMenuConfiguration(identifier: identifier, previewProvider: {
167167
return nil
168168
}, actionProvider: { _ in
169-
let contextMenu = NCContextMenuMain(metadata: metadata.detachedCopy(), viewController: self, sceneIdentifier: self.sceneIdentifier, sender: cell)
169+
let contextMenu = NCContextMenuMain(metadata: metadata.detachedCopy(), viewController: self, controller: self.controller, sender: cell)
170170
return contextMenu.viewMenu()
171171
})
172172
}

iOSClient/Main/Collection Common/NCCollectionViewCommon+DragDrop.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ extension NCCollectionViewCommon: UICollectionViewDropDelegate {
134134
destination = utilityFileSystem.createServerUrl(serverUrl: destinationMetadata.serverUrl, fileName: destinationMetadata.fileName)
135135
}
136136
Task {
137-
await NCDragDrop().copyFile(metadatas: sourceMetadatas, destination: destination)
137+
await NCDragDrop().copyFile(metadatas: sourceMetadatas, destination: destination, controller: self.controller)
138138
}
139139
}
140140

@@ -146,7 +146,7 @@ extension NCCollectionViewCommon: UICollectionViewDropDelegate {
146146
destination = utilityFileSystem.createServerUrl(serverUrl: destinationMetadata.serverUrl, fileName: destinationMetadata.fileName)
147147
}
148148
Task {
149-
await NCDragDrop().moveFile(metadatas: sourceMetadatas, destination: destination)
149+
await NCDragDrop().moveFile(metadatas: sourceMetadatas, destination: destination, controller: self.controller)
150150
}
151151
}
152152
}

0 commit comments

Comments
 (0)