浏览代码

Add new Swipe to Favorite view

Marino Faggiana 7 年之前
父节点
当前提交
d4446f5bcb

+ 2 - 1
iOSClient/Favorites/CCFavorites.h

@@ -27,6 +27,7 @@
 #import "UIScrollView+EmptyDataSet.h"
 #import "TWMessageBarManager.h"
 #import "AHKActionSheet.h"
+#import "MGSwipeTableCell.h"
 #import "CCFavoritesCell.h"
 #import "CCUtility.h"
 #import "CCMain.h"
@@ -42,7 +43,7 @@
 
 @class tableMetadata;
 
-@interface CCFavorites : UIViewController <UITableViewDataSource, UITableViewDelegate, UIDocumentInteractionControllerDelegate, UIActionSheetDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate, CCAccountWebDelegate, CCBancomatDelegate, CCCartaDiCreditoDelegate, CCCartaIdentitaDelegate, CCContoCorrenteDelegate, CCNoteDelegate, CCPassaportoDelegate, CCPatenteGuidaDelegate>
+@interface CCFavorites : UIViewController <UITableViewDataSource, UITableViewDelegate, UIDocumentInteractionControllerDelegate, UIActionSheetDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate, CCAccountWebDelegate, CCBancomatDelegate, CCCartaDiCreditoDelegate, CCCartaIdentitaDelegate, CCContoCorrenteDelegate, CCNoteDelegate, CCPassaportoDelegate, CCPatenteGuidaDelegate, MGSwipeTableCellDelegate>
 
 @property (nonatomic, weak) IBOutlet UITableView *tableView;
 

+ 42 - 35
iOSClient/Favorites/CCFavorites.m

@@ -471,16 +471,6 @@
     [actionSheet addButtonWithTitle: metadata.fileNamePrint image: iconHeader backgroundColor: [NCBrandColor sharedInstance].tabBar height: 50.0 type: AHKActionSheetButtonTypeDisabled handler: nil
     ];
 
-    // ONLY Root Favorites : Remove file/folder Favorites
-    if (_serverUrl == nil) {
-        
-        [actionSheet addButtonWithTitle:NSLocalizedString(@"_remove_favorites_", nil) image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetOffline"] color:[NCBrandColor sharedInstance].brand] backgroundColor:[UIColor whiteColor] height: 50.0 type:AHKActionSheetButtonTypeDefault handler:^(AHKActionSheet *as) {
-                                    
-            [self.tableView setEditing:NO animated:YES];
-            [[CCActions sharedInstance] settingFavorite:metadata favorite:NO delegate:self];
-        }];
-    }
-    
     // Share
     if (_metadata.cryptated == NO) {
         
@@ -509,43 +499,44 @@
 #pragma mark ===== Swipe Tablet -> menu =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
-{
-    return UITableViewCellEditingStyleDelete;
-}
-
-- (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
-    return NSLocalizedString(@"_more_", nil);
-}
-
-- (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath
-{
-    [self requestMoreMetadata:[_dataSource objectAtIndex:indexPath.row] indexPath:indexPath];
-}
-
-- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
+- (BOOL)swipeTableCell:(MGSwipeTableCell *)cell canSwipe:(MGSwipeDirection)direction
 {
-    return NSLocalizedString(@"_delete_", nil);
+    return YES;
 }
 
-- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
+- (BOOL)swipeTableCell:(MGSwipeTableCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion
 {
-    if (editingStyle == UITableViewCellEditingStyleDelete) {
-                
-        [self requestDeleteMetadata:[_dataSource objectAtIndex:indexPath.row] indexPath:indexPath];
+    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
+    
+    if (direction == MGSwipeDirectionRightToLeft) {
+        
+        // Delete
+        if (index == 0)
+            [self requestDeleteMetadata:[_dataSource objectAtIndex:indexPath.row] indexPath:indexPath];
+        
+        // More
+        if (index == 1)
+            [self requestMoreMetadata:[_dataSource objectAtIndex:indexPath.row] indexPath:indexPath];
+    }
+    
+    if (direction == MGSwipeDirectionLeftToRight) {
+        
+        tableMetadata *metadata = [_dataSource objectAtIndex:indexPath.row];
+        [[CCActions sharedInstance] settingFavorite:metadata favorite:NO delegate:self];
     }
+    
+    return YES;
 }
 
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ==== Table ====
 #pragma --------------------------------------------------------------------------------------------
 
 - (tableMetadata *)setSelfMetadataFromIndexPath:(NSIndexPath *)indexPath
 {
-    NSManagedObject *record = [_dataSource objectAtIndex:indexPath.row];
+    tableMetadata *metadata = [_dataSource objectAtIndex:indexPath.row];
     
-    tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", [record valueForKey:@"fileID"]]];
-
     return metadata;
 }
 
@@ -601,6 +592,10 @@
     CCFavoritesCell *cell = (CCFavoritesCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
     tableMetadata *metadata;
     
+    // variable base
+    cell.delegate = self;
+    cell.indexPath = indexPath;
+    
     // separator
     cell.separatorInset = UIEdgeInsetsMake(0.f, 60.f, 0.f, 0.f);
     
@@ -677,14 +672,26 @@
                 cell.local.image = nil;
             
             cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ %@", date, length];
-            //cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ • %@", date, length];
-            //cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ ◦ %@", date, length];
         }
         
         cell.accessoryType = UITableViewCellAccessoryNone;
         
     }
     
+    // ======== MGSwipe ========
+    
+    //configure left buttons : ONLY Root Favorites : Remove file/folder Favorites
+    
+    if (_serverUrl == nil) {
+        cell.leftButtons = @[[MGSwipeButton buttonWithTitle:[NSString stringWithFormat:@" %@ ", NSLocalizedString(@"_unfavorite_", nil)] icon:[UIImage imageNamed:@"swipeUnfavorite"] backgroundColor:[UIColor colorWithRed:242.0/255.0 green:220.0/255.0 blue:132.0/255.0 alpha:1.000]]];
+        cell.leftExpansion.buttonIndex = 0;
+        cell.leftExpansion.fillOnTrigger = NO;
+    }
+    
+    //configure right buttons
+    cell.rightButtons = @[[MGSwipeButton buttonWithTitle:[NSString stringWithFormat:@" %@ ", NSLocalizedString(@"_delete_", nil)] icon:[UIImage imageNamed:@"swipeDelete"] backgroundColor:[UIColor redColor]], [MGSwipeButton buttonWithTitle:[NSString stringWithFormat:@" %@ ", NSLocalizedString(@"_more_", nil)] icon:[UIImage imageNamed:@"swipeMore"] backgroundColor:[UIColor lightGrayColor]]];
+    cell.rightSwipeSettings.transition = MGSwipeTransitionBorder;
+    
     return cell;
 }
 

+ 2 - 1
iOSClient/Favorites/CCFavoritesCell.h

@@ -22,8 +22,9 @@
 //
 
 #import <UIKit/UIKit.h>
+#import "MGSwipeTableCell.h"
 
-@interface CCFavoritesCell : UITableViewCell
+@interface CCFavoritesCell : MGSwipeTableCell
 
 @property(nonatomic, weak) IBOutlet UIImageView *file;
 @property(nonatomic, weak) IBOutlet UIImageView *status;

+ 1 - 1
iOSClient/Main/CCMain.m

@@ -5469,7 +5469,7 @@
     [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
     [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
 
-    // MGSwipe
+    // ======== MGSwipe ========
 
     //configure left buttons
     if (metadata.favorite)

+ 0 - 2
iOSClient/Networking/CCNetworking.m

@@ -25,7 +25,6 @@
 
 #import "AppDelegate.h"
 #import "CCCertificate.h"
-#import "TableAccount+CoreDataClass.h"
 #import "NSDate+ISO8601.h"
 #import "NSString+Encode.h"
 #import "NCRequestAsset.h"
@@ -33,7 +32,6 @@
 
 @interface CCNetworking () <NCRequestAssetDelegate>
 {
-    NSManagedObjectContext *_context;
     NSMutableDictionary *_taskData;
     
     NSString *_activeAccount;

+ 0 - 8
iOSClient/Shares/NCShares.m

@@ -261,14 +261,6 @@
 #pragma mark ==== Table ====
 #pragma --------------------------------------------------------------------------------------------
 
-- (tableMetadata *)setSelfMetadataFromIndexPath:(NSIndexPath *)indexPath
-{
-    NSManagedObject *record = [_dataSource objectAtIndex:indexPath.row];
-    tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", [record valueForKey:@"fileID"]]];
-
-    return metadata;
-}
-
 - (void)readFolder:(NSString *)serverUrl
 {
     [self reloadDatasource];