NCUploadScanDocument.swift 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // NCUploadScanDocument.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 28/12/22.
  6. // Copyright © 2022 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import SwiftUI
  24. import NextcloudKit
  25. import Vision
  26. import VisionKit
  27. import Photos
  28. import PDFKit
  29. // MARK: - Preview / Test
  30. class NCManageUploadScanDocument: NSObject {
  31. @objc func makeShipDetailsUI(account: String) -> UIViewController {
  32. let account = (UIApplication.shared.delegate as? AppDelegate)?.account
  33. let details = UploadScanDocumentView(currentValue: 1.0, password: "", isSecured: true)
  34. let vc = UIHostingController(rootView: details)
  35. vc.title = NSLocalizedString("_save_settings_", comment: "")
  36. return vc
  37. }
  38. }
  39. class NCUploadScanDocument: ObservableObject {
  40. @Published var isTextRecognition: Bool = false
  41. }
  42. extension NCUploadScanDocument: NCSelectDelegate {
  43. func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, items: [Any], overwrite: Bool, copy: Bool, move: Bool) {
  44. }
  45. }
  46. extension NCUploadScanDocument: NCCreateFormUploadConflictDelegate {
  47. func dismissCreateFormUploadConflict(metadatas: [tableMetadata]?) {
  48. }
  49. }
  50. struct UploadScanDocumentView: View {
  51. @ObservedObject var uploadScanDocument = NCUploadScanDocument()
  52. @State var currentValue = 1.0
  53. @State var password: String = ""
  54. @State var isSecured: Bool = true
  55. @State var urlPreviewFile: URL = Bundle.main.url(forResource: "Reasons to use Nextcloud", withExtension: "pdf")!
  56. var body: some View {
  57. GeometryReader { geo in
  58. VStack {
  59. List {
  60. Section(header: Text(NSLocalizedString("_save_path_", comment: ""))) {
  61. HStack {
  62. Label {
  63. Text("/")
  64. .frame(maxWidth: .infinity, alignment: .trailing)
  65. } icon: {
  66. Image("folder")
  67. .renderingMode(.template)
  68. .resizable()
  69. .scaledToFit()
  70. .frame(width: NCBrandSettings.shared.settingsSizeImage, height: NCBrandSettings.shared.settingsSizeImage)
  71. .foregroundColor(Color(NCBrandColor.shared.brand))
  72. }
  73. Spacer()
  74. }
  75. .contentShape(Rectangle())
  76. .onTapGesture {
  77. //
  78. }
  79. }
  80. Section(header: Text(NSLocalizedString("_quality_image_title_", comment: ""))) {
  81. VStack {
  82. Text("Current slider value")
  83. Slider(value: $currentValue, in: 0...3, step: 1) { didChange in
  84. //
  85. }
  86. .accentColor(Color(NCBrandColor.shared.brand))
  87. }
  88. }
  89. Section(header: Text(NSLocalizedString("_preview_", comment: ""))) {
  90. PDFKitRepresentedView(urlPreviewFile)
  91. .frame(width: .infinity, height: geo.size.height / 3)
  92. }
  93. Section(header: Text(NSLocalizedString("_file_creation_", comment: ""))) {
  94. HStack {
  95. Group {
  96. Text(NSLocalizedString("_password_", comment: ""))
  97. if isSecured {
  98. SecureField(NSLocalizedString("_enter_password_", comment: ""), text: $password)
  99. .multilineTextAlignment(.trailing)
  100. } else {
  101. TextField(NSLocalizedString("_enter_password_", comment: ""), text: $password)
  102. .multilineTextAlignment(.trailing)
  103. }
  104. }
  105. Button(action: {
  106. isSecured.toggle()
  107. }) {
  108. Image(systemName: self.isSecured ? "eye.slash" : "eye")
  109. .accentColor(.gray)
  110. }
  111. }
  112. HStack {
  113. Toggle(NSLocalizedString("_text_recognition_", comment: ""), isOn: $uploadScanDocument.isTextRecognition)
  114. .toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand)))
  115. .onChange(of: uploadScanDocument.isTextRecognition) { newValue in
  116. }
  117. }
  118. HStack {
  119. Text(NSLocalizedString("_filename_", comment: ""))
  120. TextField(NSLocalizedString("_enter_filename_", comment: ""), text: $password)
  121. .multilineTextAlignment(.trailing)
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }
  128. }
  129. struct PDFKitRepresentedView: UIViewRepresentable {
  130. let url: URL
  131. init(_ url: URL) {
  132. self.url = url
  133. }
  134. func makeUIView(context: UIViewRepresentableContext<PDFKitRepresentedView>) -> PDFKitRepresentedView.UIViewType {
  135. let pdfView = PDFView()
  136. pdfView.document = PDFDocument(url: self.url)
  137. pdfView.autoScales = true
  138. pdfView.backgroundColor = .clear
  139. pdfView.displayMode = .singlePage
  140. pdfView.displayDirection = .vertical
  141. return pdfView
  142. }
  143. func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PDFKitRepresentedView>) {
  144. }
  145. }
  146. struct UploadScanDocumentView_Previews: PreviewProvider {
  147. static var previews: some View {
  148. // let account = (UIApplication.shared.delegate as! AppDelegate).account
  149. UploadScanDocumentView()
  150. // .previewDevice(PreviewDevice(rawValue: "iPhone 14 Pro"))
  151. // .previewDisplayName("iPhone 14")
  152. }
  153. }