NCAutoUploadView.swift 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // NCAutoUploadView.swift
  3. // Nextcloud
  4. //
  5. // Created by Aditya Tyagi on 06/03/24.
  6. // Created by Marino Faggiana on 30/05/24.
  7. // Copyright © 2024 Marino Faggiana. All rights reserved.
  8. //
  9. // Author Aditya Tyagi <adityagi02@yahoo.com>
  10. //
  11. // This program is free software: you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published by
  13. // the Free Software Foundation, either version 3 of the License, or
  14. // (at your option) any later version.
  15. //
  16. // This program is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU General Public License
  22. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. //
  24. import SwiftUI
  25. import UIKit
  26. /// A view that allows the user to configure the `auto upload settings for Nextcloud`
  27. struct NCAutoUploadView: View {
  28. @ObservedObject var model: NCAutoUploadModel
  29. var body: some View {
  30. Form {
  31. /// Auto Upload
  32. Section(content: {
  33. Toggle(NSLocalizedString("_autoupload_", comment: ""), isOn: $model.autoUpload)
  34. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  35. .onChange(of: model.autoUpload) { newValue in
  36. model.handleAutoUploadChange(newValue: newValue)
  37. }
  38. .font(.system(size: 16))
  39. }, footer: {
  40. Text(NSLocalizedString("_autoupload_notice_", comment: ""))
  41. })
  42. /// If `autoUpload` state will be true, we will animate out the whole `autoUploadOnView` section
  43. if model.autoUpload {
  44. autoUploadOnView
  45. .transition(.slide)
  46. .animation(.easeInOut, value: model.autoUpload)
  47. }
  48. }
  49. .navigationBarTitle(NSLocalizedString("_auto_upload_folder_", comment: ""))
  50. .defaultViewModifier(model)
  51. .alert(model.error, isPresented: $model.showErrorAlert) {
  52. Button(NSLocalizedString("_ok_", comment: ""), role: .cancel) { }
  53. }
  54. .sheet(isPresented: $model.autoUploadFolder) {
  55. SelectView(serverUrl: $model.serverUrl, session: model.session)
  56. .onDisappear {
  57. model.setAutoUploadDirectory(serverUrl: model.serverUrl)
  58. }
  59. }
  60. }
  61. @ViewBuilder
  62. var autoUploadOnView: some View {
  63. Section(content: {
  64. Button(action: {
  65. model.autoUploadFolder.toggle()
  66. }, label: {
  67. HStack {
  68. Image(systemName: "folder")
  69. .resizable()
  70. .scaledToFit()
  71. .font(Font.system(.body).weight(.light))
  72. .frame(width: 25, height: 25)
  73. .foregroundColor(Color(NCBrandColor.shared.iconImageColor))
  74. Text(NSLocalizedString("_autoupload_select_folder_", comment: ""))
  75. }
  76. .font(.system(size: 16))
  77. })
  78. .tint(Color(UIColor.label))
  79. }, footer: {
  80. Text("\(NSLocalizedString("_autoupload_current_folder_", comment: "")): \(model.returnPath())")
  81. })
  82. /// Auto Upload Photo
  83. Section(content: {
  84. Toggle(NSLocalizedString("_autoupload_photos_", comment: ""), isOn: $model.autoUploadImage)
  85. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  86. .onChange(of: model.autoUploadImage) { newValue in
  87. model.handleAutoUploadImageChange(newValue: newValue)
  88. }
  89. .font(.system(size: 16))
  90. Toggle(NSLocalizedString("_wifi_only_", comment: ""), isOn: $model.autoUploadWWAnPhoto)
  91. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  92. .onChange(of: model.autoUploadWWAnPhoto) { newValue in
  93. model.handleAutoUploadWWAnPhotoChange(newValue: newValue)
  94. }
  95. .font(.system(size: 16))
  96. })
  97. /// Auto Upload Video
  98. Section(content: {
  99. Toggle(NSLocalizedString("_autoupload_videos_", comment: ""), isOn: $model.autoUploadVideo)
  100. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  101. .onChange(of: model.autoUploadVideo) { newValue in
  102. model.handleAutoUploadVideoChange(newValue: newValue)
  103. }
  104. .font(.system(size: 16))
  105. Toggle(NSLocalizedString("_wifi_only_", comment: ""), isOn: $model.autoUploadWWAnVideo)
  106. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  107. .onChange(of: model.autoUploadWWAnVideo) { newValue in
  108. model.handleAutoUploadWWAnVideoChange(newValue: newValue)
  109. }
  110. .font(.system(size: 16))
  111. })
  112. /// Only upload favorites if desired
  113. Section(content: {
  114. Toggle(NSLocalizedString("_autoupload_favorites_", comment: ""), isOn: $model.autoUploadFavoritesOnly)
  115. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  116. .onChange(of: model.autoUploadFavoritesOnly) { newValue in
  117. model.handleAutoUploadFavoritesOnlyChange(newValue: newValue)
  118. }
  119. .font(.system(size: 16))
  120. })
  121. /// Auto Upload create subfolder
  122. Section(content: {
  123. Toggle(NSLocalizedString("_autoupload_create_subfolder_", comment: ""), isOn: $model.autoUploadCreateSubfolder)
  124. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  125. .onChange(of: model.autoUploadCreateSubfolder) { newValue in
  126. model.handleAutoUploadCreateSubfolderChange(newValue: newValue)
  127. }
  128. .font(.system(size: 16))
  129. Picker(NSLocalizedString("_autoupload_subfolder_granularity_", comment: ""), selection: $model.autoUploadSubfolderGranularity) {
  130. Text(NSLocalizedString("_daily_", comment: "")).tag(Granularity.daily)
  131. Text(NSLocalizedString("_monthly_", comment: "")).tag(Granularity.monthly)
  132. Text(NSLocalizedString("_yearly_", comment: "")).tag(Granularity.yearly)
  133. }
  134. .font(.system(size: 16))
  135. .onChange(of: model.autoUploadSubfolderGranularity) { newValue in
  136. model.handleAutoUploadSubfolderGranularityChange(newValue: newValue)
  137. }
  138. }, footer: {
  139. Text(NSLocalizedString("_autoupload_create_subfolder_footer_", comment: ""))
  140. })
  141. /// Auto Upload Full
  142. Section(content: {
  143. Toggle(NSLocalizedString("_autoupload_fullphotos_", comment: ""), isOn: $model.autoUploadFull)
  144. .tint(Color(NCBrandColor.shared.getElement(account: model.session.account)))
  145. .onChange(of: model.autoUploadFull) { newValue in
  146. model.handleAutoUploadFullChange(newValue: newValue)
  147. }
  148. .font(.system(size: 16))
  149. }, footer: {
  150. Text(
  151. NSLocalizedString("_autoupload_fullphotos_footer_", comment: "") + "\n \n")
  152. })
  153. }
  154. }
  155. #Preview {
  156. NCAutoUploadView(model: NCAutoUploadModel(controller: nil))
  157. }