Browse Source

clear code

marinofaggiana 5 years ago
parent
commit
fe355dff9b

+ 0 - 3
iOSClient/AppDelegate.h

@@ -147,9 +147,6 @@
 // Setting Active Account
 - (void)settingActiveAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl activeUser:(NSString *)activeUser activeUserID:(NSString *)activeUserID activePassword:(NSString *)activePassword;
 
-// Updated Shares
-- (void)updateShares:(NSArray *)items;
-
 // Quick Actions - ShotcutItem
 - (void)configDynamicShortcutItems;
 - (BOOL)handleShortCutItem:(UIApplicationShortcutItem *)shortcutItem;

+ 0 - 21
iOSClient/AppDelegate.m

@@ -623,27 +623,6 @@ PKPushRegistry *pushRegistry;
     return [token copy];
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Update Share =====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)updateShares:(NSArray *)items
-{
-    [self.sharesID removeAllObjects];
-    
-    for (OCSharedDto *item in items)
-        [self.sharesID setObject:item forKey:[@(item.idRemoteShared) stringValue]];
-    
-    NSArray *result = [[NCManageDatabase sharedInstance] updateShare:self.sharesID activeUrl:self.activeUrl account:self.activeAccount];
-    if (result) {
-        self.sharesLink = result[0];
-        self.sharesUserAndGroup = result[1];
-    }
-    
-    [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"ShareReloadDatasource" object:nil userInfo:nil];
-    [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"SharesReloadDatasource" object:nil userInfo:nil];
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Quick Actions - ShotcutItem =====
 #pragma --------------------------------------------------------------------------------------------

+ 2 - 1
iOSClient/Main/CCMain.h

@@ -47,7 +47,7 @@
 
 @class tableMetadata;
 
-@interface CCMain : UIViewController <UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, UIViewControllerPreviewingDelegate, BKPasscodeViewControllerDelegate, UISplitViewControllerDelegate, UIPopoverControllerDelegate, UIDocumentMenuDelegate, UIDocumentPickerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, UIScrollViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
+@interface CCMain : UIViewController <UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, UIViewControllerPreviewingDelegate, BKPasscodeViewControllerDelegate, UISplitViewControllerDelegate, UIPopoverControllerDelegate, CCShareOCDelegate, UIDocumentMenuDelegate, UIDocumentPickerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, UIScrollViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
 
 @property (nonatomic, weak) IBOutlet UITableView *tableView;
 @property (nonatomic, strong) tableMetadata *metadata;
@@ -82,6 +82,7 @@
 - (void)reloadDatasource:(NSString *)serverUrl fileID:(NSString *)fileID action:(NSInteger)action;
 
 - (void)openShareWithMetadata:(tableMetadata *)metadata;
+- (void)readShareServer;
 
 - (void)clearDateReadDataSource:(NSNotification *)notification;
 - (void)cancelSearchBar;

+ 7 - 0
iOSClient/Main/CCMain.m

@@ -1881,6 +1881,8 @@
         // Apriamo la view
         _shareOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareOC"];
         
+        _shareOC.delegate = self;
+        
         _shareOC.metadata = metadata;
         _shareOC.serverUrl = metadata.serverUrl;
         
@@ -1892,6 +1894,11 @@
     }
 }
 
+- (void)readShareServer
+{
+    
+}
+
 - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
 {
     CGPoint location = [tapGesture locationInView:self.tableView];

+ 1 - 5
iOSClient/Networking/NCService.swift

@@ -270,11 +270,7 @@ class NCService: NSObject {
                 // Get Share Server
                 if (capabilities!.isFilesSharingAPIEnabled && self.appDelegate.activeMain != nil) {
                     
-                    OCNetworking.sharedManager()?.readShare(withAccount: account, completion: { (account, items, message, errorCode) in
-                        if errorCode == 0 && account == self.appDelegate.activeAccount {
-                            self.appDelegate.updateShares(items)
-                        }
-                    })
+                    self.appDelegate.activeMain.readShareServer()
                 }
                 
                 // Get Activity

+ 10 - 0
iOSClient/Share/CCShareOC.h

@@ -29,8 +29,12 @@
 
 @class tableMetadata;
 
+@protocol CCShareOCDelegate;
+
 @interface CCShareOC : XLFormViewController
 
+@property (nonatomic, weak) id <CCShareOCDelegate> delegate;
+
 @property (nonatomic, weak) IBOutlet UIImageView *fileImageView;
 @property (nonatomic, weak) IBOutlet UILabel *labelTitle;
 @property (nonatomic, weak) IBOutlet UILabel *labelSharedWithYouBy;
@@ -51,3 +55,9 @@
 - (IBAction)endButtonAction:(id)sender;
 
 @end
+
+@protocol CCShareOCDelegate
+
+- (void)readShareServer;
+
+@end

+ 12 - 16
iOSClient/Share/CCShareOC.m

@@ -42,7 +42,7 @@
         appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
         self.itemsShareWith = [[NSMutableArray alloc] init];
 
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData) name:@"ShareReloadDatasource" object:nil];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadDatasource) name:@"ShareReloadDatasource" object:nil];
 
         [self initializeForm];
     }
@@ -135,7 +135,7 @@
     [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
     self.endButton.tintColor = [UIColor blackColor];
     
-    [self reloadData];
+    [self reloadDatasource];
     
     if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:self.metadata.fileID fileNameView:self.metadata.fileNameView]]) {
         
@@ -173,14 +173,12 @@
         
         if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
             
-            [self reloadData];
-            
         } else if (errorCode != 0) {
             
             [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         }
         
-        [self reloadData];
+        [self reloadDatasource];
     }];
 }
 
@@ -198,14 +196,12 @@
                 appDelegate.sharesUserAndGroup = result[1];
             }
             
-            [self reloadData];
-            
         } else if (errorCode != 0) {
             
             [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         }
         
-        [self reloadData];
+        [self reloadDatasource];
     }];
 }
 
@@ -215,14 +211,12 @@
         
         if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
             
-            [self reloadData];
-            
         } else if (errorCode != 0) {
             
             [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         }
         
-        [self reloadData];
+        [self reloadDatasource];
     }];
 }
 
@@ -230,12 +224,13 @@
 #pragma mark ===== Reload Data =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)reloadData
+- (void)reloadDatasource
 {    
     // bugfix
     if (!self.serverUrl || !self.metadata) {
         
         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+            [self.delegate readShareServer];
             [self dismissViewControllerAnimated:YES completion:nil];
         });
         
@@ -494,7 +489,7 @@
                     [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
                 }];
                 UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
-                    [self reloadData];
+                    [self reloadDatasource];
                 }];
                 UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                     NSString *password = alertController.textFields.firstObject.text;
@@ -611,14 +606,14 @@
             
             [appDelegate messageNotification:@"_share_link_" description:@"_password_obligatory_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
 
-            [self reloadData];
+            [self reloadDatasource];
             
         } else {
         
             // if the password is not changed or is 0 lenght
             if ([[self.itemShareLink shareWith] isEqualToString:password]) {
                 
-                [self reloadData];
+                [self reloadDatasource];
                 
             } else {
                 
@@ -643,9 +638,10 @@
 {
     [self.tableView endEditing:YES];
     
-    // reload delegate
     [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.metadata.serverUrl fileID:self.metadata.fileID action:k_action_MOD];
     
+    [self.delegate readShareServer];
+    
     [self dismissViewControllerAnimated:YES completion:nil];
 }