From: David A. Velasco Date: Mon, 12 May 2014 07:59:19 +0000 (+0200) Subject: Joint local removal of files to RemoteFileOperation to fix refresh of UI X-Git-Tag: oc-android-1.7.0_signed~309^2~36 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/6cb184ab6377431383d7a6b30da30c3c4b02d8d7?ds=inline;hp=--cc Joint local removal of files to RemoteFileOperation to fix refresh of UI --- 6cb184ab6377431383d7a6b30da30c3c4b02d8d7 diff --git a/owncloud-android-library b/owncloud-android-library index 21577231..16d237e4 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit 2157723124a15dffb0a142c25e4ca706558acc48 +Subproject commit 16d237e42ad8338aea13365f6a50459f3b6c1fd8 diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 44d78206..a6765310 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -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; } /** diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index d037e832..c596ed93 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -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(); diff --git a/src/com/owncloud/android/operations/RemoveFileOperation.java b/src/com/owncloud/android/operations/RemoveFileOperation.java index c5883b1c..6bd4e8a0 100644 --- a/src/com/owncloud/android/operations/RemoveFileOperation.java +++ b/src/com/owncloud/android/operations/RemoveFileOperation.java @@ -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; diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index c3082d42..0bed2399 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -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 diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index e5cf6d7a..641ff9e6 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -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 diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index e13f109c..4b471171 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -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 diff --git a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java index 608fc62c..aa2a6b36 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -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(); } /** diff --git a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java index 8762cbdd..2c32d4a9 100644 --- a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@ -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(); } /**