Browse Source

Add new view

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 years ago
parent
commit
bc52e5596a

+ 86 - 5
iOSClient/Main/Create cloud/NCUploadAssets.swift

@@ -10,10 +10,10 @@ import SwiftUI
 
 class NCHostingUploadAssetsView: NSObject {
 
-    @objc func makeShipDetailsUI(assets: [PHAsset], cryptated: Bool, session: String ,userBaseUrl: NCUserBaseUrl, serverUrl: String) -> UIViewController {
+    @objc func makeShipDetailsUI(assets: [PHAsset], cryptated: Bool, session: String, userBaseUrl: NCUserBaseUrl, serverUrl: String) -> UIViewController {
 
         let uploadAssets = NCUploadAssets(assets: assets, cryptated: cryptated, session: session, userBaseUrl: userBaseUrl, serverUrl: serverUrl)
-        let details = UploadAssetsView(uploadAssets: uploadAssets)
+        let details = UploadAssetsView(uploadAssets)
         let vc = UIHostingController(rootView: details)
         vc.title = NSLocalizedString("_upload_photos_videos_", comment: "")
         return vc
@@ -37,22 +37,103 @@ class NCUploadAssets: ObservableObject {
     }
 }
 
+// MARK: - Delegate
+
+extension NCUploadAssets: NCSelectDelegate {
+
+    func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, items: [Any], overwrite: Bool, copy: Bool, move: Bool) {
+
+        if let serverUrl = serverUrl {
+            CCUtility.setDirectoryScanDocument(serverUrl)
+            self.serverUrl = serverUrl
+        }
+    }
+}
+
 struct UploadAssetsView: View {
 
+    @State var isPresentedSelect = false
+
     @ObservedObject var uploadAssets: NCUploadAssets
 
+    init(_ uploadAssets: NCUploadAssets) {
+        self.uploadAssets = uploadAssets
+    }
+
     var body: some View {
-        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
+        GeometryReader { geo in
+            ZStack(alignment: .top) {
+                List {
+                    Section(header: Text(NSLocalizedString("_save_path_", comment: ""))) {
+                        HStack {
+                            Label {
+                                if NCUtilityFileSystem.shared.getHomeServer(urlBase: uploadAssets.userBaseUrl.urlBase, userId: uploadAssets.userBaseUrl.userId) == uploadAssets.serverUrl {
+                                    Text("/")
+                                        .frame(maxWidth: .infinity, alignment: .trailing)
+                                } else {
+                                    Text((uploadAssets.serverUrl as NSString).lastPathComponent)
+                                        .frame(maxWidth: .infinity, alignment: .trailing)
+                                }
+                            } icon: {
+                                Image("folder")
+                                    .renderingMode(.template)
+                                    .resizable()
+                                    .scaledToFit()
+                                    .foregroundColor(Color(NCBrandColor.shared.brand))
+                            }
+                        }
+                        .contentShape(Rectangle())
+                        .onTapGesture {
+                            isPresentedSelect = true
+                        }
+                        .complexModifier { view in
+                            if #available(iOS 16, *) {
+                                view.alignmentGuide(.listRowSeparatorLeading) { _ in
+                                    return 0
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        .background(Color(UIColor.systemGroupedBackground))
+        .sheet(isPresented: $isPresentedSelect) {
+            NCSelectUploadAssets(delegate: uploadAssets)
+        }
     }
 }
 
+// MARK: - UIViewControllerRepresentable
+
+struct NCSelectUploadAssets: UIViewControllerRepresentable {
+
+    typealias UIViewControllerType = UINavigationController
+    @ObservedObject var delegate: NCUploadAssets
+
+    func makeUIViewController(context: Context) -> UINavigationController {
+
+        let storyboard = UIStoryboard(name: "NCSelect", bundle: nil)
+        let navigationController = storyboard.instantiateInitialViewController() as? UINavigationController
+        let viewController = navigationController?.topViewController as? NCSelect
+
+        viewController?.delegate = delegate
+        viewController?.typeOfCommandView = .selectCreateFolder
+        viewController?.includeDirectoryE2EEncryption = true
+
+        return navigationController!
+    }
+
+    func updateUIViewController(_ uiViewController: UINavigationController, context: Context) { }
+}
+
 // MARK: - Preview
 
 struct UploadAssetsView_Previews: PreviewProvider {
     static var previews: some View {
         if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
-            let uploadAssets = NCUploadAssets(assets: [], cryptated: false, session: "", userBaseUrl: appDelegate, serverUrl: "ABCD")
-            UploadAssetsView(uploadAssets: uploadAssets)
+            let uploadAssets = NCUploadAssets(assets: [], cryptated: false, session: "", userBaseUrl: appDelegate, serverUrl: "/")
+            UploadAssetsView(uploadAssets)
         }
     }
 }

+ 6 - 8
iOSClient/Scan document/NCUploadScanDocument.swift

@@ -496,7 +496,7 @@ struct UploadScanDocumentView: View {
         }
         .background(Color(UIColor.systemGroupedBackground))
         .sheet(isPresented: $isPresentedSelect) {
-            NCSelectRepresentedView(uploadScanDocument: uploadScanDocument)
+            NCSelectScanDocument(delegate: uploadScanDocument)
         }
         .sheet(isPresented: $isPresentedUploadConflict) {
             NCUploadConflictRepresentedView(uploadScanDocument: uploadScanDocument)
@@ -543,10 +543,10 @@ struct ButtonUploadScanDocumenStyle: ButtonStyle {
 
 // MARK: - UIViewControllerRepresentable
 
-struct NCSelectRepresentedView: UIViewControllerRepresentable {
+struct NCSelectScanDocument: UIViewControllerRepresentable {
 
     typealias UIViewControllerType = UINavigationController
-    @ObservedObject var uploadScanDocument: NCUploadScanDocument
+    @ObservedObject var delegate: NCUploadScanDocument
 
     func makeUIViewController(context: Context) -> UINavigationController {
 
@@ -554,15 +554,14 @@ struct NCSelectRepresentedView: UIViewControllerRepresentable {
         let navigationController = storyboard.instantiateInitialViewController() as? UINavigationController
         let viewController = navigationController?.topViewController as? NCSelect
 
-        viewController?.delegate = uploadScanDocument
+        viewController?.delegate = delegate
         viewController?.typeOfCommandView = .selectCreateFolder
         viewController?.includeDirectoryE2EEncryption = true
 
         return navigationController!
     }
 
-    func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {
-    }
+    func updateUIViewController(_ uiViewController: UINavigationController, context: Context) { }
 }
 
 struct NCUploadConflictRepresentedView: UIViewControllerRepresentable {
@@ -583,8 +582,7 @@ struct NCUploadConflictRepresentedView: UIViewControllerRepresentable {
         return viewController!
     }
 
-    func updateUIViewController(_ uiViewController: NCCreateFormUploadConflict, context: Context) {
-    }
+    func updateUIViewController(_ uiViewController: NCCreateFormUploadConflict, context: Context) { }
 }
 
 struct PDFKitRepresentedView: UIViewRepresentable {