Browse Source

remake favorite

marinofaggiana 5 years ago
parent
commit
24b1d94e63

+ 0 - 1
iOSClient/Favorites/CCFavorites.h

@@ -47,6 +47,5 @@
 - (void)listingFavorites;
 
 - (void)actionDelete:(NSIndexPath *)indexPath;
-- (void)settingFavorite:(tableMetadata *)metadata favorite:(BOOL)favorite;
 
 @end

+ 15 - 23
iOSClient/Favorites/CCFavorites.m

@@ -68,6 +68,7 @@
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:k_notificationCenter_progressTask object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:k_notificationCenter_changeTheming object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteFile:) name:k_notificationCenter_deleteFile object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(favoriteFile:) name:k_notificationCenter_favoriteFile object:nil];
     
     // Metadata
     self.metadata = [tableMetadata new];
@@ -136,6 +137,19 @@
     }
 }
 
+- (void)favoriteFile:(NSNotification *)notification
+{
+    if (self.view.window == nil) { return; }
+    
+    NSDictionary *userInfo = notification.userInfo;
+    tableMetadata *metadata = userInfo[@"metadata"];
+    NSInteger errorCode = [userInfo[@"errorCode"] integerValue];
+    
+    if (errorCode == 0) {
+        [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl ocId:metadata.ocId action:k_action_MOD];
+    }
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ==== DZNEmptyDataSetSource ====
 #pragma --------------------------------------------------------------------------------------------
@@ -172,27 +186,6 @@
     return [[NSAttributedString alloc] initWithString:text attributes:attributes];
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Favorite =====
-#pragma--------------------------------------------------------------------------------------------
-
-- (void)settingFavorite:(tableMetadata *)metadata favorite:(BOOL)favorite
-{
-    NSString *fileNameServerUrl = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:metadata.serverUrl activeUrl:appDelegate.activeUrl];
-    
-    [[NCCommunication sharedInstance] setFavoriteWithServerUrl:appDelegate.activeUrl fileName:fileNameServerUrl favorite:favorite account:appDelegate.activeAccount completionHandler:^(NSString *account, NSInteger errorCode, NSString *errorDecription) {
-        
-        if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
-            [[NCManageDatabase sharedInstance] setMetadataFavoriteWithOcId:metadata.ocId favorite:favorite];
-            [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl ocId:metadata.ocId action:k_action_MOD];
-        } else if (errorCode != 0) {
-            [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDecription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
-        } else {
-            NSLog(@"[LOG] It has been changed user during networking process, error.");
-        }
-    }];
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== listingFavorites =====
 #pragma--------------------------------------------------------------------------------------------
@@ -398,8 +391,7 @@
     if (direction == MGSwipeDirectionLeftToRight) {
         
         tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
-        
-        [self settingFavorite:metadata favorite:NO];
+        [[NCNetworking sharedInstance] favoriteMetadata:metadata url:appDelegate.activeUrl completion:^(NSInteger errorCode, NSString *errorDescription) { }];
     }
     
     return YES;

+ 2 - 1
iOSClient/Main/Menu/CCFavorites+Menu.swift

@@ -29,6 +29,7 @@ extension CCFavorites {
 
     private func initMoreMenu(indexPath: IndexPath, metadata: tableMetadata) -> [NCMenuAction] {
         var actions = [NCMenuAction]()
+        let appDelegate = UIApplication.shared.delegate as! AppDelegate
 
         var iconHeader: UIImage!
         if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
@@ -55,7 +56,7 @@ extension CCFavorites {
                     title: NSLocalizedString("_remove_favorites_", comment: ""),
                     icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
                     action: { menuAction in
-                        self.settingFavorite(metadata, favorite: false)
+                        NCNetworking.sharedInstance.favoriteMetadata(metadata, url: appDelegate.activeUrl) { (errorCode, errorDescription) in }
                     }
                 )
             )

+ 1 - 1
iOSClient/Main/Menu/NCDetailNavigationController+Menu.swift

@@ -38,7 +38,7 @@ extension NCDetailNavigationController {
                 title: titleFavorite,
                 icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
                 action: { menuAction in
-                    
+                    NCNetworking.sharedInstance.favoriteMetadata(metadata, url: self.appDelegate.activeUrl) { (errorCode, errorDescription) in }
                 }
             )
         )