// // NCUploadScanDocument.swift // Nextcloud // // Created by Marino Faggiana on 28/12/22. // Copyright © 2022 Marino Faggiana. All rights reserved. // // Author Marino Faggiana // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // import SwiftUI import NextcloudKit import Vision import VisionKit import Photos import PDFKit // MARK: - Preview / Test class NCManageUploadScanDocument: NSObject { @objc func makeShipDetailsUI(account: String) -> UIViewController { let account = (UIApplication.shared.delegate as? AppDelegate)?.account let details = UploadScanDocumentView(currentValue: 1.0, password: "", isSecured: true) let vc = UIHostingController(rootView: details) vc.title = NSLocalizedString("_save_settings_", comment: "") return vc } } class NCUploadScanDocument: ObservableObject { @Published var isTextRecognition: Bool = false } extension NCUploadScanDocument: NCSelectDelegate { func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, items: [Any], overwrite: Bool, copy: Bool, move: Bool) { } } extension NCUploadScanDocument: NCCreateFormUploadConflictDelegate { func dismissCreateFormUploadConflict(metadatas: [tableMetadata]?) { } } struct UploadScanDocumentView: View { @ObservedObject var uploadScanDocument = NCUploadScanDocument() @State var currentValue = 1.0 @State var password: String = "" @State var isSecured: Bool = true @State var urlPreviewFile: URL = Bundle.main.url(forResource: "Reasons to use Nextcloud", withExtension: "pdf")! var body: some View { GeometryReader { geo in VStack { List { Section(header: Text(NSLocalizedString("_save_path_", comment: ""))) { HStack { Label { Text("/") .frame(maxWidth: .infinity, alignment: .trailing) } icon: { Image("folder") .renderingMode(.template) .resizable() .scaledToFit() .frame(width: NCBrandSettings.shared.settingsSizeImage, height: NCBrandSettings.shared.settingsSizeImage) .foregroundColor(Color(NCBrandColor.shared.brand)) } Spacer() } .contentShape(Rectangle()) .onTapGesture { // } } Section(header: Text(NSLocalizedString("_quality_image_title_", comment: ""))) { VStack { Text("Current slider value") Slider(value: $currentValue, in: 0...3, step: 1) { didChange in // } .accentColor(Color(NCBrandColor.shared.brand)) } } Section(header: Text(NSLocalizedString("_preview_", comment: ""))) { PDFKitRepresentedView(urlPreviewFile) .frame(width: .infinity, height: geo.size.height / 3) } Section(header: Text(NSLocalizedString("_file_creation_", comment: ""))) { HStack { Group { Text(NSLocalizedString("_password_", comment: "")) if isSecured { SecureField(NSLocalizedString("_enter_password_", comment: ""), text: $password) .multilineTextAlignment(.trailing) } else { TextField(NSLocalizedString("_enter_password_", comment: ""), text: $password) .multilineTextAlignment(.trailing) } } Button(action: { isSecured.toggle() }) { Image(systemName: self.isSecured ? "eye.slash" : "eye") .accentColor(.gray) } } HStack { Toggle(NSLocalizedString("_text_recognition_", comment: ""), isOn: $uploadScanDocument.isTextRecognition) .toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand))) .onChange(of: uploadScanDocument.isTextRecognition) { newValue in } } HStack { Text(NSLocalizedString("_filename_", comment: "")) TextField(NSLocalizedString("_enter_filename_", comment: ""), text: $password) .multilineTextAlignment(.trailing) } } } } } } } struct PDFKitRepresentedView: UIViewRepresentable { let url: URL init(_ url: URL) { self.url = url } func makeUIView(context: UIViewRepresentableContext) -> PDFKitRepresentedView.UIViewType { let pdfView = PDFView() pdfView.document = PDFDocument(url: self.url) pdfView.autoScales = true pdfView.backgroundColor = .clear pdfView.displayMode = .singlePage pdfView.displayDirection = .vertical return pdfView } func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext) { } } struct UploadScanDocumentView_Previews: PreviewProvider { static var previews: some View { // let account = (UIApplication.shared.delegate as! AppDelegate).account UploadScanDocumentView() // .previewDevice(PreviewDevice(rawValue: "iPhone 14 Pro")) // .previewDisplayName("iPhone 14") } }