123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- //
- // NCManageAutoUploadFileName.swift
- // Nextcloud iOS
- //
- // Created by Marino Faggiana on 19/07/17.
- // Copyright (c) 2017 TWS. All rights reserved.
- //
- // Author Marino Faggiana <m.faggiana@twsweb.it>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- import Foundation
- class NCManageAutoUploadFileName: XLFormViewController {
-
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- let dateExample = Date()
-
- required init(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- self.initializeForm()
- }
-
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
- self.initializeForm()
- }
-
- func initializeForm() {
-
- let form : XLFormDescriptor = XLFormDescriptor(title: NSLocalizedString("_autoupload_filename_title_", comment: "")) as XLFormDescriptor
- form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow
-
- var section : XLFormSectionDescriptor
- var row : XLFormRowDescriptor
- // Section: Add File Name Type
-
- section = XLFormSectionDescriptor.formSection()
- form.addFormSection(section)
-
- row = XLFormRowDescriptor(tag: "addFileNameType", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_filenametype_photo_video_", comment: ""))
- row.value = CCUtility.getFileNameType(k_keyFileNameAutoUploadType)
- section.addFormRow(row)
-
- // Section: Rename File Name
-
- section = XLFormSectionDescriptor.formSection()
- form.addFormSection(section)
-
- row = XLFormRowDescriptor(tag: "maskFileName", rowType: XLFormRowDescriptorTypeAccount, title: NSLocalizedString("_filename_", comment: ""))
-
- let fileNameMask : String = CCUtility.getFileNameMask(k_keyFileNameAutoUploadMask)
- if fileNameMask.count > 0 {
- row.value = fileNameMask
- }
- section.addFormRow(row)
-
- // Section: Preview File Name
-
- row = XLFormRowDescriptor(tag: "previewFileName", rowType: XLFormRowDescriptorTypeTextView, title: "")
- row.height = 180
- row.cellConfig.setObject(NCBrandColor.sharedInstance.backgroundView, forKey: "backgroundColor" as NSCopying)
- row.cellConfig.setObject(NCBrandColor.sharedInstance.backgroundView, forKey: "textView.backgroundColor" as NSCopying)
-
- row.disabled = true
- section.addFormRow(row)
-
- self.form = form
- }
-
- override func formRowDescriptorValueHasChanged(_ formRow: XLFormRowDescriptor!, oldValue: Any!, newValue: Any!) {
-
- super.formRowDescriptorValueHasChanged(formRow, oldValue: oldValue, newValue: newValue)
-
- if formRow.tag == "addFileNameType" {
- CCUtility.setFileNameType((formRow.value! as AnyObject).boolValue, key: k_keyFileNameAutoUploadType)
- self.reloadForm()
- }
- else if formRow.tag == "maskFileName" {
-
- let fileName = formRow.value as? String
-
- self.form.delegate = nil
-
- if let fileName = fileName {
- formRow.value = CCUtility.removeForbiddenCharactersServer(fileName)
- }
-
- self.form.delegate = self
-
- let previewFileName : XLFormRowDescriptor = self.form.formRow(withTag: "previewFileName")!
- previewFileName.value = self.previewFileName(valueRename: formRow.value as? String)
-
- // reload cell
- if fileName != nil {
-
- if newValue as! String != formRow.value as! String {
-
- self.reloadFormRow(formRow)
-
- appDelegate.messageNotification("_info_", description: "_forbidden_characters_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.info, errorCode: 0)
- }
- }
-
- self.reloadFormRow(previewFileName)
- }
- }
-
- // MARK: - View Life Cycle
-
- override func viewDidLoad() {
-
- super.viewDidLoad()
-
- self.navigationController?.navigationBar.isTranslucent = false
- self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.brand
- self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.brandText
- self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: NCBrandColor.sharedInstance.brandText]
-
- self.tableView.separatorStyle = UITableViewCellSeparatorStyle.none
-
- self.tableView.backgroundColor = NCBrandColor.sharedInstance.backgroundView
-
- self.reloadForm()
- }
-
- func reloadForm() {
-
- self.form.delegate = nil
-
- let maskFileName : XLFormRowDescriptor = self.form.formRow(withTag: "maskFileName")!
- let previewFileName : XLFormRowDescriptor = self.form.formRow(withTag: "previewFileName")!
- previewFileName.value = self.previewFileName(valueRename: maskFileName.value as? String)
-
- self.tableView.reloadData()
- self.form.delegate = self
- }
-
- //MARK: TableView
-
- override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
-
- switch section {
-
- case 0:
- return " " + NSLocalizedString("_add_filenametype_", comment: "")
- case 1:
- return " " + NSLocalizedString("_rename_filename_", comment: "")
- case 2:
- return String(format: NSLocalizedString("_preview_filename_", comment: ""), "MM,MMM,DD,YY,YYYY and HH,hh,mm,ss,ampm")
- default:
- return ""
- }
- }
-
- override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
-
- switch section {
-
- /*
- case 2:
- let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "maskFileName")!
- let text = self.writePreviewFileName(buttonDestinationFolder)
- return text
- */
-
- default:
- return ""
- }
- }
-
- // MARK: - Utility
-
- func previewFileName(valueRename : String?) -> String {
-
- var returnString : String = ""
-
- if let valueRename = valueRename {
-
- let valueRenameTrimming = valueRename.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
-
- if valueRenameTrimming.count > 0 {
-
- self.form.delegate = nil
- CCUtility.setFileNameMask(valueRename, key: k_keyFileNameAutoUploadMask)
- self.form.delegate = self
-
- returnString = CCUtility.createFileName("IMG_0001.JPG", fileDate: dateExample, fileType: PHAssetMediaType.image, keyFileName: k_keyFileNameAutoUploadMask, keyFileNameType: k_keyFileNameAutoUploadType)
- } else {
-
- CCUtility.setFileNameMask("", key: k_keyFileNameAutoUploadMask)
- returnString = CCUtility.createFileName("IMG_0001.JPG", fileDate: dateExample, fileType: PHAssetMediaType.image, keyFileName: nil, keyFileNameType: k_keyFileNameAutoUploadType)
- }
-
- } else {
-
- CCUtility.setFileNameMask("", key: k_keyFileNameAutoUploadMask)
- returnString = CCUtility.createFileName("IMG_0001.JPG", fileDate: dateExample, fileType: PHAssetMediaType.image, keyFileName: nil, keyFileNameType: k_keyFileNameAutoUploadType)
- }
-
- return String(format: NSLocalizedString("_preview_filename_", comment: ""), "MM,MMM,DD,YY,YYYY and HH,hh,mm,ss,ampm") + ":" + "\n\n" + returnString
- }
- }
|