NCFileNameView.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. /// Filename
  31. if !model.maintainFilename {
  32. Toggle(NSLocalizedString("_add_filenametype_", comment: ""), isOn: $model.specifyFilename)
  33. .font(.system(size: 16))
  34. .tint(Color(NCBrandColor.shared.brandElement))
  35. .onChange(of: model.specifyFilename, perform: { newValue in
  36. model.toggleAddFilenameType(newValue: newValue)
  37. model.getFileName()
  38. })
  39. }
  40. }
  41. .transition(.slide)
  42. .animation(.easeInOut, value: model.maintainFilename)
  43. /// Filename Preview
  44. fileNamePreview
  45. .animation(.easeInOut, value: model.specifyFilename)
  46. }
  47. .navigationBarTitle(NSLocalizedString("_mode_filename_", comment: ""))
  48. .defaultViewModifier(model)
  49. .padding(.top, 0)
  50. .transition(.slide)
  51. }
  52. @ViewBuilder
  53. var fileNamePreview: some View {
  54. if !model.maintainFilename {
  55. Section(content: {
  56. HStack {
  57. Text(NSLocalizedString("_filename_", comment: ""))
  58. .font(.system(size: 17))
  59. .fontWeight(.medium)
  60. Spacer()
  61. TextField(NSLocalizedString("_filename_header_", comment: ""), text: $model.changedName)
  62. .onChange(of: model.changedName, perform: { _ in
  63. model.submitChangedName()
  64. model.getFileName()
  65. })
  66. .autocapitalization(.none)
  67. .font(.system(size: 15))
  68. .multilineTextAlignment(.trailing)
  69. }
  70. .font(.system(size: 16))
  71. Text("\(model.fileNamePreview)")
  72. .font(.system(size: 16))
  73. .foregroundColor(Color(UIColor.lightGray))
  74. }, header: {
  75. Text(NSLocalizedString("_filename_", comment: ""))
  76. }, footer: {
  77. Text(String(format: NSLocalizedString("_preview_filename_", comment: ""), "MM, MMM, DD, YY, YYYY, HH, hh, mm, ss, ampm"))
  78. })
  79. } else {
  80. Section(content: {
  81. Text("IMG_0001.JPG")
  82. .foregroundColor(Color(UIColor.lightGray))
  83. }, header: {
  84. Text(NSLocalizedString("_filename_", comment: ""))
  85. }, footer: {
  86. Text(NSLocalizedString("_default_preview_filename_footer_", comment: ""))
  87. })
  88. }
  89. }
  90. }
  91. #Preview {
  92. NCFileNameView(model: NCFileNameModel())
  93. }