NCUploadScanDocument.swift 3.6 KB

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