浏览代码

Add new separate Class in swift for Actions

Marino Faggiana 8 年之前
父节点
当前提交
6e3ea0d303

+ 12 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -80,6 +80,7 @@
 		F7145A241D12E3B700CAFEEC /* CCCellShareExt.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7296A621C8880C9001A7809 /* CCCellShareExt.xib */; };
 		F71E68001DC1F792003BA52B /* libownCloudiOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F71E67FC1DC1F76F003BA52B /* libownCloudiOS.a */; };
 		F71E68021DC1F79D003BA52B /* libownCloudiOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F71E67FC1DC1F76F003BA52B /* libownCloudiOS.a */; };
+		F720E01F1E48C73E001A4B9E /* CCActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F720E01E1E48C73E001A4B9E /* CCActions.swift */; };
 		F7253FCA1E38BAF20084135B /* JSAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = F7253FC91E38BAF20084135B /* JSAlertView.m */; };
 		F725437C1E12A44A009BF4C2 /* CCSection.m in Sources */ = {isa = PBXBuildFile; fileRef = F78F6FAF1CC8CCB700F4EA25 /* CCSection.m */; };
 		F72C63891DC14B0400FA5ED5 /* libMagicalRecord.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F7B61E9B1DC13C20009E938F /* libMagicalRecord.a */; };
@@ -1077,6 +1078,7 @@
 		F71E67F61DC1F76F003BA52B /* ownCloud iOS library.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "ownCloud iOS library.xcodeproj"; path = "Libraries external/OCCommunicationLib/ownCloud iOS library.xcodeproj"; sourceTree = SOURCE_ROOT; };
 		F71EDBFC1C4B93ED00265D0C /* JBroken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JBroken.h; sourceTree = "<group>"; };
 		F71EDBFD1C4B93ED00265D0C /* JBroken.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JBroken.m; sourceTree = "<group>"; };
+		F720E01E1E48C73E001A4B9E /* CCActions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CCActions.swift; path = Actions/CCActions.swift; sourceTree = "<group>"; };
 		F721371D1BAFF0920012B613 /* CCAccountWeb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCAccountWeb.h; sourceTree = "<group>"; };
 		F721371E1BAFF0920012B613 /* CCAccountWeb.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCAccountWeb.m; sourceTree = "<group>"; };
 		F72137211BAFF0920012B613 /* CCBancomat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCBancomat.h; sourceTree = "<group>"; };
@@ -2338,6 +2340,14 @@
 			name = Products;
 			sourceTree = "<group>";
 		};
+		F720E02A1E48C74C001A4B9E /* Actions */ = {
+			isa = PBXGroup;
+			children = (
+				F720E01E1E48C73E001A4B9E /* CCActions.swift */,
+			);
+			name = Actions;
+			sourceTree = "<group>";
+		};
 		F721371B1BAFF0920012B613 /* Templates */ = {
 			isa = PBXGroup;
 			children = (
@@ -3187,6 +3197,7 @@
 				F7F67BB81A24D27800EE80DA /* Images.xcassets */,
 				F7596C771D128FC80092A6B8 /* Nextcloud.xcassets */,
 				F70211F31BAC56E9003FC03E /* Main */,
+				F720E02A1E48C74C001A4B9E /* Actions */,
 				F7ECBA6B1E239DCD003E6328 /* Create */,
 				F7E95CEC1AC40BA40060D08E /* FileSystem */,
 				F744BE911BEBB2EE004FFF66 /* Intro */,
@@ -3967,6 +3978,7 @@
 				F77B0E201D118A16002130FE /* CCShareUserOC.m in Sources */,
 				F77B0E211D118A16002130FE /* ThumbsMainToolbar.m in Sources */,
 				F73CCDF31DC13776007E38D8 /* XLFormSwitchCell.m in Sources */,
+				F720E01F1E48C73E001A4B9E /* CCActions.swift in Sources */,
 				F77B0E221D118A16002130FE /* CCManageLocation.m in Sources */,
 				F77B0E231D118A16002130FE /* CCSharePermissionOC.m in Sources */,
 				F77B0E241D118A16002130FE /* HRColorCursor.m in Sources */,

+ 111 - 0
iOSClient/Actions/CCActions.swift

@@ -0,0 +1,111 @@
+//
+//  CCActions.swift
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 06/02/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
+
+@objc protocol CCActionsDelegate  {
+    
+    func deleteFileOrFolderSuccess(_ metadataNet : CCMetadataNet)
+    func deleteFileOrFolderFailure(_ metadataNet : CCMetadataNet, message : NSString, errorCode : NSInteger)
+}
+
+class CCActions: NSObject {
+    
+    //MARK: Shared Instance
+    
+    /*
+    static let sharedInstance : CCActions = {
+        let instance = CCActions()
+        return instance
+    }()
+    */
+    
+    //MARK: Local Variable
+    
+    let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    var metadataNet : CCMetadataNet = CCMetadataNet.init()
+    
+    var delegate : CCActionsDelegate?
+    
+    //MARK: Init
+    
+    override init() {
+    }
+    
+    // BARK: Delete
+    func deleteFileOrFolder(_ metadata : CCMetadata, serverUrl : String, delegate : AnyObject) {
+        
+        let metadataNet : CCMetadataNet = CCMetadataNet.init()
+        
+        if metadata.cryptated == true {
+            
+            metadataNet.action = actionDeleteFileDirectory
+            metadataNet.delegate = delegate
+            metadataNet.fileID = metadata.fileID
+            metadataNet.fileNamePrint = metadata.fileNamePrint
+            metadataNet.metadata = metadata
+            metadataNet.serverUrl = serverUrl
+            
+            // data crypto
+            metadataNet.fileName = metadata.fileNameData
+            metadataNet.selector = selectorDeleteCrypto
+            
+            appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
+            
+            // plist
+            metadataNet.fileName = metadata.fileName;
+            metadataNet.selector = selectorDeletePlist
+
+            appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
+            
+        } else {
+            
+            metadataNet.action = actionDeleteFileDirectory
+            metadataNet.delegate = self
+            metadataNet.fileID = metadata.fileID
+            metadataNet.fileName = metadata.fileName
+            metadataNet.fileNamePrint = metadata.fileNamePrint
+            metadataNet.metadata = metadata
+            metadataNet.selector = selectorDelete
+            metadataNet.serverUrl = serverUrl
+
+            appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
+        }
+    }
+    
+    func deleteFileOrFolderSuccess(_ metadataNet : CCMetadataNet) {
+                
+        CCCoreData.deleteFile(metadataNet.metadata, serverUrl: metadataNet.serverUrl, directoryUser: appDelegate.directoryUser, typeCloud: appDelegate.typeCloud, activeAccount: appDelegate.activeAccount)
+        
+        delegate?.deleteFileOrFolderSuccess(metadataNet)
+    }
+    
+    func deleteFileOrFolderFailure(_ metadataNet : CCMetadataNet, message : NSString, errorCode : NSInteger) {
+        
+        if errorCode == 404 {
+            CCCoreData.deleteFile(metadataNet.metadata, serverUrl: metadataNet.serverUrl, directoryUser: appDelegate.directoryUser, typeCloud: appDelegate.typeCloud, activeAccount: appDelegate.activeAccount)
+        }
+
+        delegate?.deleteFileOrFolderFailure(metadataNet, message: message, errorCode: errorCode)
+    }
+}

+ 17 - 59
iOSClient/Main/CCMain.m

@@ -40,7 +40,7 @@
 #define alertRename 3
 #define alertOfflineFolder 4
 
-@interface CCMain ()
+@interface CCMain () <CCActionsDelegate>
 {
     CCMetadata *_metadataSegue;
     CCMetadata *_metadata;
@@ -79,6 +79,9 @@
     // Datasource
     CCSectionDataSource *_sectionDataSource;
     NSDate *_dateReadDataSource;
+    
+    // Actions
+    CCActions *_actions;
 }
 @end
 
@@ -118,6 +121,7 @@
     [super viewDidLoad];
     
     // init object
+    _actions = [CCActions new];
     _metadata = [[CCMetadata alloc] init];
     _metadataSegue = [[CCMetadata alloc] init];
     _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
@@ -131,6 +135,7 @@
     self.tableView.delegate = self;
     self.tableView.tableFooterView = [UIView new];
     self.tableView.separatorColor = COLOR_SEPARATOR_TABLE;
+    _actions.delegate = self;
 
     [[CCNetworking sharedNetworking] settingDelegate:self];
     
@@ -1878,9 +1883,10 @@
 {
     [_hud hideHud];
     
-    if (errorCode == 404)
+    if (errorCode == 404) {
         [self deleteFileOrFolderSuccess:metadataNet];
-    
+    }
+        
     if (message)
         [app messageNotification:@"_delete_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
 
@@ -1904,25 +1910,18 @@
         
         [_hud hideHud];
         
-        CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadataNet.fileID, app.activeAccount] context:nil];
-        
-        if (metadata) {
-            
-            [CCCoreData deleteFile:metadata serverUrl:metadataNet.serverUrl directoryUser:app.directoryUser typeCloud:app.typeCloud activeAccount:app.activeAccount];
-            
-            // Carico la Folder o il Datasource
-            if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced]) {
-                [self readFolderWithForced:YES];
-            } else {
-                [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:metadataNet.selector];
-            }
+        // Carico la Folder o il Datasource
+        if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced]) {
+            [self readFolderWithForced:YES];
+        } else {
+            [self getDataSourceWithReloadTableView:metadataNet.metadata.directoryID fileID:metadataNet.metadata.fileID selector:metadataNet.selector];
         }
 
         // if detailViewController
         if (_detailViewController) {
             
             dispatch_async(dispatch_get_main_queue(), ^{
-                [_detailViewController deleteFileSuccess:metadata metadataNetVar:metadataNet];
+                [_detailViewController deleteFileSuccess:metadataNet.metadata metadataNetVar:metadataNet];
             });
         }
 
@@ -1939,50 +1938,9 @@
 
 - (void)deleteFileOrFolder:(CCMetadata *)metadata numFile:(NSInteger)numFile ofFile:(NSInteger)ofFile
 {
-    if (metadata.cryptated == YES) {
-        
-        // Cryptated
-        
-        CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-        
-        metadataNet.action = actionDeleteFileDirectory;
-        metadataNet.delegate = self;
-        metadataNet.fileID = metadata.fileID;
-        metadataNet.fileNamePrint = metadata.fileNamePrint;
-        metadataNet.serverUrl = _localServerUrl;
-
-        // data crypto
-        metadataNet.fileName = metadata.fileNameData;
-        metadataNet.selector = selectorDeleteCrypto;
-            
-        [_queueSelector addObject:metadataNet.selector];
-        [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-        
-        // plist
-        metadataNet.fileName = metadata.fileName;
-        metadataNet.selector = selectorDeletePlist;
-            
-        [_queueSelector addObject:metadataNet.selector];
-        [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-            
-    } else {
-            
-        // Plain
+    [_queueSelector addObject:selectorDelete];
+    [_actions deleteFileOrFolder:metadata serverUrl:_localServerUrl delegate:self];
     
-        CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-        
-        metadataNet.action = actionDeleteFileDirectory;
-        metadataNet.delegate = self;
-        metadataNet.fileID = metadata.fileID;
-        metadataNet.fileName = metadata.fileName;
-        metadataNet.fileNamePrint = metadata.fileNamePrint;
-        metadataNet.selector = selectorDelete;
-        metadataNet.serverUrl = _localServerUrl;
-        
-        [_queueSelector addObject:metadataNet.selector];
-        [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-    }
-        
     [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_delete_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
 }
 

+ 18 - 3
iOSClient/Offline/CCOfflinePageContent.h

@@ -1,9 +1,24 @@
 //
 //  CCOfflinePageContent.h
-//  Nextcloud
+//  Crypto Cloud Technology Nextcloud
 //
-//  Created by Marino Faggiana on 01/02/17.
-//  Copyright © 2017 TWS. All rights reserved.
+//  Created by Marino Faggiana on 16/01/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 <UIKit/UIKit.h>

+ 18 - 3
iOSClient/Offline/CCOfflinePageContent.m

@@ -1,9 +1,24 @@
 //
 //  CCOfflinePageContent.m
-//  Nextcloud
+//  Crypto Cloud Technology Nextcloud
 //
-//  Created by Marino Faggiana on 01/02/17.
-//  Copyright © 2017 TWS. All rights reserved.
+//  Created by Marino Faggiana on 16/01/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 "CCOfflinePageContent.h"