CCCreateCloud.swift 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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: Rename File Name
  208. section = XLFormSectionDescriptor.formSection()
  209. form.addFormSection(section)
  210. row = XLFormRowDescriptor(tag: "maskFileName", rowType: XLFormRowDescriptorTypeAccount, title: NSLocalizedString("_filename_", comment: ""))
  211. let fileNameMask : String = CCUtility.getFileNameMask(k_keyFileNameMask)
  212. if fileNameMask.characters.count > 0 {
  213. row.value = fileNameMask
  214. }
  215. section.addFormRow(row)
  216. // Section: Preview File Name
  217. //section = XLFormSectionDescriptor.formSection()
  218. //form.addFormSection(section)
  219. row = XLFormRowDescriptor(tag: "previewFileName", rowType: XLFormRowDescriptorTypeTextView, title: "")
  220. row.height = 180
  221. row.cellConfig.setObject(NCBrandColor.sharedInstance.tableBackground, forKey: "backgroundColor" as NSCopying)
  222. row.cellConfig.setObject(NCBrandColor.sharedInstance.tableBackground, forKey: "textView.backgroundColor" as NSCopying)
  223. row.disabled = true
  224. section.addFormRow(row)
  225. self.form = form
  226. }
  227. override func formRowDescriptorValueHasChanged(_ formRow: XLFormRowDescriptor!, oldValue: Any!, newValue: Any!) {
  228. super.formRowDescriptorValueHasChanged(formRow, oldValue: oldValue, newValue: newValue)
  229. if formRow.tag == "useFolderPhoto" {
  230. if (formRow.value! as AnyObject).boolValue == true {
  231. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  232. buttonDestinationFolder.hidden = true
  233. } else{
  234. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  235. buttonDestinationFolder.hidden = false
  236. }
  237. }
  238. else if formRow.tag == "useSubFolder" {
  239. if (formRow.value! as AnyObject).boolValue == true {
  240. } else{
  241. }
  242. }
  243. else if formRow.tag == "maskFileName" {
  244. let fileName : String? = formRow.value as? String
  245. self.form.delegate = nil
  246. if fileName != nil {
  247. formRow.value = CCUtility.removeForbiddenCharactersServer(fileName)
  248. }
  249. self.form.delegate = self
  250. let previewFileName : XLFormRowDescriptor = self.form.formRow(withTag: "previewFileName")!
  251. previewFileName.value = self.previewFileName(valueRename: formRow.value as? String)
  252. // reload cell
  253. if fileName != nil {
  254. if newValue as! String != formRow.value as! String {
  255. self.reloadFormRow(formRow)
  256. appDelegate.messageNotification("_info_", description: "_forbidden_characters_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.info, errorCode: 0)
  257. }
  258. }
  259. self.reloadFormRow(previewFileName)
  260. }
  261. }
  262. // MARK: - View Life Cycle
  263. override func viewDidLoad() {
  264. super.viewDidLoad()
  265. let cancelButton : UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_cancel_", comment: ""), style: UIBarButtonItemStyle.plain, target: self, action: #selector(cancel))
  266. let saveButton : UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_save_", comment: ""), style: UIBarButtonItemStyle.plain, target: self, action: #selector(save))
  267. self.navigationItem.leftBarButtonItem = cancelButton
  268. self.navigationItem.rightBarButtonItem = saveButton
  269. self.navigationController?.navigationBar.isTranslucent = false
  270. self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.brand
  271. self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.navigationBarText
  272. self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: NCBrandColor.sharedInstance.navigationBarText]
  273. self.tableView.separatorStyle = UITableViewCellSeparatorStyle.none
  274. self.tableView.backgroundColor = NCBrandColor.sharedInstance.tableBackground
  275. self.reloadForm()
  276. }
  277. override func viewWillDisappear(_ animated: Bool)
  278. {
  279. self.delegate?.dismissFormUploadAssets()
  280. super.viewWillDisappear(animated)
  281. }
  282. func reloadForm() {
  283. self.form.delegate = nil
  284. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  285. buttonDestinationFolder.title = self.titleServerUrl
  286. let maskFileName : XLFormRowDescriptor = self.form.formRow(withTag: "maskFileName")!
  287. let previewFileName : XLFormRowDescriptor = self.form.formRow(withTag: "previewFileName")!
  288. previewFileName.value = self.previewFileName(valueRename: maskFileName.value as? String)
  289. self.tableView.reloadData()
  290. self.form.delegate = self
  291. }
  292. //MARK: TableView
  293. override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
  294. switch section {
  295. case 0:
  296. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  297. if buttonDestinationFolder.isHidden() {
  298. return ""
  299. } else {
  300. return " " + NSLocalizedString("_destination_folder_", comment: "")
  301. }
  302. case 1:
  303. return " " + NSLocalizedString("_use_folder_photos_", comment: "")
  304. case 2:
  305. return " " + NSLocalizedString("_rename_filename_", comment: "")
  306. case 3:
  307. return NSLocalizedString("_preview_filename_", comment: "")
  308. default:
  309. return ""
  310. }
  311. }
  312. override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
  313. switch section {
  314. /*
  315. case 2:
  316. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "maskFileName")!
  317. let text = self.writePreviewFileName(buttonDestinationFolder)
  318. return text
  319. */
  320. default:
  321. return ""
  322. }
  323. }
  324. // MARK: - Action
  325. func moveServerUrl(to serverUrlTo: String!, title: String!) {
  326. self.serverUrl = serverUrlTo
  327. if title == nil {
  328. self.titleServerUrl = "/"
  329. } else {
  330. self.titleServerUrl = title
  331. }
  332. self.reloadForm()
  333. }
  334. func save() {
  335. self.dismiss(animated: true, completion: {
  336. let useFolderPhotoRow : XLFormRowDescriptor = self.form.formRow(withTag: "useFolderPhoto")!
  337. let useSubFolderRow : XLFormRowDescriptor = self.form.formRow(withTag: "useSubFolder")!
  338. var useSubFolder : Bool = false
  339. if (useFolderPhotoRow.value! as AnyObject).boolValue == true {
  340. self.serverUrl = NCManageDatabase.sharedInstance.getAccountAutoUploadPath(self.appDelegate.activeUrl)
  341. useSubFolder = (useSubFolderRow.value! as AnyObject).boolValue
  342. }
  343. self.appDelegate.activeMain.uploadFileAsset(self.assets, serverUrl: self.serverUrl, cryptated: self.cryptated, useSubFolder: useSubFolder, session: self.session)
  344. })
  345. }
  346. func cancel() {
  347. self.dismiss(animated: true, completion: nil)
  348. }
  349. // MARK: - Utility
  350. func previewFileName(valueRename : String?) -> String {
  351. var returnString : String = ""
  352. if valueRename != nil {
  353. let valueRenameTrimming = valueRename!.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
  354. if valueRenameTrimming.characters.count > 0 {
  355. self.form.delegate = nil
  356. CCUtility.setFileNameMask(valueRenameTrimming, key: k_keyFileNameMask)
  357. self.form.delegate = self
  358. returnString = CCUtility.createFileName(from: assets[0] as! PHAsset, key: k_keyFileNameMask)
  359. } else {
  360. CCUtility.setFileNameMask("", key: k_keyFileNameMask)
  361. returnString = CCUtility.createFileName(from: assets[0] as! PHAsset, key: nil)
  362. }
  363. } else {
  364. CCUtility.setFileNameMask("", key: k_keyFileNameMask)
  365. returnString = CCUtility.createFileName(from: assets[0] as! PHAsset, key: nil)
  366. }
  367. return NSLocalizedString("_preview_filename_", comment: "") + ":" + "\n\n" + returnString
  368. }
  369. func changeDestinationFolder(_ sender: XLFormRowDescriptor) {
  370. self.deselectFormRow(sender)
  371. let storyboard : UIStoryboard = UIStoryboard(name: "CCMove", bundle: nil)
  372. let navigationController = storyboard.instantiateViewController(withIdentifier: "CCMove") as! UINavigationController
  373. let viewController : CCMove = navigationController.topViewController as! CCMove
  374. viewController.delegate = self;
  375. viewController.tintColor = NCBrandColor.sharedInstance.navigationBarText
  376. viewController.barTintColor = NCBrandColor.sharedInstance.brand
  377. viewController.tintColorTitle = NCBrandColor.sharedInstance.navigationBarText
  378. viewController.move.title = NSLocalizedString("_select_", comment: "");
  379. viewController.networkingOperationQueue = appDelegate.netQueue
  380. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  381. self.present(navigationController, animated: true, completion: nil)
  382. }
  383. }