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

Commit

Permalink
新增多選一棟刪除功能
Browse files Browse the repository at this point in the history
  • Loading branch information
albertChien-tw authored and dabechen committed Jun 20, 2018
1 parent 2fb60a4 commit 689a922
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Owncloud iOs Client/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ extern NSString * NotReachableNetworkForDownloadsNotification;
@property (nonatomic, strong) NSString *urlServerRedirected;
@property (nonatomic, strong) ManageDownloads *downloadManager;
@property (nonatomic, strong) NSString *userSessionCurrentToken;

@property (nonatomic ,strong) NSMutableArray *multipleSelectedFileDto;
@property (nonatomic,strong) NSString *currentFolder;
@property (nonatomic, strong) OCOAuth2Configuration *oauth2Configuration;

/*
Expand Down
2 changes: 1 addition & 1 deletion Owncloud iOs Client/DataBase/DTOs/FileDto.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ typedef enum {
@property (nonatomic) NSInteger providingFileId;
@property (nonatomic, copy) NSString *ocId;
@property (nonatomic, copy) NSString *ocPrivatelink;

@property BOOL isSelected;
///-----------------------------------
/// @name Init with OCFileDto
///-----------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,7 @@ - (void) endLoading {
self.view.userInteractionEnabled = YES;
self.navigationController.navigationBar.userInteractionEnabled = YES;
self.tabBarController.tabBar.userInteractionEnabled = YES;
[[NSNotificationCenter defaultCenter]postNotificationName:@"endDelete" object:self];
}

#pragma mark - UIAlertView delegate methods
Expand Down
165 changes: 155 additions & 10 deletions Owncloud iOs Client/Tabs/FileTab/FilesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,21 @@
#define k_navigation_bar_height 44
#define k_navigation_bar_height_in_iphone_landscape 32

//typedef NS_ENUM(NSInteger, SELECTTYPE){
// ENDMOVE = 0,
// ENDDELETE = 1
//};

typedef NS_ENUM(NSInteger, SELECTTYPE) {
ENDMOVE,
ENDDELETE
};

@interface FilesViewController ()

@property (nonatomic, strong) ELCAlbumPickerController *albumController;
@property (nonatomic, strong) ELCImagePickerController *elcPicker;
@property (nonatomic, assign) SELECTTYPE selectType;
@property (nonatomic) BOOL didLayoutSubviews;
@property (nonatomic) BOOL willLayoutSubviews;

Expand All @@ -98,7 +109,7 @@ - (void)dealloc
*/
- (id) initWithNibName:(NSString *) nibNameOrNil onFolder:(NSString *) currentFolder andFileId:(NSInteger) fileIdToShowFiles andCurrentLocalFolder:(NSString *)currentLocalFoler
{
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
//If is 0 is root folder
if(fileIdToShowFiles == 0) {
_fileIdToShowFiles = [ManageFilesDB getRootFileDtoByUser:app.activeUser];
Expand Down Expand Up @@ -170,7 +181,8 @@ - (void)viewDidLoad

//Add a more button
UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"more-filled"] style:UIBarButtonItemStylePlain target:self action:@selector(showOptions)];
self.navigationItem.rightBarButtonItem = addButtonItem;
self.navigationItem.rightBarButtonItems = @[addButtonItem,self.editButtonItem];
// self.navigationItem.rightBarButtonItem = addButtonItem;

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

}

}

- (void)initFilesView {
Expand Down Expand Up @@ -767,7 +779,7 @@ - (void) setNotificationForCommunicationBetweenViews {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endLoading) name:EndLoadingFileListNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initLoading) name:InitLoadingFileListNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTableFromDataBase) name:ReloadFileListFromDataBaseNotification object:nil];

//Add an observer for know when the Checked Share of server is done
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshSharedPath) name:RefreshSharesItemsAfterCheckServerVersion object:nil];

Expand Down Expand Up @@ -1242,6 +1254,19 @@ - (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker {
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

if (tableView.isEditing){
FileDto *file = (FileDto *)[[self.sortedArray objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];

file.isSelected = !file.isSelected;

CustomCellFileAndDirectory *fileCell = (CustomCellFileAndDirectory *)[tableView cellForRowAtIndexPath:indexPath];

fileCell.editingAccessoryType = file.isSelected ? UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;

return;

}

AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];

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

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
return YES;
}

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

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

if (tableView.isEditing){

fileCell.editingAccessoryType = file.isSelected ? UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;

}

NSDate* date = [NSDate dateWithTimeIntervalSince1970:file.date];
NSString *fileDateString;
if (file.date > 0) {
Expand Down Expand Up @@ -1443,6 +1474,35 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
[super setEditing:editing animated:animated];

if (!editing)
{
if (self.plusActionSheet) {
self.plusActionSheet = nil;
}

self.plusActionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"cancel", nil) destructiveButtonTitle:NSLocalizedString(@"delete_label", nil) otherButtonTitles:NSLocalizedString(@"move_long_press", nil),nil];

self.plusActionSheet.actionSheetStyle=UIActionSheetStyleDefault;
self.plusActionSheet.tag=150;
if (IS_IPHONE) {
[self.plusActionSheet showInView:self.tabBarController.view];
} else {

AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];

[self.plusActionSheet showInView:app.splitViewController.view];
}
}else{
[self.tableView setEditing:editing animated:animated];
}
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
// Asks the data source to return the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
Expand Down Expand Up @@ -2317,7 +2377,24 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn
}
}

//Long press menu
if (actionSheet.tag==150){

switch (buttonIndex) {
case 0:
self.selectType = ENDDELETE;
[self didSelectionMultipeMoveOption];
break;
case 1:
self.selectType = ENDMOVE;
[self didSelectionMultipeMoveOption];
break;
default:
[self.tableView setEditing:NO animated:YES];
break;
}
}

//Long press menu
if (actionSheet.tag==200) {
if(_selectedFileDto.isDirectory) {
switch (buttonIndex) {
Expand Down Expand Up @@ -2648,10 +2725,10 @@ - (void) removeSelectedIndexPath {
* over the selected file
*/
- (void)didSelectRenameOption {
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];

//Update fileDto
self.selectedFileDto = [ManageFilesDB getFileDtoByFileName:self.selectedFileDto.fileName andFilePath:[UtilsUrls getFilePathOnDBByFilePathOnFileDto:self.selectedFileDto.filePath andUser:app.activeUser] andUser:app.activeUser];
self.selectedFileDto = [ManageFilesDB getFileDtoByFileName:self.selectedFileDto.fileName andFilePath:[UtilsUrls getFilePathOnDBByFilePathOnFileDto:self.selectedFileDto.filePath andUser:app.activeUser] andUser:app.activeUser];

if ([_selectedFileDto isDownload] == downloading) {
//if the file is downloading alert the user
Expand Down Expand Up @@ -2682,6 +2759,73 @@ - (void)didSelectRenameOption {
/*
* Method called when the user select the move option
*/
-(void)didSelectionMultipeMoveOption{

AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSInteger sections = _tableView.numberOfSections;
app.multipleSelectedFileDto = [[NSMutableArray alloc]init];
[app.multipleSelectedFileDto removeAllObjects];

for (int section = 0; section < sections; section++) {
NSInteger rows = [_tableView numberOfRowsInSection:section];
for (int row = 0; row < rows; row++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];

FileDto *selectedFile = (FileDto *)[[self.sortedArray objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];

if (selectedFile.isSelected){
selectedFile = [ManageFilesDB getFileDtoByFileName:selectedFile.fileName andFilePath:[UtilsUrls getFilePathOnDBByFilePathOnFileDto:selectedFile.filePath andUser:app.activeUser] andUser:app.activeUser];
[app.multipleSelectedFileDto addObject:selectedFile];
}
}

}

FileDto *firstFile = app.multipleSelectedFileDto.firstObject;

_selectedFileDto = firstFile;

if ([_selectedFileDto.fileName isEqualToString:app.detailViewController.file.fileName] &&
[_selectedFileDto.filePath isEqualToString:app.detailViewController.file.filePath] &&
_selectedFileDto.userId == app.detailViewController.file.userId) {
app.detailViewController.file = _selectedFileDto;
}
NSString * observerForName = @"";

switch (self.selectType) {
case ENDMOVE:
[self didSelectMoveOption];
observerForName = @"endMove";
break;
case ENDDELETE:
[self didSelectDeleteOption];
observerForName = @"endDelete";
break;
}

NSOperationQueue *mainQueue = [[NSOperationQueue alloc]init];

__block NSInteger i = 0;

[[NSNotificationCenter defaultCenter]addObserverForName:observerForName object:nil queue:mainQueue usingBlock:^(NSNotification *note) {
if (i < app.multipleSelectedFileDto.count - 1){
i ++;
FileDto *file = [app.multipleSelectedFileDto objectAtIndex:i];
self.selectedFileDto = file;
[self folderSelected:app.currentFolder];
//last
if (i == app.multipleSelectedFileDto.count - 1){
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView setEditing:NO animated:YES];
});

}
}

}];


}
- (void)didSelectMoveOption {
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];

Expand Down Expand Up @@ -2922,7 +3066,7 @@ - (void) didSelectCancelDownloadFileOption {
* this method close de backgroundtask
*/
- (void)endMoveBackGroundTask {

[[NSNotificationCenter defaultCenter]postNotificationName:@"endMove" object:self];
if (_moveTask) {
[[UIApplication sharedApplication] endBackgroundTask:_moveTask];
}
Expand Down Expand Up @@ -3029,7 +3173,8 @@ - (void)didSelectShareLinkOption {
* @folder -> folder selected.
*/
- (void)folderSelected:(NSString*)folder {

AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
app.currentFolder = folder;
DLog(@"Folder: %@", folder);

// [self pauseDonwloadsQueue];
Expand Down

0 comments on commit 689a922

Please sign in to comment.