NCFileNameView.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // NCFileNameView.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 26/06/24.
  6. // Copyright © 2024 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. struct NCFileNameView: View {
  25. @ObservedObject var model: NCFileNameModel
  26. var body: some View {
  27. Form {
  28. /// Specify Filename
  29. Section(header: Text(NSLocalizedString("_mode_filename_", comment: ""))) {
  30. ///
  31. Toggle(NSLocalizedString("_maintain_original_filename_", comment: ""), isOn: $model.maintainFilenameOriginal)
  32. .font(.system(size: 16))
  33. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  34. .onChange(of: model.maintainFilenameOriginal, perform: { newValue in
  35. model.toggleMaintainFilenameOriginal(newValue: newValue)
  36. model.getFileName()
  37. })
  38. /// Filename
  39. if !model.maintainFilenameOriginal {
  40. Toggle(NSLocalizedString("_add_filenametype_", comment: ""), isOn: $model.addFileNameType)
  41. .font(.system(size: 16))
  42. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  43. .onChange(of: model.addFileNameType, perform: { newValue in
  44. model.toggleAddFilenameType(newValue: newValue)
  45. model.getFileName()
  46. })
  47. }
  48. }
  49. .transition(.slide)
  50. .animation(.easeInOut, value: model.maintainFilenameOriginal)
  51. /// Filename Preview
  52. fileNamePreview
  53. .animation(.easeInOut, value: model.addFileNameType)
  54. }
  55. .navigationBarTitle(NSLocalizedString("_mode_filename_", comment: ""))
  56. .defaultViewModifier(model)
  57. .padding(.top, 0)
  58. .transition(.slide)
  59. }
  60. @ViewBuilder
  61. var fileNamePreview: some View {
  62. if !model.maintainFilenameOriginal {
  63. Section(content: {
  64. HStack {
  65. Text(NSLocalizedString("_filename_", comment: ""))
  66. .font(.system(size: 17))
  67. .fontWeight(.medium)
  68. Spacer()
  69. TextField(NSLocalizedString("_filename_header_", comment: ""), text: $model.changedName)
  70. .onChange(of: model.changedName, perform: { _ in
  71. model.submitChangedName()
  72. model.getFileName()
  73. })
  74. .autocapitalization(.none)
  75. .font(.system(size: 15))
  76. .multilineTextAlignment(.trailing)
  77. }
  78. .font(.system(size: 16))
  79. Text("\(model.fileNamePreview)")
  80. .font(.system(size: 16))
  81. .foregroundColor(Color(UIColor.lightGray))
  82. }, header: {
  83. Text(NSLocalizedString("_filename_", comment: ""))
  84. }, footer: {
  85. Text(String(format: NSLocalizedString("_preview_filename_", comment: ""), "MM, MMM, DD, YY, YYYY, HH, hh, mm, ss, ampm"))
  86. })
  87. } else {
  88. Section(content: {
  89. Text("IMG_0001.JPG")
  90. .foregroundColor(Color(UIColor.lightGray))
  91. }, header: {
  92. Text(NSLocalizedString("_filename_", comment: ""))
  93. }, footer: {
  94. Text(NSLocalizedString("_default_preview_filename_footer_", comment: ""))
  95. })
  96. }
  97. }
  98. }
  99. #Preview {
  100. NCFileNameView(model: NCFileNameModel(controller: nil))
  101. }