mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
Joint local removal of files to RemoteFileOperation to fix refresh of UI
This commit is contained in:
parent
288dbd6348
commit
6cb184ab63
9 changed files with 75 additions and 51 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 2157723124a15dffb0a142c25e4ca706558acc48
|
||||
Subproject commit 16d237e42ad8338aea13365f6a50459f3b6c1fd8
|
|
@ -422,10 +422,11 @@ public class FileDataStorageManager {
|
|||
// }
|
||||
|
||||
|
||||
public void removeFile(OCFile file, boolean removeDBData, boolean removeLocalCopy) {
|
||||
public boolean removeFile(OCFile file, boolean removeDBData, boolean removeLocalCopy) {
|
||||
boolean success = true;
|
||||
if (file != null) {
|
||||
if (file.isFolder()) {
|
||||
removeFolder(file, removeDBData, removeLocalCopy);
|
||||
success = removeFolder(file, removeDBData, removeLocalCopy);
|
||||
|
||||
} else {
|
||||
if (removeDBData) {
|
||||
|
@ -433,19 +434,20 @@ public class FileDataStorageManager {
|
|||
Uri file_uri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, file.getFileId());
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?";
|
||||
String [] whereArgs = new String[]{mAccount.name, file.getRemotePath()};
|
||||
int deleted = 0;
|
||||
if (getContentProviderClient() != null) {
|
||||
try {
|
||||
getContentProviderClient().delete(file_uri, where, whereArgs);
|
||||
deleted = getContentProviderClient().delete(file_uri, where, whereArgs);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
getContentResolver().delete(file_uri, where, whereArgs);
|
||||
deleted = getContentResolver().delete(file_uri, where, whereArgs);
|
||||
}
|
||||
//updateFolderSize(file.getParentId());
|
||||
success &= (deleted > 0);
|
||||
}
|
||||
if (removeLocalCopy && file.isDown() && file.getStoragePath() != null) {
|
||||
boolean success = new File(file.getStoragePath()).delete();
|
||||
if (removeLocalCopy && file.isDown() && file.getStoragePath() != null && success) {
|
||||
success = new File(file.getStoragePath()).delete();
|
||||
if (!removeDBData && success) {
|
||||
// maybe unnecessary, but should be checked TODO remove if unnecessary
|
||||
file.setStoragePath(null);
|
||||
|
@ -454,51 +456,57 @@ public class FileDataStorageManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
public void removeFolder(OCFile folder, boolean removeDBData, boolean removeLocalContent) {
|
||||
public boolean removeFolder(OCFile folder, boolean removeDBData, boolean removeLocalContent) {
|
||||
boolean success = true;
|
||||
if (folder != null && folder.isFolder()) {
|
||||
if (removeDBData && folder.getFileId() != -1) {
|
||||
removeFolderInDb(folder);
|
||||
success = removeFolderInDb(folder);
|
||||
}
|
||||
if (removeLocalContent) {
|
||||
if (removeLocalContent && success) {
|
||||
File localFolder = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, folder));
|
||||
removeLocalFolder(localFolder);
|
||||
success = removeLocalFolder(localFolder);
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
private void removeFolderInDb(OCFile folder) {
|
||||
private boolean removeFolderInDb(OCFile folder) {
|
||||
Uri folder_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, ""+ folder.getFileId()); // URI for recursive deletion
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?";
|
||||
String [] whereArgs = new String[]{mAccount.name, folder.getRemotePath()};
|
||||
int deleted = 0;
|
||||
if (getContentProviderClient() != null) {
|
||||
try {
|
||||
getContentProviderClient().delete(folder_uri, where, whereArgs);
|
||||
deleted = getContentProviderClient().delete(folder_uri, where, whereArgs);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
getContentResolver().delete(folder_uri, where, whereArgs);
|
||||
deleted = getContentResolver().delete(folder_uri, where, whereArgs);
|
||||
}
|
||||
//updateFolderSize(folder.getParentId());
|
||||
return deleted > 0;
|
||||
}
|
||||
|
||||
private void removeLocalFolder(File folder) {
|
||||
private boolean removeLocalFolder(File folder) {
|
||||
boolean success = true;
|
||||
if (folder.exists()) {
|
||||
File[] files = folder.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
removeLocalFolder(file);
|
||||
success &= removeLocalFolder(file);
|
||||
} else {
|
||||
file.delete();
|
||||
success &= file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
folder.delete();
|
||||
success &= folder.delete();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -220,13 +220,13 @@ public class FileOperationsHelper {
|
|||
}
|
||||
|
||||
|
||||
public void removeFile(OCFile file, boolean removeLocalCopy) {
|
||||
public void removeFile(OCFile file, boolean onlyLocalCopy) {
|
||||
// RemoveFile
|
||||
Intent service = new Intent(mFileActivity, OperationsService.class);
|
||||
service.setAction(OperationsService.ACTION_REMOVE);
|
||||
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
|
||||
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
|
||||
service.putExtra(OperationsService.EXTRA_REMOVE_LOCAL_COPY, removeLocalCopy);
|
||||
service.putExtra(OperationsService.EXTRA_REMOVE_ONLY_LOCAL, onlyLocalCopy);
|
||||
mFileActivity.getOperationsServiceBinder().newOperation(service);
|
||||
|
||||
mFileActivity.showLoadingDialog();
|
||||
|
|
|
@ -37,18 +37,20 @@ public class RemoveFileOperation extends SyncOperation {
|
|||
|
||||
OCFile mFileToRemove;
|
||||
String mRemotePath;
|
||||
boolean mDeleteLocalCopy;
|
||||
boolean mOnlyLocalCopy;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param remotePath RemotePath of the OCFile instance describing the remote file or folder to remove from the server
|
||||
* @param deleteLocalCopy When 'true', and a local copy of the file exists, it is also removed.
|
||||
* @param remotePath RemotePath of the OCFile instance describing the remote file or
|
||||
* folder to remove from the server
|
||||
* @param onlyLocalCopy When 'true', and a local copy of the file exists, only this is
|
||||
* removed.
|
||||
*/
|
||||
public RemoveFileOperation(String remotePath, boolean deleteLocalCopy) {
|
||||
public RemoveFileOperation(String remotePath, boolean onlyLocalCopy) {
|
||||
mRemotePath = remotePath;
|
||||
mDeleteLocalCopy = deleteLocalCopy;
|
||||
mOnlyLocalCopy = onlyLocalCopy;
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,13 +72,25 @@ public class RemoveFileOperation extends SyncOperation {
|
|||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
RemoteOperationResult result = null;
|
||||
|
||||
RemoveRemoteFileOperation operation = new RemoveRemoteFileOperation(mRemotePath);
|
||||
result = operation.execute(client);
|
||||
|
||||
mFileToRemove = getStorageManager().getFileByPath(mRemotePath);
|
||||
|
||||
boolean localRemovalFailed = false;
|
||||
if (!mOnlyLocalCopy) {
|
||||
RemoveRemoteFileOperation operation = new RemoveRemoteFileOperation(mRemotePath);
|
||||
result = operation.execute(client);
|
||||
if (result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND) {
|
||||
localRemovalFailed = !(getStorageManager().removeFile(mFileToRemove, true, true));
|
||||
}
|
||||
|
||||
} else {
|
||||
localRemovalFailed = !(getStorageManager().removeFile(mFileToRemove, false, true));
|
||||
if (!localRemovalFailed) {
|
||||
result = new RemoteOperationResult(ResultCode.OK);
|
||||
}
|
||||
}
|
||||
|
||||
if (result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND) {
|
||||
getStorageManager().removeFile(mFileToRemove, true, mDeleteLocalCopy);
|
||||
if (localRemovalFailed) {
|
||||
result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_REMOVED);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -68,7 +68,7 @@ public class OperationsService extends Service {
|
|||
public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
|
||||
public static final String EXTRA_SEND_INTENT = "SEND_INTENT";
|
||||
public static final String EXTRA_NEWNAME = "NEWNAME";
|
||||
public static final String EXTRA_REMOVE_LOCAL_COPY = "REMOVE_LOCAL_COPY";
|
||||
public static final String EXTRA_REMOVE_ONLY_LOCAL = "REMOVE_LOCAL_COPY";
|
||||
public static final String EXTRA_CREATE_FULL_PATH = "CREATE_FULL_PATH";
|
||||
public static final String EXTRA_RESULT = "RESULT";
|
||||
|
||||
|
@ -349,8 +349,8 @@ public class OperationsService extends Service {
|
|||
} else if (action.equals(ACTION_REMOVE)) {
|
||||
// Remove file or folder
|
||||
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
|
||||
boolean removeLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_LOCAL_COPY, true);
|
||||
operation = new RemoveFileOperation(remotePath, removeLocalCopy);
|
||||
boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false);
|
||||
operation = new RemoveFileOperation(remotePath, onlyLocalCopy);
|
||||
|
||||
} else if (action.equals(ACTION_CREATE_FOLDER)) {
|
||||
// Create Folder
|
||||
|
|
|
@ -315,7 +315,7 @@ public class FileDetailFragment extends FileFragment implements
|
|||
OCFile file = getFile();
|
||||
if (callerTag.equals(FTAG_CONFIRMATION)) {
|
||||
if (mContainerActivity.getStorageManager().getFileById(file.getFileId()) != null) {
|
||||
mContainerActivity.getFileOperationsHelper().removeFile(file, true);
|
||||
mContainerActivity.getFileOperationsHelper().removeFile(file, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -323,11 +323,11 @@ public class FileDetailFragment extends FileFragment implements
|
|||
@Override
|
||||
public void onNeutral(String callerTag) {
|
||||
OCFile file = getFile();
|
||||
mContainerActivity.getStorageManager().removeFile(file, false, true); // TODO perform in background task / new thread
|
||||
if (file.getStoragePath() != null) {
|
||||
file.setStoragePath(null);
|
||||
updateFileDetails(file, mAccount);
|
||||
}
|
||||
mContainerActivity.getFileOperationsHelper().removeFile(file, true);
|
||||
//if (file.getStoragePath() != null) {
|
||||
// file.setStoragePath(null);
|
||||
// updateFileDetails(file, mAccount);
|
||||
//}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -471,16 +471,16 @@ implements EditNameDialogListener, ConfirmationDialogFragmentListener {
|
|||
if (callerTag.equals(FileDetailFragment.FTAG_CONFIRMATION)) {
|
||||
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
|
||||
if (storageManager.getFileById(mTargetFile.getFileId()) != null) {
|
||||
mContainerActivity.getFileOperationsHelper().removeFile(mTargetFile, true);
|
||||
mContainerActivity.getFileOperationsHelper().removeFile(mTargetFile, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeutral(String callerTag) {
|
||||
mContainerActivity.getStorageManager().removeFile(mTargetFile, false, true); // TODO perform in background task / new thread
|
||||
listDirectory();
|
||||
mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
|
||||
mContainerActivity.getFileOperationsHelper().removeFile(mTargetFile, true);
|
||||
//listDirectory();
|
||||
//mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -346,7 +346,7 @@ ConfirmationDialogFragment.ConfirmationDialogFragmentListener {
|
|||
public void onConfirmation(String callerTag) {
|
||||
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
|
||||
if (storageManager.getFileById(getFile().getFileId()) != null) { // check that the file is still there;
|
||||
mContainerActivity.getFileOperationsHelper().removeFile(getFile(), true);
|
||||
mContainerActivity.getFileOperationsHelper().removeFile(getFile(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -357,8 +357,9 @@ ConfirmationDialogFragment.ConfirmationDialogFragmentListener {
|
|||
@Override
|
||||
public void onNeutral(String callerTag) {
|
||||
OCFile file = getFile();
|
||||
mContainerActivity.getStorageManager().removeFile(file, false, true); // TODO perform in background task / new thread
|
||||
finish();
|
||||
mContainerActivity.getFileOperationsHelper().removeFile(file, true);
|
||||
//mContainerActivity.getStorageManager().removeFile(file, false, true); // TODO perform in background task / new thread
|
||||
//finish();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -618,7 +618,7 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
|
||||
if (storageManager.getFileById(file.getFileId()) != null) { // check that the file is still there;
|
||||
stopPreview(true);
|
||||
mContainerActivity.getFileOperationsHelper().removeFile(file, true);
|
||||
mContainerActivity.getFileOperationsHelper().removeFile(file, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -630,8 +630,9 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
public void onNeutral(String callerTag) {
|
||||
OCFile file = getFile();
|
||||
stopPreview(true);
|
||||
mContainerActivity.getStorageManager().removeFile(file, false, true); // TODO perform in background task / new thread
|
||||
finish();
|
||||
//mContainerActivity.getStorageManager().removeFile(file, false, true); // TODO perform in background task / new thread
|
||||
mContainerActivity.getFileOperationsHelper().removeFile(file, true);
|
||||
//finish();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue