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

Commit

Permalink
Made changes for improve the code in order to have a more clear code
Browse files Browse the repository at this point in the history
  • Loading branch information
RebecaMartin committed Sep 4, 2013
1 parent 9de27dd commit 8ac2ea7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Owncloud iOs Client/DataBase/Queries/ManageFilesDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@
/*
* Method that give all files with a concrete download state and by active user
*/
+ (BOOL) getFilesByDownloadState:(enumDownload)downloadState andByUser:(UserDto *) currentUser andFolder:(NSString *) folder;
+ (BOOL) isGetFilesByDownloadState:(enumDownload)downloadState andByUser:(UserDto *) currentUser andFolder:(NSString *) folder;


/*
* Method that update the download state of all files in a folder by active user
*/
+ (void) updateFilesByUser:(UserDto *) currentUser andFolder:(NSString *) folder ToDownloadState:(enumDownload)downloadState;
+ (void) updateFilesByUser:(UserDto *) currentUser andFolder:(NSString *) folder toDownloadState:(enumDownload)downloadState;

@end
4 changes: 2 additions & 2 deletions Owncloud iOs Client/DataBase/Queries/ManageFilesDB.m
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ + (void) updateFilesWithFileId:(int) oldFileId withNewFileId:(int) fileId {
}


+ (BOOL) getFilesByDownloadState:(enumDownload)downloadState andByUser:(UserDto *) currentUser andFolder:(NSString *) folder {
+ (BOOL) isGetFilesByDownloadState:(enumDownload)downloadState andByUser:(UserDto *) currentUser andFolder:(NSString *) folder {

__block BOOL *output = NO;
DLog(@"getFilesByFileId:(int) fileId");
Expand All @@ -831,7 +831,7 @@ + (BOOL) getFilesByDownloadState:(enumDownload)downloadState andByUser:(UserDto
}


+ (void) updateFilesByUser:(UserDto *) currentUser andFolder:(NSString *) folder ToDownloadState:(enumDownload)downloadState {
+ (void) updateFilesByUser:(UserDto *) currentUser andFolder:(NSString *) folder toDownloadState:(enumDownload)downloadState {

FMDatabaseQueue *queue = [AppDelegate sharedDatabase];

Expand Down
2 changes: 1 addition & 1 deletion Owncloud iOs Client/Tabs/FileTab/DeleteFile/DeleteFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
UIView *_viewToShow;
int _deleteFromFlag;
BOOL _deleteFromFilePreview;
BOOL _filesDownloadedInFolder;
BOOL _isFilesDownloadedInFolder;
UIActionSheet *_popupQuery;
}

Expand Down
69 changes: 33 additions & 36 deletions Owncloud iOs Client/Tabs/FileTab/DeleteFile/DeleteFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ - (void)initialize

- (void)askToDeleteFileByFileDto: (FileDto *) file {

self.file = file;
_filesDownloadedInFolder=NO;
_file = file;
_isFilesDownloadedInFolder=NO;

//If the device is an iPhone and its orientation is landscape
if ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) &&
if ((IS_IPHONE) &&
([[UIApplication sharedApplication] statusBarOrientation] != UIInterfaceOrientationPortrait)) {

DLog(@"iPhone in landscape");
Expand All @@ -54,31 +54,28 @@ - (void)askToDeleteFileByFileDto: (FileDto *) file {
[alertView show];
}else{
//If the file is a directory, checks if contains downloaded files
if (self.file.isDirectory){
if (_file.isDirectory){
DLog(@"Delete a folder");
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
//Obtains the complete path of the folder
NSString *pathFolder= [NSString stringWithFormat:@"%@%@",_file.filePath,_file.fileName];
//Remove: /owncloud/remote.php/webdav/ to the pathFolder
pathFolder =[UtilsDtos getDbBFolderPathFromFullFolderPath:pathFolder];
//Obtains the number of the downloaded files in DB which filepath contains the folder that the user want delete
if ([ManageFilesDB getFilesByDownloadState:downloaded andByUser:app.activeUser andFolder:pathFolder]) {
DLog(@"Delete a folder with downloaded files");
_filesDownloadedInFolder=YES;
}
_isFilesDownloadedInFolder=[ManageFilesDB isGetFilesByDownloadState:downloaded andByUser:app.activeUser andFolder:pathFolder];
}
if(self.file.isDownload || _filesDownloadedInFolder==YES) {
if(_file.isDownload || _isFilesDownloadedInFolder==YES) {
DLog(@"Delete downloaded files or folder with downloaded files");
self.popupQuery = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"cancel", nil) destructiveButtonTitle:NSLocalizedString(@"delete_local_server", nil) otherButtonTitles:NSLocalizedString(@"delete_local", nil), nil];
_popupQuery = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"cancel", nil) destructiveButtonTitle:NSLocalizedString(@"delete_local_server", nil) otherButtonTitles:NSLocalizedString(@"delete_local", nil), nil];
} else {
DLog(@"Delete files or folder from server");
self.popupQuery = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"cancel", nil) destructiveButtonTitle:NSLocalizedString(@"delete_server", nil) otherButtonTitles:nil];
_popupQuery = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"cancel", nil) destructiveButtonTitle:NSLocalizedString(@"delete_server", nil) otherButtonTitles:nil];
}

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
[self.popupQuery showInView:self.viewToShow];
[_popupQuery showInView:_viewToShow];
}else{
[self.popupQuery showInView:[self.viewToShow window]];
[_popupQuery showInView:[_viewToShow window]];
}
}

Expand Down Expand Up @@ -106,7 +103,7 @@ - (void) deleteItemFromServerAndDeviceByFileDto:(FileDto *) file {

NSURL *urlToDelete = [NSURL URLWithString:direccion];

if ([(NSObject*)self.delegate respondsToSelector:@selector(initLoading)]) {
if ([(NSObject*)_delegate respondsToSelector:@selector(initLoading)]) {
[_delegate initLoading];
}

Expand Down Expand Up @@ -142,7 +139,7 @@ - (void) deleteItemFromServerAndDeviceByFileDto:(FileDto *) file {
//Check if there are fragmens of saml in url, in this case there are a credential error
isSamlCredentialsError = [FileNameUtils isURLWithSamlFragment:operation.response.URL.absoluteString];
if (isSamlCredentialsError) {
if ([(NSObject*)self.delegate respondsToSelector:@selector(endLoading)]) {
if ([(NSObject*)_delegate respondsToSelector:@selector(endLoading)]) {
[_delegate endLoading];
}
[_delegate errorLogin];
Expand All @@ -152,7 +149,7 @@ - (void) deleteItemFromServerAndDeviceByFileDto:(FileDto *) file {
if (!isSamlCredentialsError) {

DLog(@"Great, the item is deleted");
if([self.file isDirectory]) {
if([_file isDirectory]) {
DLog(@"Is directory");
NSError *error;

Expand All @@ -161,20 +158,20 @@ - (void) deleteItemFromServerAndDeviceByFileDto:(FileDto *) file {
[fileMgr removeItemAtPath:[self filePath] error:&error];

//Then delete folder of BD.
[self deleteFolderChildsWithIdFile:self.file.idFile];
[self deleteFolderChildsWithIdFile:_file.idFile];

}else{
//if a file
[ManageFilesDB deleteFileByIdFile:self.file.idFile];
[ManageFilesDB deleteFileByIdFile:_file.idFile];
}

//The end of delete

if ([(NSObject*)self.delegate respondsToSelector:@selector(endLoading)]) {
if ([(NSObject*)_delegate respondsToSelector:@selector(endLoading)]) {
[_delegate endLoading];
}

if ([(NSObject*)self.delegate respondsToSelector:@selector(reloadTableFromDataBase)]) {
if ([(NSObject*)_delegate respondsToSelector:@selector(reloadTableFromDataBase)]) {
[_delegate reloadTableFromDataBase];
}
//Quit movie player if the delete file is running.
Expand All @@ -187,7 +184,7 @@ - (void) deleteItemFromServerAndDeviceByFileDto:(FileDto *) file {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
DLog(@"error: %@", error);

if ([(NSObject*)self.delegate respondsToSelector:@selector(endLoading)]) {
if ([(NSObject*)_delegate respondsToSelector:@selector(endLoading)]) {
[_delegate endLoading];
}

Expand Down Expand Up @@ -246,7 +243,7 @@ - (void) deleteItemFromServerAndDeviceByFileDto:(FileDto *) file {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"not_possible_connect_to_server", nil) message:@"" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil, nil];
[alert show];

if ([(NSObject*)self.delegate respondsToSelector:@selector(endLoading)]) {
if ([(NSObject*)_delegate respondsToSelector:@selector(endLoading)]) {
[_delegate endLoading];
}
}
Expand Down Expand Up @@ -346,34 +343,34 @@ - (void)deleteFolderChildsWithIdFile:(NSInteger)idFile{


-(void) errorLogin {
if ([(NSObject*)self.delegate respondsToSelector:@selector(endLoading)]) {
if ([(NSObject*)_delegate respondsToSelector:@selector(endLoading)]) {
[_delegate endLoading];
}
//[self.delegate endLoading];
[self.delegate errorLogin];
[_delegate errorLogin];
}

/*
*Deletes items in the server
*/
- (void)executeDeleteItemInServer{
[self deleteItemFromDeviceByFileDto:self.file];
[self deleteItemFromServerAndDeviceByFileDto:self.file];
[self deleteItemFromDeviceByFileDto:_file];
[self deleteItemFromServerAndDeviceByFileDto:_file];
}

/*
*Deletes items in the device
*/
- (void)executeDeleteItemInDevice{
[self deleteItemFromDeviceByFileDto:self.file];
[self deleteItemFromDeviceByFileDto:_file];

if (_filesDownloadedInFolder==YES) {
if (_isFilesDownloadedInFolder==YES) {
//If the item deleted is a directory update the is_download state to notDownload in the files contains in the folder for deleted
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
NSString *pathFolder= [NSString stringWithFormat:@"%@%@",_file.filePath,_file.fileName];
//Remove: /owncloud/remote.php/webdav/ to the pathFolder
pathFolder =[UtilsDtos getDbBFolderPathFromFullFolderPath:pathFolder];
[ManageFilesDB updateFilesByUser:app.activeUser andFolder:pathFolder ToDownloadState:notDownload];
[ManageFilesDB updateFilesByUser:app.activeUser andFolder:pathFolder toDownloadState:notDownload];
DLog(@"path: %@",pathFolder);

//Delete the folder and the files that it contains
Expand All @@ -391,11 +388,11 @@ - (void)executeDeleteItemInDevice{

- (NSString *)filePath {

NSString *localUrl = [NSString stringWithFormat:@"%@%@", self.currentLocalFolder, self.file.fileName];
NSString *localUrl = [NSString stringWithFormat:@"%@%@", currentLocalFolder, _file.fileName];

DLog(@"Current Local Folder: %@", self.currentLocalFolder);
DLog(@"Current Local Folder: %@", currentLocalFolder);

DLog(@"File Name: %@", self.file);
DLog(@"File Name: %@", _file);

DLog(@"Local URL: %@", localUrl);

Expand Down Expand Up @@ -427,16 +424,16 @@ - (void) isConnectedToServer:(BOOL)isConnected{
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

//We check the version of iOS
if (self.file.isDownload || _filesDownloadedInFolder==YES) {
if (_file.isDownload || _isFilesDownloadedInFolder==YES) {
switch (buttonIndex) {
case 0:
NSLog(@"Delete from server");
self.deleteFromFlag = deleteFromServerAndLocal;
_deleteFromFlag = deleteFromServerAndLocal;
[self executeDeleteItemInServer];
break;
case 1:
NSLog(@"Delete from local");
self.deleteFromFlag = deleteFromLocal;
_deleteFromFlag = deleteFromLocal;
[self executeDeleteItemInDevice];
break;
case 2:
Expand All @@ -447,7 +444,7 @@ -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)
switch (buttonIndex) {
case 0:
NSLog(@"Delete from server");
self.deleteFromFlag = deleteFromServerAndLocal;
_deleteFromFlag = deleteFromServerAndLocal;
[self executeDeleteItemInServer];
break;
case 1:
Expand Down

0 comments on commit 8ac2ea7

Please sign in to comment.