Browse Source

Manage auto upload filename

Marino Faggiana 7 years ago
parent
commit
83e960974b

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -220,6 +220,7 @@
 		F750374F1DBFA91A008FB480 /* NSArray+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = F75037461DBFA91A008FB480 /* NSArray+PureLayout.m */; };
 		F75037511DBFA91A008FB480 /* NSLayoutConstraint+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = F75037481DBFA91A008FB480 /* NSLayoutConstraint+PureLayout.m */; };
 		F75797AE1E81356C00187A1B /* CTAssetsPicker.strings in Resources */ = {isa = PBXBuildFile; fileRef = F75797AC1E81356C00187A1B /* CTAssetsPicker.strings */; };
+		F75AC2431F1F62450073EC19 /* NCManageAutoUploadFileName.swift in Sources */ = {isa = PBXBuildFile; fileRef = F75AC2421F1F62450073EC19 /* NCManageAutoUploadFileName.swift */; };
 		F75ADF451DC75FFE008A7347 /* CCLogin.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F75ADF441DC75FFE008A7347 /* CCLogin.storyboard */; };
 		F75AE3C71E9D12900088BB09 /* SwiftyAvatar.swift in Sources */ = {isa = PBXBuildFile; fileRef = F75AE3C61E9D12900088BB09 /* SwiftyAvatar.swift */; };
 		F75EDFAC1E8C106900E6F369 /* FirebaseAnalytics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F75EDFA61E8C106900E6F369 /* FirebaseAnalytics.framework */; };
@@ -1116,6 +1117,7 @@
 		F7540F2B1D5B238600C3FFA8 /* x509_vfy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = x509_vfy.h; sourceTree = "<group>"; };
 		F7540F2C1D5B238600C3FFA8 /* x509v3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = x509v3.h; sourceTree = "<group>"; };
 		F75797AD1E81356C00187A1B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/CTAssetsPicker.strings; sourceTree = "<group>"; };
+		F75AC2421F1F62450073EC19 /* NCManageAutoUploadFileName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCManageAutoUploadFileName.swift; sourceTree = "<group>"; };
 		F75ADF441DC75FFE008A7347 /* CCLogin.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = CCLogin.storyboard; sourceTree = "<group>"; };
 		F75AE3C61E9D12900088BB09 /* SwiftyAvatar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyAvatar.swift; sourceTree = "<group>"; };
 		F75B91DF1ECAE17800199C96 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/CTAssetsPicker.strings; sourceTree = "<group>"; };
@@ -2903,6 +2905,7 @@
 				F7ACE42A1BAC0268006C0017 /* Acknowledgements.m */,
 				F7ACE42B1BAC0268006C0017 /* Acknowledgements.rtf */,
 				F7A321AB1E9E6AD50069AD1B /* CCAdvanced.h */,
+				F75AC2421F1F62450073EC19 /* NCManageAutoUploadFileName.swift */,
 				F7A321AC1E9E6AD50069AD1B /* CCAdvanced.m */,
 				F7ACE42C1BAC0268006C0017 /* CCManageAccount.h */,
 				F7ACE42D1BAC0268006C0017 /* CCManageAccount.m */,
@@ -4620,6 +4623,7 @@
 				F762CB091EACB66200B38484 /* XLFormViewController.m in Sources */,
 				F762CB161EACB66200B38484 /* XLFormTextView.m in Sources */,
 				F7D424681F063B82009C9782 /* CTAssetsGridViewFooter.m in Sources */,
+				F75AC2431F1F62450073EC19 /* NCManageAutoUploadFileName.swift in Sources */,
 				F7D424701F063B82009C9782 /* CTAssetsPickerNoAssetsView.m in Sources */,
 				F7D424591F063B82009C9782 /* PHImageManager+CTAssetsPickerController.m in Sources */,
 				F7ECBA6D1E239DCD003E6328 /* CCCreateCloud.swift in Sources */,

+ 2 - 0
iOSClient/Settings/CCManageAutoUpload.m

@@ -155,6 +155,8 @@
     [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
     [section addFormRow:row];
 
+    // Auto Upload file name
+    
     // end
     
     section = [XLFormSectionDescriptor formSection];

+ 204 - 0
iOSClient/Settings/NCManageAutoUploadFileName.swift

@@ -0,0 +1,204 @@
+//
+//  NCManageAutoUploadFileName.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 19/07/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+import Foundation
+
+class NCManageAutoUploadFileName: XLFormViewController {
+    
+    let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    
+    convenience init() {
+        
+        self.init()
+        self.initializeForm()
+    }
+    
+    //MARK: XLFormDescriptorDelegate
+    
+    func initializeForm() {
+        
+        let form : XLFormDescriptor = XLFormDescriptor() 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_keyFileNameType)
+        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_keyFileNameMask)
+        if fileNameMask.characters.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.tableBackground, forKey: "backgroundColor" as NSCopying)
+        row.cellConfig.setObject(NCBrandColor.sharedInstance.tableBackground, 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_keyFileNameType)
+            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.navigationBarText
+        self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: NCBrandColor.sharedInstance.navigationBarText]
+        
+        self.tableView.separatorStyle = UITableViewCellSeparatorStyle.none
+        
+        self.tableView.backgroundColor = NCBrandColor.sharedInstance.tableBackground
+        
+        self.reloadForm()
+    }
+    
+    override func viewWillDisappear(_ animated: Bool)
+    {
+        super.viewWillDisappear(animated)
+    }
+    
+    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 NSLocalizedString("_preview_filename_", comment: "")
+        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.characters.count > 0 {
+                
+                self.form.delegate = nil
+                CCUtility.setFileNameMask(valueRenameTrimming, key: k_keyFileNameMask)
+                self.form.delegate = self
+                
+                //returnString = CCUtility.createFileName(from: assets[0] as! PHAsset, keyFileName: k_keyFileNameMask, keyFileNameType: k_keyFileNameType)
+                
+            } else {
+                
+                CCUtility.setFileNameMask("", key: k_keyFileNameMask)
+                //returnString = CCUtility.createFileName(from: assets[0] as! PHAsset, keyFileName: nil, keyFileNameType: k_keyFileNameType)
+            }
+            
+        } else {
+            
+            CCUtility.setFileNameMask("", key: k_keyFileNameMask)
+            //returnString = CCUtility.createFileName(from: assets[0] as! PHAsset, keyFileName: nil, keyFileNameType: k_keyFileNameType)
+        }
+        
+        return NSLocalizedString("_preview_filename_", comment: "") + ":" + "\n\n" + returnString
+    }
+}