CCCreateCloud.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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. class CreateFormUploadAssets: XLFormViewController, CCMoveDelegate {
  153. var serverUrl : String = ""
  154. var titleServerUrl : String?
  155. var assets: NSMutableArray = []
  156. var cryptated : Bool = false
  157. var session : String = ""
  158. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  159. convenience init(_ titleServerUrl : String?, serverUrl : String, assets : NSMutableArray, cryptated : Bool, session : String) {
  160. self.init()
  161. if titleServerUrl == nil || titleServerUrl?.isEmpty == true {
  162. self.titleServerUrl = "/"
  163. } else {
  164. self.titleServerUrl = titleServerUrl
  165. }
  166. self.serverUrl = serverUrl
  167. self.assets = assets
  168. self.cryptated = cryptated
  169. self.session = session
  170. self.initializeForm()
  171. }
  172. //MARK: XLFormDescriptorDelegate
  173. func initializeForm() {
  174. let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor
  175. form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow
  176. var section : XLFormSectionDescriptor
  177. var row : XLFormRowDescriptor
  178. // Section: Destination Folder
  179. section = XLFormSectionDescriptor.formSection()
  180. form.addFormSection(section)
  181. row = XLFormRowDescriptor(tag: "ButtonDestinationFolder", rowType: XLFormRowDescriptorTypeButton, title: self.titleServerUrl)
  182. let imageFolder = CCGraphics.changeThemingColorImage(UIImage(named: "folder")!, color: NCBrandColor.sharedInstance.brand) as UIImage
  183. row.cellConfig.setObject(imageFolder, forKey: "imageView.image" as NSCopying)
  184. row.cellConfig.setObject(UIColor.black, forKey: "textLabel.textColor" as NSCopying)
  185. row.action.formSelector = #selector(changeDestinationFolder(_:))
  186. section.addFormRow(row)
  187. // Section: Folder Photo
  188. section = XLFormSectionDescriptor.formSection()
  189. form.addFormSection(section)
  190. row = XLFormRowDescriptor(tag: "useFolderPhoto", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_photo_camera_", comment: ""))
  191. row.value = 0
  192. section.addFormRow(row)
  193. row = XLFormRowDescriptor(tag: "useSubFolder", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_autoupload_create_subfolder_", comment: ""))
  194. row.hidden = "$\("useFolderPhoto") == 0"
  195. let tableAccount = NCManageDatabase.sharedInstance.getAccountActive()
  196. if tableAccount?.autoUploadCreateSubfolder == true {
  197. row.value = 1
  198. } else {
  199. row.value = 0
  200. }
  201. section.addFormRow(row)
  202. // Section: Rename File Name
  203. section = XLFormSectionDescriptor.formSection()
  204. form.addFormSection(section)
  205. row = XLFormRowDescriptor(tag: "maskFileName", rowType: XLFormRowDescriptorTypeAccount, title: NSLocalizedString("_filename_", comment: ""))
  206. let fileNameMask : String = CCUtility.getFileNameMask(k_keyFileNameMask)
  207. if fileNameMask.characters.count > 0 {
  208. row.value = fileNameMask
  209. }
  210. section.addFormRow(row)
  211. // Section: Preview File Name
  212. //section = XLFormSectionDescriptor.formSection()
  213. //form.addFormSection(section)
  214. row = XLFormRowDescriptor(tag: "previewFileName", rowType: XLFormRowDescriptorTypeTextView, title: "")
  215. row.height = 180
  216. row.cellConfig.setObject(NCBrandColor.sharedInstance.tableBackground, forKey: "backgroundColor" as NSCopying)
  217. row.cellConfig.setObject(NCBrandColor.sharedInstance.tableBackground, forKey: "textView.backgroundColor" as NSCopying)
  218. row.disabled = true
  219. section.addFormRow(row)
  220. self.form = form
  221. }
  222. override func formRowDescriptorValueHasChanged(_ formRow: XLFormRowDescriptor!, oldValue: Any!, newValue: Any!) {
  223. super.formRowDescriptorValueHasChanged(formRow, oldValue: oldValue, newValue: newValue)
  224. if formRow.tag == "useFolderPhoto" {
  225. if (formRow.value! as AnyObject).boolValue == true {
  226. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  227. buttonDestinationFolder.hidden = true
  228. } else{
  229. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  230. buttonDestinationFolder.hidden = false
  231. }
  232. }
  233. else if formRow.tag == "useSubFolder" {
  234. if (formRow.value! as AnyObject).boolValue == true {
  235. } else{
  236. }
  237. }
  238. else if formRow.tag == "maskFileName" {
  239. let fileName : String? = formRow.value as? String
  240. self.form.delegate = nil
  241. if fileName != nil {
  242. formRow.value = CCUtility.removeForbiddenCharactersServer(fileName)
  243. }
  244. self.form.delegate = self
  245. let previewFileName : XLFormRowDescriptor = self.form.formRow(withTag: "previewFileName")!
  246. previewFileName.value = self.previewFileName(valueRename: formRow.value as? String)
  247. // reload cell
  248. if fileName != nil {
  249. if newValue as! String != formRow.value as! String {
  250. self.reloadFormRow(formRow)
  251. appDelegate.messageNotification("_info_", description: "_forbidden_characters_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.info, errorCode: 0)
  252. }
  253. }
  254. self.reloadFormRow(previewFileName)
  255. }
  256. }
  257. // MARK: - View Life Cycle
  258. override func viewDidLoad() {
  259. super.viewDidLoad()
  260. let cancelButton : UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_cancel_", comment: ""), style: UIBarButtonItemStyle.plain, target: self, action: #selector(cancel))
  261. let saveButton : UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_save_", comment: ""), style: UIBarButtonItemStyle.plain, target: self, action: #selector(save))
  262. self.navigationItem.leftBarButtonItem = cancelButton
  263. self.navigationItem.rightBarButtonItem = saveButton
  264. self.navigationController?.navigationBar.isTranslucent = false
  265. self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.brand
  266. self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.navigationBarText
  267. self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: NCBrandColor.sharedInstance.navigationBarText]
  268. self.tableView.separatorStyle = UITableViewCellSeparatorStyle.none
  269. self.tableView.backgroundColor = NCBrandColor.sharedInstance.tableBackground
  270. self.reloadForm()
  271. }
  272. func reloadForm() {
  273. self.form.delegate = nil
  274. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  275. buttonDestinationFolder.title = self.titleServerUrl
  276. let maskFileName : XLFormRowDescriptor = self.form.formRow(withTag: "maskFileName")!
  277. let previewFileName : XLFormRowDescriptor = self.form.formRow(withTag: "previewFileName")!
  278. previewFileName.value = self.previewFileName(valueRename: maskFileName.value as? String)
  279. self.tableView.reloadData()
  280. self.form.delegate = self
  281. }
  282. //MARK: TableView
  283. override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
  284. switch section {
  285. case 0:
  286. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  287. if buttonDestinationFolder.isHidden() {
  288. return ""
  289. } else {
  290. return " " + NSLocalizedString("_destination_folder_", comment: "")
  291. }
  292. case 1:
  293. return " " + NSLocalizedString("_use_folder_photos_", comment: "")
  294. case 2:
  295. return " " + NSLocalizedString("_rename_filename_", comment: "")
  296. case 3:
  297. return NSLocalizedString("_preview_filename_", comment: "")
  298. default:
  299. return ""
  300. }
  301. }
  302. override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
  303. switch section {
  304. /*
  305. case 2:
  306. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "maskFileName")!
  307. let text = self.writePreviewFileName(buttonDestinationFolder)
  308. return text
  309. */
  310. default:
  311. return ""
  312. }
  313. }
  314. // MARK: - Action
  315. func moveServerUrl(to serverUrlTo: String!, title: String!) {
  316. self.serverUrl = serverUrlTo
  317. if title == nil {
  318. self.titleServerUrl = "/"
  319. } else {
  320. self.titleServerUrl = title
  321. }
  322. self.reloadForm()
  323. }
  324. func save() {
  325. self.dismiss(animated: true, completion: {
  326. let useFolderPhotoRow : XLFormRowDescriptor = self.form.formRow(withTag: "useFolderPhoto")!
  327. let useSubFolderRow : XLFormRowDescriptor = self.form.formRow(withTag: "useSubFolder")!
  328. var useSubFolder : Bool = false
  329. if (useFolderPhotoRow.value! as AnyObject).boolValue == true {
  330. self.serverUrl = NCManageDatabase.sharedInstance.getAccountAutoUploadPath(self.appDelegate.activeUrl)
  331. useSubFolder = (useSubFolderRow.value! as AnyObject).boolValue
  332. }
  333. self.appDelegate.activeMain.uploadFileAsset(self.assets, serverUrl: self.serverUrl, cryptated: self.cryptated, useSubFolder: useSubFolder, session: self.session)
  334. })
  335. }
  336. func cancel() {
  337. self.dismiss(animated: true, completion: nil)
  338. }
  339. // MARK: - Utility
  340. func previewFileName(valueRename : String?) -> String {
  341. var returnString : String = ""
  342. if valueRename != nil {
  343. let valueRenameTrimming = valueRename!.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
  344. if valueRenameTrimming.characters.count > 0 {
  345. self.form.delegate = nil
  346. CCUtility.setFileNameMask(valueRenameTrimming, key: k_keyFileNameMask)
  347. self.form.delegate = self
  348. returnString = CCUtility.createFileName(from: assets[0] as! PHAsset, key: k_keyFileNameMask)
  349. } else {
  350. CCUtility.setFileNameMask("", key: k_keyFileNameMask)
  351. returnString = CCUtility.createFileName(from: assets[0] as! PHAsset, key: nil)
  352. }
  353. } else {
  354. CCUtility.setFileNameMask("", key: k_keyFileNameMask)
  355. returnString = CCUtility.createFileName(from: assets[0] as! PHAsset, key: nil)
  356. }
  357. return NSLocalizedString("_preview_filename_", comment: "") + ":" + "\n\n" + returnString
  358. }
  359. func changeDestinationFolder(_ sender: XLFormRowDescriptor) {
  360. self.deselectFormRow(sender)
  361. let storyboard : UIStoryboard = UIStoryboard(name: "CCMove", bundle: nil)
  362. let navigationController = storyboard.instantiateViewController(withIdentifier: "CCMove") as! UINavigationController
  363. let viewController : CCMove = navigationController.topViewController as! CCMove
  364. viewController.delegate = self;
  365. viewController.tintColor = NCBrandColor.sharedInstance.navigationBarText
  366. viewController.barTintColor = NCBrandColor.sharedInstance.brand
  367. viewController.tintColorTitle = NCBrandColor.sharedInstance.navigationBarText
  368. viewController.move.title = NSLocalizedString("_select_", comment: "");
  369. viewController.networkingOperationQueue = appDelegate.netQueue
  370. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  371. self.present(navigationController, animated: true, completion: nil)
  372. }
  373. }