Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

Commit b7198b9

Browse files
albertChien-twdabechen
authored andcommitted
add multi-selection move and delete function
1 parent 2fb60a4 commit b7198b9

File tree

4 files changed

+159
-12
lines changed

4 files changed

+159
-12
lines changed

Owncloud iOs Client/AppDelegate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ extern NSString * NotReachableNetworkForDownloadsNotification;
149149
@property (nonatomic, strong) NSString *urlServerRedirected;
150150
@property (nonatomic, strong) ManageDownloads *downloadManager;
151151
@property (nonatomic, strong) NSString *userSessionCurrentToken;
152-
152+
@property (nonatomic ,strong) NSMutableArray *multipleSelectedFileDto;
153+
@property (nonatomic,strong) NSString *currentFolder;
153154
@property (nonatomic, strong) OCOAuth2Configuration *oauth2Configuration;
154155

155156
/*

Owncloud iOs Client/DataBase/DTOs/FileDto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef enum {
5050
@property (nonatomic) NSInteger providingFileId;
5151
@property (nonatomic, copy) NSString *ocId;
5252
@property (nonatomic, copy) NSString *ocPrivatelink;
53-
53+
@property BOOL isSelected;
5454
///-----------------------------------
5555
/// @name Init with OCFileDto
5656
///-----------------------------------

Owncloud iOs Client/Files/Preview/DetailView/DetailViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,7 @@ - (void) endLoading {
19951995
self.view.userInteractionEnabled = YES;
19961996
self.navigationController.navigationBar.userInteractionEnabled = YES;
19971997
self.tabBarController.tabBar.userInteractionEnabled = YES;
1998+
[[NSNotificationCenter defaultCenter]postNotificationName:@"endDelete" object:self];
19981999
}
19992000

20002001
#pragma mark - UIAlertView delegate methods

Owncloud iOs Client/Tabs/FileTab/FilesViewController.m

Lines changed: 155 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,21 @@
7070
#define k_navigation_bar_height 44
7171
#define k_navigation_bar_height_in_iphone_landscape 32
7272

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+
7383
@interface FilesViewController ()
7484

7585
@property (nonatomic, strong) ELCAlbumPickerController *albumController;
7686
@property (nonatomic, strong) ELCImagePickerController *elcPicker;
87+
@property (nonatomic, assign) SELECTTYPE selectType;
7788
@property (nonatomic) BOOL didLayoutSubviews;
7889
@property (nonatomic) BOOL willLayoutSubviews;
7990

@@ -98,7 +109,7 @@ - (void)dealloc
98109
*/
99110
- (id) initWithNibName:(NSString *) nibNameOrNil onFolder:(NSString *) currentFolder andFileId:(NSInteger) fileIdToShowFiles andCurrentLocalFolder:(NSString *)currentLocalFoler
100111
{
101-
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
112+
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
102113
//If is 0 is root folder
103114
if(fileIdToShowFiles == 0) {
104115
_fileIdToShowFiles = [ManageFilesDB getRootFileDtoByUser:app.activeUser];
@@ -170,7 +181,8 @@ - (void)viewDidLoad
170181

171182
//Add a more button
172183
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;
174186

175187
// Create a searchBar and a displayController "Future Option"
176188
//UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
@@ -284,7 +296,7 @@ - (void)viewWillAppear:(BOOL)animated
284296
[self initLoading];
285297

286298
}
287-
299+
288300
}
289301

290302
- (void)initFilesView {
@@ -767,7 +779,7 @@ - (void) setNotificationForCommunicationBetweenViews {
767779
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endLoading) name:EndLoadingFileListNotification object:nil];
768780
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initLoading) name:InitLoadingFileListNotification object:nil];
769781
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTableFromDataBase) name:ReloadFileListFromDataBaseNotification object:nil];
770-
782+
771783
//Add an observer for know when the Checked Share of server is done
772784
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshSharedPath) name:RefreshSharesItemsAfterCheckServerVersion object:nil];
773785

@@ -1242,6 +1254,19 @@ - (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker {
12421254
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
12431255
{
12441256

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+
12451270
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
12461271

12471272
// If the selected cell is showing the SwipeMenu, we don´t navigate further
@@ -1278,7 +1303,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
12781303

12791304
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
12801305
{
1281-
return NO;
1306+
return YES;
12821307
}
12831308

12841309
#pragma mark - UITableView datasource
@@ -1346,6 +1371,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
13461371

13471372
FileDto *file = (FileDto *)[[_sortedArray objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
13481373

1374+
if (tableView.isEditing){
1375+
1376+
fileCell.editingAccessoryType = file.isSelected ? UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
1377+
1378+
}
1379+
13491380
NSDate* date = [NSDate dateWithTimeIntervalSince1970:file.date];
13501381
NSString *fileDateString;
13511382
if (file.date > 0) {
@@ -1443,6 +1474,35 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
14431474
return cell;
14441475
}
14451476

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+
}
14461506
// Asks the data source to return the number of sections in the table view.
14471507
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
14481508
{
@@ -2317,7 +2377,24 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn
23172377
}
23182378
}
23192379

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
23212398
if (actionSheet.tag==200) {
23222399
if(_selectedFileDto.isDirectory) {
23232400
switch (buttonIndex) {
@@ -2648,10 +2725,10 @@ - (void) removeSelectedIndexPath {
26482725
* over the selected file
26492726
*/
26502727
- (void)didSelectRenameOption {
2651-
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
2728+
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
26522729

26532730
//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];
26552732

26562733
if ([_selectedFileDto isDownload] == downloading) {
26572734
//if the file is downloading alert the user
@@ -2682,6 +2759,73 @@ - (void)didSelectRenameOption {
26822759
/*
26832760
* Method called when the user select the move option
26842761
*/
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+
}
26852829
- (void)didSelectMoveOption {
26862830
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
26872831

@@ -2922,7 +3066,7 @@ - (void) didSelectCancelDownloadFileOption {
29223066
* this method close de backgroundtask
29233067
*/
29243068
- (void)endMoveBackGroundTask {
2925-
3069+
[[NSNotificationCenter defaultCenter]postNotificationName:@"endMove" object:self];
29263070
if (_moveTask) {
29273071
[[UIApplication sharedApplication] endBackgroundTask:_moveTask];
29283072
}
@@ -3029,7 +3173,8 @@ - (void)didSelectShareLinkOption {
30293173
* @folder -> folder selected.
30303174
*/
30313175
- (void)folderSelected:(NSString*)folder {
3032-
3176+
AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
3177+
app.currentFolder = folder;
30333178
DLog(@"Folder: %@", folder);
30343179

30353180
// [self pauseDonwloadsQueue];

0 commit comments

Comments
 (0)