Browse Source

clear code

marinofaggiana 5 years ago
parent
commit
ab7f67818e

+ 3 - 0
iOSClient/AppDelegate.h

@@ -147,6 +147,9 @@
 // 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;

+ 21 - 0
iOSClient/AppDelegate.m

@@ -623,6 +623,27 @@ 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];
+    }
+    
+    // Notify Shares View
+    [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"SharesReloadDatasource" object:nil userInfo:nil];
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Quick Actions - ShotcutItem =====
 #pragma --------------------------------------------------------------------------------------------

+ 2 - 2
iOSClient/Favorites/CCFavorites.m

@@ -257,7 +257,7 @@
     
     tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
     if (metadata)
-        [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:metadata];
+        [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount metadata:metadata];
 }
 
 #pragma --------------------------------------------------------------------------------------------
@@ -476,7 +476,7 @@
     // Share
     [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil) image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"share"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement] backgroundColor:[NCBrandColor sharedInstance].backgroundView height: 50.0 type:AHKActionSheetButtonTypeDefault handler:^(AHKActionSheet *as) {
         
-        [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:metadata];
+        [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount metadata:metadata];
     }];
     
     // NO Directory

+ 2 - 2
iOSClient/Main/CCDetail.m

@@ -591,7 +591,7 @@
 - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
 {
     tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
-    [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:metadata];
+    [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount metadata:metadata];
 }
 
 - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
@@ -988,7 +988,7 @@
 
 - (void)shareButtonPressed:(UIBarButtonItem *)sender
 {
-    [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:self.metadataDetail];
+    [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount metadata:self.metadataDetail];
 }
 
 - (void)deleteButtonPressed:(UIBarButtonItem *)sender

+ 1 - 1
iOSClient/Main/CCMain.h

@@ -81,7 +81,7 @@
 
 - (void)reloadDatasource:(NSString *)serverUrl fileID:(NSString *)fileID action:(NSInteger)action;
 
-- (void)readShareWithAccount:(NSString *)account openWindow:(BOOL)openWindow metadata:(tableMetadata *)metadata;
+- (void)readShareWithAccount:(NSString *)account metadata:(tableMetadata *)metadata;
 
 - (void)clearDateReadDataSource:(NSNotification *)notification;
 - (void)cancelSearchBar;

+ 26 - 31
iOSClient/Main/CCMain.m

@@ -1870,7 +1870,7 @@
 #pragma mark ===== Shared =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)readShareWithAccount:(NSString *)account openWindow:(BOOL)openWindow metadata:(tableMetadata *)metadata
+- (void)readShareWithAccount:(NSString *)account metadata:(tableMetadata *)metadata
 {
     [[OCNetworking sharedManager] readShareWithAccount:account path:@"/" completion:^(NSString *account, NSArray *items, NSString *message, NSInteger errorCode) {
         
@@ -1892,27 +1892,24 @@
             // Notify Shares View
             [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"SharesReloadDatasource" object:nil userInfo:nil];
             
-            if (openWindow) {
-                
-                if (_shareOC) {
-                    
-                    [_shareOC reloadData];
-                    
-                } else if (metadata) {
-                    
-                    // Apriamo la view
-                    _shareOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareOC"];
+            if (_shareOC) {
                     
-                    _shareOC.delegate = self;
-                    _shareOC.metadata = metadata;
-                    _shareOC.serverUrl = metadata.serverUrl;
-                    
-                    _shareOC.shareLink = [appDelegate.sharesLink objectForKey:metadata.fileID];
-                    _shareOC.shareUserAndGroup = [appDelegate.sharesUserAndGroup objectForKey:metadata.fileID];
-                    
-                    [_shareOC setModalPresentationStyle:UIModalPresentationFormSheet];
-                    [self presentViewController:_shareOC animated:YES completion:nil];
-                }
+                [_shareOC reloadData];
+                
+            } else if (metadata) {
+                
+                // Apriamo la view
+                _shareOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareOC"];
+                
+                _shareOC.delegate = self;
+                _shareOC.metadata = metadata;
+                _shareOC.serverUrl = metadata.serverUrl;
+                
+                _shareOC.shareLink = [appDelegate.sharesLink objectForKey:metadata.fileID];
+                _shareOC.shareUserAndGroup = [appDelegate.sharesUserAndGroup objectForKey:metadata.fileID];
+                
+                [_shareOC setModalPresentationStyle:UIModalPresentationFormSheet];
+                [self presentViewController:_shareOC animated:YES completion:nil];
             }
             
             [self tableViewReloadData];
@@ -1923,9 +1920,7 @@
         }
     }];
     
-    if (openWindow) {
-        [_hud visibleIndeterminateHud];
-    }
+    [_hud visibleIndeterminateHud];
 }
 
 - (void)share:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password permission:(NSInteger)permission hideDownload:(BOOL)hideDownload
@@ -1938,7 +1933,7 @@
         
         if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
             
-            [self readShareWithAccount:account openWindow:YES metadata:metadata];
+            [self readShareWithAccount:account metadata:metadata];
             
         } else if (errorCode != 0) {
             
@@ -1970,7 +1965,7 @@
                 appDelegate.sharesUserAndGroup = result[1];
             }
             
-            [self readShareWithAccount:account openWindow:YES metadata:metadata];
+            [self readShareWithAccount:account metadata:metadata];
             
         } else if (errorCode != 0) {
             
@@ -1994,7 +1989,7 @@
         
         if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
             
-            [self readShareWithAccount:account openWindow:YES metadata:metadata];
+            [self readShareWithAccount:account metadata:metadata];
             
         } else if (errorCode != 0) {
             
@@ -2042,7 +2037,7 @@
         
         if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
             
-            [self readShareWithAccount:account openWindow:YES metadata:metadata];
+            [self readShareWithAccount:account metadata:metadata];
             
         } else if (errorCode != 0) {
             
@@ -2066,7 +2061,7 @@
     tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
     
     if (metadata)
-        [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:metadata];
+        [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount metadata:metadata];
 }
 
 - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
@@ -3204,7 +3199,7 @@
                                      height:50.0
                                        type:AHKActionSheetButtonTypeDefault
                                     handler:^(AHKActionSheet *as) {
-                                        [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:self.metadata];
+                                        [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount metadata:self.metadata];
                                     }];
         }
         
@@ -3393,7 +3388,7 @@
                                         height: 50.0
                                         type:AHKActionSheetButtonTypeDefault
                                         handler:^(AHKActionSheet *as) {
-                                            [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:self.metadata];
+                                            [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount metadata:self.metadata];
                                         }];
         }
         

+ 6 - 2
iOSClient/Networking/NCService.swift

@@ -267,10 +267,14 @@ class NCService: NSObject {
                     NCManageDatabase.sharedInstance.deleteExternalSites(account: account!)
                 }
                 
-                // Get Share
+                // Get Share Server
                 if (capabilities!.isFilesSharingAPIEnabled && self.appDelegate.activeMain != nil) {
                     
-                    self.appDelegate.activeMain.readShare(withAccount: account, openWindow: false, metadata: nil)
+                    OCNetworking.sharedManager()?.readShare(withAccount: account, completion: { (account, items, message, errorCode) in
+                        if errorCode == 0 && account == self.appDelegate.activeAccount {
+                            self.appDelegate.updateShares(items)
+                        }
+                    })
                 }
                 
                 // Get Activity

+ 1 - 1
iOSClient/Offline/NCOffline.swift

@@ -338,7 +338,7 @@ class NCOffline: UIViewController, UIGestureRecognizerDelegate, NCListCellDelega
                     }
                     self.loadDatasource()
                 }
-                if item.value as? Int == 1 { self.appDelegate.activeMain.readShare(withAccount: self.appDelegate.activeAccount, openWindow: true, metadata: metadata) }
+                if item.value as? Int == 1 { self.appDelegate.activeMain.readShare(withAccount: self.appDelegate.activeAccount, metadata: metadata) }
                 if item.value as? Int == 2 { self.deleteItem(with: metadata, sender: sender) }
                 if item is ActionSheetCancelButton { print("Cancel buttons has the value `true`") }
             }

+ 1 - 1
iOSClient/PeekPop/CCPeekPop.m

@@ -78,7 +78,7 @@
     
     if (self.showShare) {
         UIPreviewAction *share = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_share_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action,  UIViewController *previewViewController){
-            [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:self.metadata];
+            [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount metadata:self.metadata];
         }];
         [items addObject:share];
     }

+ 1 - 1
iOSClient/Shares/NCShares.m

@@ -357,7 +357,7 @@
         
         metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileName == %@", appDelegate.activeAccount, table.serverUrl, table.fileName]];
         if (metadata) {
-            [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:metadata];
+            [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount metadata:metadata];
         }
     }
 }

+ 3 - 2
iOSClient/Viewer/NCViewerRichdocument.swift

@@ -109,7 +109,7 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
             }
             
             if message.body as! String == "share" {
-                appDelegate.activeMain.readShare(withAccount: appDelegate.activeAccount, openWindow: true, metadata: self.detail.metadataDetail)
+                appDelegate.activeMain.readShare(withAccount: appDelegate.activeAccount, metadata: self.detail.metadataDetail)
             }
         }
     }
@@ -118,12 +118,13 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
 
     @objc func grabFocus() {
     
+        /*
         let functionJS = "OCA.RichDocuments.documentsMain.postGrabFocus()"
         evaluateJavaScript(functionJS) { (result, error) in
             let text = result as? String
             print(text)
         }
-
+        */
     }
     
     //MARK: -