70
70
#define k_navigation_bar_height 44
71
71
#define k_navigation_bar_height_in_iphone_landscape 32
72
72
73
+ // typedef NS_ENUM(NSInteger, SELECTTYPE){
74
+ // ENDMOVE = 0,
75
+ // ENDDELETE = 1
76
+ // };
77
+
78
+ typedef NS_ENUM (NSInteger , SELECTTYPE) {
79
+ ENDMOVE,
80
+ ENDDELETE
81
+ };
82
+
73
83
@interface FilesViewController ()
74
84
75
85
@property (nonatomic , strong ) ELCAlbumPickerController *albumController;
76
86
@property (nonatomic , strong ) ELCImagePickerController *elcPicker;
87
+ @property (nonatomic , assign ) SELECTTYPE selectType;
77
88
@property (nonatomic ) BOOL didLayoutSubviews;
78
89
@property (nonatomic ) BOOL willLayoutSubviews;
79
90
@@ -98,7 +109,7 @@ - (void)dealloc
98
109
*/
99
110
- (id ) initWithNibName : (NSString *) nibNameOrNil onFolder : (NSString *) currentFolder andFileId : (NSInteger ) fileIdToShowFiles andCurrentLocalFolder : (NSString *)currentLocalFoler
100
111
{
101
- AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication ]delegate];
112
+ AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication ]delegate];
102
113
// If is 0 is root folder
103
114
if (fileIdToShowFiles == 0 ) {
104
115
_fileIdToShowFiles = [ManageFilesDB getRootFileDtoByUser: app.activeUser];
@@ -170,7 +181,8 @@ - (void)viewDidLoad
170
181
171
182
// Add a more button
172
183
UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc ] initWithImage: [UIImage imageNamed: @" more-filled" ] style: UIBarButtonItemStylePlain target: self action: @selector (showOptions )];
173
- self.navigationItem .rightBarButtonItem = addButtonItem;
184
+ self.navigationItem .rightBarButtonItems = @[addButtonItem,self .editButtonItem];
185
+ // self.navigationItem.rightBarButtonItem = addButtonItem;
174
186
175
187
// Create a searchBar and a displayController "Future Option"
176
188
// UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
@@ -284,7 +296,7 @@ - (void)viewWillAppear:(BOOL)animated
284
296
[self initLoading ];
285
297
286
298
}
287
-
299
+
288
300
}
289
301
290
302
- (void )initFilesView {
@@ -767,7 +779,7 @@ - (void) setNotificationForCommunicationBetweenViews {
767
779
[[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (endLoading ) name: EndLoadingFileListNotification object: nil ];
768
780
[[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (initLoading ) name: InitLoadingFileListNotification object: nil ];
769
781
[[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (reloadTableFromDataBase ) name: ReloadFileListFromDataBaseNotification object: nil ];
770
-
782
+
771
783
// Add an observer for know when the Checked Share of server is done
772
784
[[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (refreshSharedPath ) name: RefreshSharesItemsAfterCheckServerVersion object: nil ];
773
785
@@ -1242,6 +1254,19 @@ - (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker {
1242
1254
- (void )tableView : (UITableView *)tableView didSelectRowAtIndexPath : (NSIndexPath *)indexPath
1243
1255
{
1244
1256
1257
+ if (tableView.isEditing ){
1258
+ FileDto *file = (FileDto *)[[self .sortedArray objectAtIndex: indexPath.section]objectAtIndex:indexPath.row];
1259
+
1260
+ file.isSelected = !file.isSelected ;
1261
+
1262
+ CustomCellFileAndDirectory *fileCell = (CustomCellFileAndDirectory *)[tableView cellForRowAtIndexPath: indexPath];
1263
+
1264
+ fileCell.editingAccessoryType = file.isSelected ? UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
1265
+
1266
+ return ;
1267
+
1268
+ }
1269
+
1245
1270
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication ]delegate];
1246
1271
1247
1272
// If the selected cell is showing the SwipeMenu, we don´t navigate further
@@ -1278,7 +1303,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
1278
1303
1279
1304
- (BOOL )tableView : (UITableView *)tableView canEditRowAtIndexPath : (NSIndexPath *)indexPath
1280
1305
{
1281
- return NO ;
1306
+ return YES ;
1282
1307
}
1283
1308
1284
1309
#pragma mark - UITableView datasource
@@ -1346,6 +1371,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
1346
1371
1347
1372
FileDto *file = (FileDto *)[[_sortedArray objectAtIndex: indexPath.section]objectAtIndex:indexPath.row];
1348
1373
1374
+ if (tableView.isEditing ){
1375
+
1376
+ fileCell.editingAccessoryType = file.isSelected ? UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
1377
+
1378
+ }
1379
+
1349
1380
NSDate * date = [NSDate dateWithTimeIntervalSince1970: file.date];
1350
1381
NSString *fileDateString;
1351
1382
if (file.date > 0 ) {
@@ -1443,6 +1474,35 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
1443
1474
return cell;
1444
1475
}
1445
1476
1477
+ - (void )setEditing : (BOOL )editing animated : (BOOL )animated {
1478
+ [super setEditing: editing animated: animated];
1479
+
1480
+ if (!editing)
1481
+ {
1482
+ if (self.plusActionSheet ) {
1483
+ self.plusActionSheet = nil ;
1484
+ }
1485
+
1486
+ self.plusActionSheet = [[UIActionSheet alloc ]initWithTitle:nil delegate: self cancelButtonTitle: NSLocalizedString(@" cancel" , nil ) destructiveButtonTitle: NSLocalizedString(@" delete_label" , nil ) otherButtonTitles: NSLocalizedString(@" move_long_press" , nil ),nil ];
1487
+
1488
+ self.plusActionSheet .actionSheetStyle =UIActionSheetStyleDefault;
1489
+ self.plusActionSheet .tag =150 ;
1490
+ if (IS_IPHONE) {
1491
+ [self .plusActionSheet showInView: self .tabBarController.view];
1492
+ } else {
1493
+
1494
+ AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication ]delegate];
1495
+
1496
+ [self .plusActionSheet showInView: app.splitViewController.view];
1497
+ }
1498
+ }else {
1499
+ [self .tableView setEditing: editing animated: animated];
1500
+ }
1501
+ }
1502
+
1503
+ - (UITableViewCellEditingStyle)tableView : (UITableView *)tableView editingStyleForRowAtIndexPath : (NSIndexPath *)indexPath {
1504
+ return UITableViewCellEditingStyleNone;
1505
+ }
1446
1506
// Asks the data source to return the number of sections in the table view.
1447
1507
- (NSInteger )numberOfSectionsInTableView : (UITableView *)tableView
1448
1508
{
@@ -2317,7 +2377,24 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn
2317
2377
}
2318
2378
}
2319
2379
2320
- // Long press menu
2380
+ if (actionSheet.tag ==150 ){
2381
+
2382
+ switch (buttonIndex) {
2383
+ case 0 :
2384
+ self.selectType = ENDDELETE;
2385
+ [self didSelectionMultipeMoveOption ];
2386
+ break ;
2387
+ case 1 :
2388
+ self.selectType = ENDMOVE;
2389
+ [self didSelectionMultipeMoveOption ];
2390
+ break ;
2391
+ default :
2392
+ [self .tableView setEditing: NO animated: YES ];
2393
+ break ;
2394
+ }
2395
+ }
2396
+
2397
+ // Long press menu
2321
2398
if (actionSheet.tag ==200 ) {
2322
2399
if (_selectedFileDto.isDirectory ) {
2323
2400
switch (buttonIndex) {
@@ -2648,10 +2725,10 @@ - (void) removeSelectedIndexPath {
2648
2725
* over the selected file
2649
2726
*/
2650
2727
- (void )didSelectRenameOption {
2651
- AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication ] delegate ];
2728
+ AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication ] delegate ];
2652
2729
2653
2730
// Update fileDto
2654
- self.selectedFileDto = [ManageFilesDB getFileDtoByFileName: self .selectedFileDto.fileName andFilePath: [UtilsUrls getFilePathOnDBByFilePathOnFileDto: self .selectedFileDto.filePath andUser: app.activeUser] andUser: app.activeUser];
2731
+ self.selectedFileDto = [ManageFilesDB getFileDtoByFileName: self .selectedFileDto.fileName andFilePath: [UtilsUrls getFilePathOnDBByFilePathOnFileDto: self .selectedFileDto.filePath andUser: app.activeUser] andUser: app.activeUser];
2655
2732
2656
2733
if ([_selectedFileDto isDownload ] == downloading) {
2657
2734
// if the file is downloading alert the user
@@ -2682,6 +2759,73 @@ - (void)didSelectRenameOption {
2682
2759
/*
2683
2760
* Method called when the user select the move option
2684
2761
*/
2762
+ -(void )didSelectionMultipeMoveOption {
2763
+
2764
+ AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication ] delegate ];
2765
+ NSInteger sections = _tableView.numberOfSections ;
2766
+ app.multipleSelectedFileDto = [[NSMutableArray alloc ]init];
2767
+ [app.multipleSelectedFileDto removeAllObjects ];
2768
+
2769
+ for (int section = 0 ; section < sections; section++) {
2770
+ NSInteger rows = [_tableView numberOfRowsInSection: section];
2771
+ for (int row = 0 ; row < rows; row++) {
2772
+ NSIndexPath *indexPath = [NSIndexPath indexPathForRow: row inSection: section];
2773
+
2774
+ FileDto *selectedFile = (FileDto *)[[self .sortedArray objectAtIndex: indexPath.section]objectAtIndex:indexPath.row];
2775
+
2776
+ if (selectedFile.isSelected ){
2777
+ selectedFile = [ManageFilesDB getFileDtoByFileName: selectedFile.fileName andFilePath: [UtilsUrls getFilePathOnDBByFilePathOnFileDto: selectedFile.filePath andUser: app.activeUser] andUser: app.activeUser];
2778
+ [app.multipleSelectedFileDto addObject: selectedFile];
2779
+ }
2780
+ }
2781
+
2782
+ }
2783
+
2784
+ FileDto *firstFile = app.multipleSelectedFileDto .firstObject ;
2785
+
2786
+ _selectedFileDto = firstFile;
2787
+
2788
+ if ([_selectedFileDto.fileName isEqualToString: app.detailViewController.file.fileName] &&
2789
+ [_selectedFileDto.filePath isEqualToString: app.detailViewController.file.filePath] &&
2790
+ _selectedFileDto.userId == app.detailViewController .file .userId ) {
2791
+ app.detailViewController .file = _selectedFileDto;
2792
+ }
2793
+ NSString * observerForName = @" " ;
2794
+
2795
+ switch (self.selectType ) {
2796
+ case ENDMOVE:
2797
+ [self didSelectMoveOption ];
2798
+ observerForName = @" endMove" ;
2799
+ break ;
2800
+ case ENDDELETE:
2801
+ [self didSelectDeleteOption ];
2802
+ observerForName = @" endDelete" ;
2803
+ break ;
2804
+ }
2805
+
2806
+ NSOperationQueue *mainQueue = [[NSOperationQueue alloc ]init];
2807
+
2808
+ __block NSInteger i = 0 ;
2809
+
2810
+ [[NSNotificationCenter defaultCenter ]addObserverForName:observerForName object: nil queue: mainQueue usingBlock: ^(NSNotification *note) {
2811
+ if (i < app.multipleSelectedFileDto .count - 1 ){
2812
+ i ++;
2813
+ FileDto *file = [app.multipleSelectedFileDto objectAtIndex: i];
2814
+ self.selectedFileDto = file;
2815
+ [self folderSelected: app.currentFolder];
2816
+ // last
2817
+ if (i == app.multipleSelectedFileDto .count - 1 ){
2818
+ dispatch_async (dispatch_get_main_queue (), ^{
2819
+ [self .tableView setEditing: NO animated: YES ];
2820
+ });
2821
+
2822
+ }
2823
+ }
2824
+
2825
+ }];
2826
+
2827
+
2828
+ }
2685
2829
- (void )didSelectMoveOption {
2686
2830
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication ] delegate ];
2687
2831
@@ -2922,7 +3066,7 @@ - (void) didSelectCancelDownloadFileOption {
2922
3066
* this method close de backgroundtask
2923
3067
*/
2924
3068
- (void )endMoveBackGroundTask {
2925
-
3069
+ [[ NSNotificationCenter defaultCenter ]postNotificationName: @" endMove " object: self ];
2926
3070
if (_moveTask) {
2927
3071
[[UIApplication sharedApplication ] endBackgroundTask: _moveTask];
2928
3072
}
@@ -3029,7 +3173,8 @@ - (void)didSelectShareLinkOption {
3029
3173
* @folder -> folder selected.
3030
3174
*/
3031
3175
- (void )folderSelected : (NSString *)folder {
3032
-
3176
+ AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication ] delegate ];
3177
+ app.currentFolder = folder;
3033
3178
DLog (@" Folder: %@ " , folder);
3034
3179
3035
3180
// [self pauseDonwloadsQueue];
0 commit comments