NCUploadScanDocument.swift 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. struct NCUploadScanDocumentTest: View {
  31. @State var currentValue = 1.0
  32. @State var password: String = ""
  33. @State var isSecured: Bool = true
  34. @State var isTextRecognition = true
  35. @State var urlPreviewFile: URL = Bundle.main.url(forResource: "Reasons to use Nextcloud", withExtension: "pdf")!
  36. var body: some View {
  37. GeometryReader { geo in
  38. VStack {
  39. List {
  40. Section(header: Text(NSLocalizedString("_save_path_", comment: ""))) {
  41. HStack {
  42. Label {
  43. Text("/")
  44. .frame(maxWidth: .infinity, alignment: .trailing)
  45. } icon: {
  46. Image("folder")
  47. .renderingMode(.template)
  48. .resizable()
  49. .scaledToFit()
  50. .frame(width: NCBrandSettings.shared.settingsSizeImage, height: NCBrandSettings.shared.settingsSizeImage)
  51. .foregroundColor(Color(NCBrandColor.shared.brand))
  52. }
  53. Spacer()
  54. }
  55. .contentShape(Rectangle())
  56. .onTapGesture {
  57. //
  58. }
  59. }
  60. Section(header: Text(NSLocalizedString("_quality_image_title_", comment: ""))) {
  61. VStack {
  62. Text("Current slider value")
  63. Slider(value: $currentValue, in: 0...3, step: 1) { didChange in
  64. //
  65. }
  66. .accentColor(Color(NCBrandColor.shared.brand))
  67. }
  68. }
  69. Section(header: Text(NSLocalizedString("_preview_", comment: ""))) {
  70. PDFKitRepresentedView(urlPreviewFile)
  71. .frame(width: .infinity, height: geo.size.height / 4)
  72. }
  73. Section(header: Text(NSLocalizedString("_file_creation_", comment: ""))) {
  74. HStack {
  75. Group {
  76. Text(NSLocalizedString("_password_", comment: ""))
  77. if isSecured {
  78. SecureField(NSLocalizedString("_enter_password_", comment: ""), text: $password)
  79. .multilineTextAlignment(.trailing)
  80. } else {
  81. TextField(NSLocalizedString("_enter_password_", comment: ""), text: $password)
  82. .multilineTextAlignment(.trailing)
  83. }
  84. }
  85. Button(action: {
  86. isSecured.toggle()
  87. }) {
  88. Image(systemName: self.isSecured ? "eye.slash" : "eye")
  89. .accentColor(.gray)
  90. }
  91. }
  92. HStack {
  93. Toggle(NSLocalizedString("_text_recognition_", comment: ""), isOn: $isTextRecognition)
  94. .toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand)))
  95. }
  96. HStack {
  97. Text(NSLocalizedString("_filename_", comment: ""))
  98. TextField(NSLocalizedString("_enter_filename_", comment: ""), text: $password)
  99. .multilineTextAlignment(.trailing)
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. struct PDFKitRepresentedView: UIViewRepresentable {
  108. let url: URL
  109. init(_ url: URL) {
  110. self.url = url
  111. }
  112. func makeUIView(context: UIViewRepresentableContext<PDFKitRepresentedView>) -> PDFKitRepresentedView.UIViewType {
  113. let pdfView = PDFView()
  114. pdfView.document = PDFDocument(url: self.url)
  115. pdfView.autoScales = true
  116. pdfView.backgroundColor = .clear
  117. return pdfView
  118. }
  119. func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PDFKitRepresentedView>) {
  120. }
  121. }
  122. struct NCUploadScanDocument_Previews: PreviewProvider {
  123. static var previews: some View {
  124. // let account = (UIApplication.shared.delegate as! AppDelegate).account
  125. NCUploadScanDocumentTest()
  126. }
  127. }