NCUploadScanDocument.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. var body: some View {
  34. GeometryReader { geo in
  35. VStack {
  36. List {
  37. Section(header: Text(NSLocalizedString("_save_path_", comment: ""))) {
  38. HStack {
  39. Label {
  40. Text("/")
  41. .frame(maxWidth: .infinity, alignment: .trailing)
  42. } icon: {
  43. Image("folder")
  44. .renderingMode(.template)
  45. .resizable()
  46. .scaledToFit()
  47. .frame(width: NCBrandSettings.shared.settingsSizeImage, height: NCBrandSettings.shared.settingsSizeImage)
  48. .foregroundColor(Color(NCBrandColor.shared.brand))
  49. }
  50. Spacer()
  51. }
  52. .contentShape(Rectangle())
  53. .onTapGesture {
  54. //
  55. }
  56. }
  57. Section(header: Text(NSLocalizedString("_quality_image_title_", comment: ""))) {
  58. VStack {
  59. Text("Current slider value")
  60. Slider(value: $currentValue, in: 0...3, step: 1) { didChange in
  61. //
  62. }
  63. .accentColor(Color(NCBrandColor.shared.brand))
  64. }
  65. }
  66. Section(header: Text(NSLocalizedString("_preview_", comment: ""))) {
  67. let fileUrl = Bundle.main.url(forResource: "Reasons to use Nextcloud", withExtension: "pdf")!
  68. PDFKitRepresentedView(fileUrl)
  69. .frame(width: .infinity, height: geo.size.height / 3)
  70. }
  71. Section(header: Text(NSLocalizedString("_pdf_password_", comment: ""))) {
  72. HStack {
  73. Text(NSLocalizedString("_password_", comment: ""))
  74. SecureField("Enter password...", text: $password)
  75. .multilineTextAlignment(.trailing)
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. struct PDFKitRepresentedView: UIViewRepresentable {
  84. let url: URL
  85. init(_ url: URL) {
  86. self.url = url
  87. }
  88. func makeUIView(context: UIViewRepresentableContext<PDFKitRepresentedView>) -> PDFKitRepresentedView.UIViewType {
  89. let pdfView = PDFView()
  90. pdfView.document = PDFDocument(url: self.url)
  91. pdfView.autoScales = true
  92. pdfView.backgroundColor = .clear
  93. return pdfView
  94. }
  95. func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PDFKitRepresentedView>) {
  96. }
  97. }
  98. struct NCUploadScanDocument_Previews: PreviewProvider {
  99. static var previews: some View {
  100. // let account = (UIApplication.shared.delegate as! AppDelegate).account
  101. NCUploadScanDocumentTest()
  102. }
  103. }