CCCreateCloud.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. //
  2. // CCCreateCloud.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 09/01/17.
  6. // Copyright © 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  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 Foundation
  24. // MARK: - CreateMenuAdd
  25. class CreateMenuAdd: NSObject {
  26. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  27. let fontButton = [NSFontAttributeName:UIFont(name: "HelveticaNeue", size: 16)!, NSForegroundColorAttributeName: UIColor(colorLiteralRed: 65.0/255.0, green: 64.0/255.0, blue: 66.0/255.0, alpha: 1.0)]
  28. let fontEncrypted = [NSFontAttributeName:UIFont(name: "HelveticaNeue", size: 16)!, NSForegroundColorAttributeName: NCBrandColor.sharedInstance.cryptocloud] as [String : Any]
  29. let fontCancel = [NSFontAttributeName:UIFont(name: "HelveticaNeue", size: 16)!, NSForegroundColorAttributeName: NCBrandColor.sharedInstance.brand] as [String : Any]
  30. let fontDisable = [NSFontAttributeName:UIFont(name: "HelveticaNeue", size: 16)!, NSForegroundColorAttributeName: UIColor(colorLiteralRed: 65.0/255.0, green: 64.0/255.0, blue: 66.0/255.0, alpha: 1.0)]
  31. let colorLightGray = UIColor(colorLiteralRed: 250.0/255.0, green: 250.0/255.0, blue: 250.0/255.0, alpha: 1)
  32. var colorIcon = NCBrandColor.sharedInstance.brand
  33. init (themingColor : UIColor) {
  34. super.init()
  35. colorIcon = themingColor
  36. }
  37. func createMenuPlain(view : UIView) {
  38. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  39. let actionSheet = AHKActionSheet.init(view: view, title: nil)!
  40. actionSheet.animationDuration = 0.2
  41. actionSheet.automaticallyTintButtonImages = 0
  42. actionSheet.blurRadius = 0.0
  43. actionSheet.blurTintColor = UIColor(white: 0.0, alpha: 0.50)
  44. actionSheet.buttonHeight = 50.0
  45. actionSheet.cancelButtonHeight = 50.0
  46. actionSheet.separatorHeight = 5.0
  47. actionSheet.separatorColor = NCBrandColor.sharedInstance.seperator
  48. actionSheet.buttonTextAttributes = fontButton
  49. actionSheet.encryptedButtonTextAttributes = fontEncrypted
  50. actionSheet.cancelButtonTextAttributes = fontCancel
  51. actionSheet.disableButtonTextAttributes = fontDisable
  52. actionSheet.cancelButtonTitle = NSLocalizedString("_cancel_", comment: "")
  53. actionSheet.addButton(withTitle: NSLocalizedString("_create_folder_", comment: ""), image: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), color: colorIcon), backgroundColor: UIColor.white, height: 50.0 ,type: AHKActionSheetButtonType.default, handler: {(AHKActionSheet) -> Void in
  54. appDelegate.activeMain.returnCreate(Int(k_returnCreateFolderPlain))
  55. })
  56. actionSheet.addButton(withTitle: NSLocalizedString("_upload_photos_videos_", comment: ""), image: CCGraphics.changeThemingColorImage(UIImage(named: "menuUploadPhoto"), color: colorIcon), backgroundColor: UIColor.white, height: 50.0, type: AHKActionSheetButtonType.default, handler: {(AHKActionSheet) -> Void in
  57. appDelegate.activeMain.returnCreate(Int(k_returnCreateFotoVideoPlain))
  58. })
  59. actionSheet.addButton(withTitle: NSLocalizedString("_upload_file_", comment: ""), image: CCGraphics.changeThemingColorImage(UIImage(named: "menuUploadFile"), color: colorIcon), backgroundColor: UIColor.white, height: 50.0, type: AHKActionSheetButtonType.default, handler: {(AHKActionSheet) -> Void in
  60. appDelegate.activeMain.returnCreate(Int(k_returnCreateFilePlain))
  61. })
  62. if appDelegate.isCryptoCloudMode {
  63. actionSheet.addButton(withTitle: NSLocalizedString("_upload_encrypted_mode", comment: ""), image: UIImage(named: "actionSheetLock"), backgroundColor: colorLightGray, height: 50.0, type: AHKActionSheetButtonType.encrypted, handler: {(AHKActionSheet) -> Void in
  64. self.createMenuEncrypted(view: view)
  65. })
  66. }
  67. actionSheet.show()
  68. CCUtility.setCreateMenuEncrypted(false)
  69. }
  70. func createMenuEncrypted(view : UIView) {
  71. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  72. let actionSheet = AHKActionSheet.init(view: view, title: nil)!
  73. actionSheet.animationDuration = 0.2
  74. actionSheet.blurRadius = 0.0
  75. actionSheet.blurTintColor = UIColor(white: 0.0, alpha: 0.50)
  76. actionSheet.buttonHeight = 50.0
  77. actionSheet.cancelButtonHeight = 50.0
  78. actionSheet.separatorHeight = 5.0
  79. actionSheet.separatorColor = NCBrandColor.sharedInstance.seperator
  80. actionSheet.buttonTextAttributes = fontButton
  81. actionSheet.encryptedButtonTextAttributes = fontEncrypted
  82. actionSheet.cancelButtonTextAttributes = fontCancel
  83. actionSheet.disableButtonTextAttributes = fontDisable
  84. actionSheet.cancelButtonTitle = NSLocalizedString("_cancel_", comment: "")
  85. actionSheet.addButton(withTitle: NSLocalizedString("_create_folder_", comment: ""), image: UIImage(named: "foldercrypto"), backgroundColor: UIColor.white, height: 50.0, type: AHKActionSheetButtonType.encrypted, handler: {(AHKActionSheet) -> Void in
  86. appDelegate.activeMain.returnCreate(Int(k_returnCreateFolderEncrypted))
  87. })
  88. actionSheet.addButton(withTitle: NSLocalizedString("_upload_photos_videos_", comment: ""), image: UIImage(named: "menuUploadPhotoCrypto"), backgroundColor: UIColor.white, height: 50.0, type: AHKActionSheetButtonType.encrypted, handler: {(AHKActionSheet) -> Void in
  89. appDelegate.activeMain.returnCreate(Int(k_returnCreateFotoVideoEncrypted))
  90. })
  91. actionSheet.addButton(withTitle: NSLocalizedString("_upload_file_", comment: ""), image: UIImage(named: "menuUploadFileCrypto"), backgroundColor: UIColor.white, height: 50.0, type: AHKActionSheetButtonType.encrypted, handler: {(AHKActionSheet) -> Void in
  92. appDelegate.activeMain.returnCreate(Int(k_returnCreateFileEncrypted))
  93. })
  94. actionSheet.addButton(withTitle: NSLocalizedString("_upload_template_", comment: ""), image: UIImage(named: "menuTemplate"), backgroundColor: colorLightGray, height: 50.0, type: AHKActionSheetButtonType.encrypted, handler: {(AHKActionSheet) -> Void in
  95. self.createMenuTemplate(view: view)
  96. })
  97. actionSheet.addButton(withTitle: NSLocalizedString("_upload_plain_mode", comment: ""), image: UIImage(named: "menuUploadPlainMode"), backgroundColor: colorLightGray, height: 50.0, type: AHKActionSheetButtonType.default, handler: {(AHKActionSheet) -> Void in
  98. self.createMenuPlain(view: view)
  99. })
  100. actionSheet.show()
  101. CCUtility.setCreateMenuEncrypted(true)
  102. }
  103. func createMenuTemplate(view : UIView) {
  104. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  105. let actionSheet = AHKActionSheet.init(view: view, title: nil)!
  106. actionSheet.animationDuration = 0.2
  107. actionSheet.blurRadius = 0.0
  108. actionSheet.blurTintColor = UIColor(white: 0.0, alpha: 0.50)
  109. actionSheet.buttonHeight = 50.0
  110. actionSheet.cancelButtonHeight = 50.0
  111. actionSheet.separatorHeight = 5.0
  112. actionSheet.separatorColor = NCBrandColor.sharedInstance.seperator
  113. actionSheet.buttonTextAttributes = fontButton
  114. actionSheet.encryptedButtonTextAttributes = fontEncrypted
  115. actionSheet.cancelButtonTextAttributes = fontCancel
  116. actionSheet.disableButtonTextAttributes = fontDisable
  117. actionSheet.cancelButtonTitle = NSLocalizedString("_cancel_", comment: "")
  118. actionSheet.addButton(withTitle: NSLocalizedString("_add_notes_", comment: ""), image: UIImage(named: "note"), backgroundColor: UIColor.white, height: 50.0, type: AHKActionSheetButtonType.encrypted, handler: {(AHKActionSheet) -> Void in
  119. appDelegate.activeMain.returnCreate(Int(k_returnNote))
  120. })
  121. actionSheet.addButton(withTitle: NSLocalizedString("_add_web_account_", comment: ""), image: UIImage(named: "templateWebAccount"), backgroundColor: UIColor.white, height: 50.0, type: AHKActionSheetButtonType.encrypted, handler: {(AHKActionSheet) -> Void in
  122. appDelegate.activeMain.returnCreate(Int(k_returnAccountWeb))
  123. })
  124. actionSheet.addButton(withTitle: "", image: nil, backgroundColor: UIColor(colorLiteralRed: 250.0/255.0, green: 250.0/255.0, blue: 250.0/255.0, alpha: 1), height: 10.0, type: AHKActionSheetButtonType.disabled, handler: {(AHKActionSheet) -> Void in
  125. print("disable")
  126. })
  127. actionSheet.addButton(withTitle: NSLocalizedString("_add_credit_card_", comment: ""), image: UIImage(named: "cartadicredito"), backgroundColor: UIColor.white, height: 50.0, type: AHKActionSheetButtonType.encrypted, handler: {(AHKActionSheet) -> Void in
  128. appDelegate.activeMain.returnCreate(Int(k_returnCartaDiCredito))
  129. })
  130. actionSheet.addButton(withTitle: NSLocalizedString("_add_atm_", comment: ""), image: UIImage(named: "bancomat"), backgroundColor: UIColor.white, height: 50.0, type: AHKActionSheetButtonType.encrypted, handler: {(AHKActionSheet) -> Void in
  131. appDelegate.activeMain.returnCreate(Int(k_returnBancomat))
  132. })
  133. actionSheet.addButton(withTitle: NSLocalizedString("_add_bank_account_", comment: ""), image: UIImage(named: "contocorrente"), backgroundColor: UIColor.white, height: 50.0, type: AHKActionSheetButtonType.encrypted, handler: {(AHKActionSheet) -> Void in
  134. appDelegate.activeMain.returnCreate(Int(k_returnContoCorrente))
  135. })
  136. actionSheet.addButton(withTitle: "", image: nil, backgroundColor: UIColor(colorLiteralRed: 250.0/255.0, green: 250.0/255.0, blue: 250.0/255.0, alpha: 1), height: 10.0, type: AHKActionSheetButtonType.disabled, handler: {(AHKActionSheet) -> Void in
  137. print("disable")
  138. })
  139. actionSheet.addButton(withTitle: NSLocalizedString("_add_driving_license_", comment: ""), image: UIImage(named: "patenteguida"), backgroundColor: UIColor.white, height: 50.0, type: AHKActionSheetButtonType.encrypted, handler: {(AHKActionSheet) -> Void in
  140. appDelegate.activeMain.returnCreate(Int(k_returnPatenteGuida))
  141. })
  142. actionSheet.addButton(withTitle: NSLocalizedString("_add_id_card_", comment: ""), image: UIImage(named: "cartaidentita"), backgroundColor: UIColor.white, height: 50.0, type: AHKActionSheetButtonType.encrypted, handler: {(AHKActionSheet) -> Void in
  143. appDelegate.activeMain.returnCreate(Int(k_returnCartaIdentita))
  144. })
  145. actionSheet.addButton(withTitle: NSLocalizedString("_add_passport_", comment: ""), image: UIImage(named: "passaporto"), backgroundColor: UIColor.white, height: 50.0, type: AHKActionSheetButtonType.encrypted, handler: {(AHKActionSheet) -> Void in
  146. appDelegate.activeMain.returnCreate(Int(k_returnPassaporto))
  147. })
  148. actionSheet.show()
  149. }
  150. }
  151. // MARK: - CreateFormUploadAssets
  152. @objc protocol createFormUploadAssetsDelegate {
  153. func dismissFormUploadAssets()
  154. }
  155. class CreateFormUploadAssets: XLFormViewController, CCMoveDelegate {
  156. var serverUrl : String = ""
  157. var titleServerUrl : String?
  158. var assets: NSMutableArray = []
  159. var cryptated : Bool = false
  160. var session : String = ""
  161. weak var delegate: createFormUploadAssetsDelegate?
  162. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  163. convenience init(_ titleServerUrl : String?, serverUrl : String, assets : NSMutableArray, cryptated : Bool, session : String, delegate: createFormUploadAssetsDelegate) {
  164. self.init()
  165. if titleServerUrl == nil || titleServerUrl?.isEmpty == true {
  166. self.titleServerUrl = "/"
  167. } else {
  168. self.titleServerUrl = titleServerUrl
  169. }
  170. self.serverUrl = serverUrl
  171. self.assets = assets
  172. self.cryptated = cryptated
  173. self.session = session
  174. self.delegate = delegate
  175. self.initializeForm()
  176. }
  177. //MARK: XLFormDescriptorDelegate
  178. func initializeForm() {
  179. let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor
  180. form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow
  181. var section : XLFormSectionDescriptor
  182. var row : XLFormRowDescriptor
  183. // Section: Destination Folder
  184. section = XLFormSectionDescriptor.formSection()
  185. form.addFormSection(section)
  186. row = XLFormRowDescriptor(tag: "ButtonDestinationFolder", rowType: XLFormRowDescriptorTypeButton, title: self.titleServerUrl)
  187. let imageFolder = CCGraphics.changeThemingColorImage(UIImage(named: "folder")!, color: NCBrandColor.sharedInstance.brand) as UIImage
  188. row.cellConfig.setObject(imageFolder, forKey: "imageView.image" as NSCopying)
  189. row.cellConfig.setObject(UIColor.black, forKey: "textLabel.textColor" as NSCopying)
  190. row.action.formSelector = #selector(changeDestinationFolder(_:))
  191. section.addFormRow(row)
  192. // Section: Folder Photo
  193. section = XLFormSectionDescriptor.formSection()
  194. form.addFormSection(section)
  195. row = XLFormRowDescriptor(tag: "useFolderPhoto", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_photo_camera_", comment: ""))
  196. row.value = 0
  197. section.addFormRow(row)
  198. row = XLFormRowDescriptor(tag: "useSubFolder", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_autoupload_create_subfolder_", comment: ""))
  199. row.hidden = "$\("useFolderPhoto") == 0"
  200. let tableAccount = NCManageDatabase.sharedInstance.getAccountActive()
  201. if tableAccount?.autoUploadCreateSubfolder == true {
  202. row.value = 1
  203. } else {
  204. row.value = 0
  205. }
  206. section.addFormRow(row)
  207. // Section: Add File Name Type
  208. section = XLFormSectionDescriptor.formSection()
  209. form.addFormSection(section)
  210. row = XLFormRowDescriptor(tag: "addFileNameType", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_filenametype_photo_video_", comment: ""))
  211. row.value = CCUtility.getFileNameType(k_keyFileNameType)
  212. section.addFormRow(row)
  213. // Section: Rename File Name
  214. section = XLFormSectionDescriptor.formSection()
  215. form.addFormSection(section)
  216. row = XLFormRowDescriptor(tag: "maskFileName", rowType: XLFormRowDescriptorTypeAccount, title: NSLocalizedString("_filename_", comment: ""))
  217. let fileNameMask : String = CCUtility.getFileNameMask(k_keyFileNameMask)
  218. if fileNameMask.characters.count > 0 {
  219. row.value = fileNameMask
  220. }
  221. section.addFormRow(row)
  222. // Section: Preview File Name
  223. //section = XLFormSectionDescriptor.formSection()
  224. //form.addFormSection(section)
  225. row = XLFormRowDescriptor(tag: "previewFileName", rowType: XLFormRowDescriptorTypeTextView, title: "")
  226. row.height = 180
  227. row.cellConfig.setObject(NCBrandColor.sharedInstance.tableBackground, forKey: "backgroundColor" as NSCopying)
  228. row.cellConfig.setObject(NCBrandColor.sharedInstance.tableBackground, forKey: "textView.backgroundColor" as NSCopying)
  229. row.disabled = true
  230. section.addFormRow(row)
  231. self.form = form
  232. }
  233. override func formRowDescriptorValueHasChanged(_ formRow: XLFormRowDescriptor!, oldValue: Any!, newValue: Any!) {
  234. super.formRowDescriptorValueHasChanged(formRow, oldValue: oldValue, newValue: newValue)
  235. if formRow.tag == "useFolderPhoto" {
  236. if (formRow.value! as AnyObject).boolValue == true {
  237. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  238. buttonDestinationFolder.hidden = true
  239. } else{
  240. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  241. buttonDestinationFolder.hidden = false
  242. }
  243. }
  244. else if formRow.tag == "useSubFolder" {
  245. if (formRow.value! as AnyObject).boolValue == true {
  246. } else{
  247. }
  248. }
  249. else if formRow.tag == "addFileNameType" {
  250. CCUtility.setFileNameType((formRow.value! as AnyObject).boolValue, key: k_keyFileNameType)
  251. self.reloadForm()
  252. }
  253. else if formRow.tag == "maskFileName" {
  254. let fileName = formRow.value as? String
  255. self.form.delegate = nil
  256. if let fileName = fileName {
  257. formRow.value = CCUtility.removeForbiddenCharactersServer(fileName)
  258. }
  259. self.form.delegate = self
  260. let previewFileName : XLFormRowDescriptor = self.form.formRow(withTag: "previewFileName")!
  261. previewFileName.value = self.previewFileName(valueRename: formRow.value as? String)
  262. // reload cell
  263. if fileName != nil {
  264. if newValue as! String != formRow.value as! String {
  265. self.reloadFormRow(formRow)
  266. appDelegate.messageNotification("_info_", description: "_forbidden_characters_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.info, errorCode: 0)
  267. }
  268. }
  269. self.reloadFormRow(previewFileName)
  270. }
  271. }
  272. // MARK: - View Life Cycle
  273. override func viewDidLoad() {
  274. super.viewDidLoad()
  275. let cancelButton : UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_cancel_", comment: ""), style: UIBarButtonItemStyle.plain, target: self, action: #selector(cancel))
  276. let saveButton : UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_save_", comment: ""), style: UIBarButtonItemStyle.plain, target: self, action: #selector(save))
  277. self.navigationItem.leftBarButtonItem = cancelButton
  278. self.navigationItem.rightBarButtonItem = saveButton
  279. self.navigationController?.navigationBar.isTranslucent = false
  280. self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.brand
  281. self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.navigationBarText
  282. self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: NCBrandColor.sharedInstance.navigationBarText]
  283. self.tableView.separatorStyle = UITableViewCellSeparatorStyle.none
  284. self.tableView.backgroundColor = NCBrandColor.sharedInstance.tableBackground
  285. self.reloadForm()
  286. }
  287. override func viewWillDisappear(_ animated: Bool)
  288. {
  289. super.viewWillDisappear(animated)
  290. self.delegate?.dismissFormUploadAssets()
  291. }
  292. func reloadForm() {
  293. self.form.delegate = nil
  294. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  295. buttonDestinationFolder.title = self.titleServerUrl
  296. let maskFileName : XLFormRowDescriptor = self.form.formRow(withTag: "maskFileName")!
  297. let previewFileName : XLFormRowDescriptor = self.form.formRow(withTag: "previewFileName")!
  298. previewFileName.value = self.previewFileName(valueRename: maskFileName.value as? String)
  299. self.tableView.reloadData()
  300. self.form.delegate = self
  301. }
  302. //MARK: TableView
  303. override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
  304. switch section {
  305. case 0:
  306. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  307. if buttonDestinationFolder.isHidden() {
  308. return ""
  309. } else {
  310. return " " + NSLocalizedString("_destination_folder_", comment: "")
  311. }
  312. case 1:
  313. return " " + NSLocalizedString("_use_folder_photos_", comment: "")
  314. case 2:
  315. return " " + NSLocalizedString("_add_filenametype_", comment: "")
  316. case 3:
  317. return " " + NSLocalizedString("_rename_filename_", comment: "")
  318. case 4:
  319. return NSLocalizedString("_preview_filename_", comment: "")
  320. default:
  321. return ""
  322. }
  323. }
  324. override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
  325. switch section {
  326. /*
  327. case 2:
  328. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "maskFileName")!
  329. let text = self.writePreviewFileName(buttonDestinationFolder)
  330. return text
  331. */
  332. default:
  333. return ""
  334. }
  335. }
  336. // MARK: - Action
  337. func moveServerUrl(to serverUrlTo: String!, title: String!) {
  338. self.serverUrl = serverUrlTo
  339. if let title = title {
  340. self.titleServerUrl = title
  341. } else {
  342. self.titleServerUrl = "/"
  343. }
  344. self.reloadForm()
  345. }
  346. func save() {
  347. self.dismiss(animated: true, completion: {
  348. let useFolderPhotoRow : XLFormRowDescriptor = self.form.formRow(withTag: "useFolderPhoto")!
  349. let useSubFolderRow : XLFormRowDescriptor = self.form.formRow(withTag: "useSubFolder")!
  350. var useSubFolder : Bool = false
  351. if (useFolderPhotoRow.value! as AnyObject).boolValue == true {
  352. self.serverUrl = NCManageDatabase.sharedInstance.getAccountAutoUploadPath(self.appDelegate.activeUrl)
  353. useSubFolder = (useSubFolderRow.value! as AnyObject).boolValue
  354. }
  355. self.appDelegate.activeMain.uploadFileAsset(self.assets, serverUrl: self.serverUrl, cryptated: self.cryptated, useSubFolder: useSubFolder, session: self.session)
  356. })
  357. }
  358. func cancel() {
  359. self.dismiss(animated: true, completion: nil)
  360. }
  361. // MARK: - Utility
  362. func previewFileName(valueRename : String?) -> String {
  363. var returnString : String = ""
  364. let asset = assets[0] as! PHAsset
  365. if let valueRename = valueRename {
  366. let valueRenameTrimming = valueRename.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
  367. if valueRenameTrimming.characters.count > 0 {
  368. self.form.delegate = nil
  369. CCUtility.setFileNameMask(valueRenameTrimming, key: k_keyFileNameMask)
  370. self.form.delegate = self
  371. returnString = CCUtility.createFileName(asset.value(forKey: "filename"), fileDate: asset.creationDate, fileType: asset.mediaType, keyFileName: k_keyFileNameMask, keyFileNameType: k_keyFileNameType)
  372. } else {
  373. CCUtility.setFileNameMask("", key: k_keyFileNameMask)
  374. returnString = CCUtility.createFileName(asset.value(forKey: "filename"), fileDate: asset.creationDate, fileType: asset.mediaType, keyFileName: nil, keyFileNameType: k_keyFileNameType)
  375. }
  376. } else {
  377. CCUtility.setFileNameMask("", key: k_keyFileNameMask)
  378. returnString = CCUtility.createFileName(asset.value(forKey: "filename"), fileDate: asset.creationDate, fileType: asset.mediaType, keyFileName: nil, keyFileNameType: k_keyFileNameType)
  379. }
  380. return NSLocalizedString("_preview_filename_", comment: "") + ":" + "\n\n" + returnString
  381. }
  382. func changeDestinationFolder(_ sender: XLFormRowDescriptor) {
  383. self.deselectFormRow(sender)
  384. let storyboard : UIStoryboard = UIStoryboard(name: "CCMove", bundle: nil)
  385. let navigationController = storyboard.instantiateViewController(withIdentifier: "CCMove") as! UINavigationController
  386. let viewController : CCMove = navigationController.topViewController as! CCMove
  387. viewController.delegate = self;
  388. viewController.tintColor = NCBrandColor.sharedInstance.navigationBarText
  389. viewController.barTintColor = NCBrandColor.sharedInstance.brand
  390. viewController.tintColorTitle = NCBrandColor.sharedInstance.navigationBarText
  391. viewController.move.title = NSLocalizedString("_select_", comment: "");
  392. viewController.networkingOperationQueue = appDelegate.netQueue
  393. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  394. self.present(navigationController, animated: true, completion: nil)
  395. }
  396. }