diff --git a/src/main/java/com/owncloud/android/operations/RemoveFileOperation.java b/src/main/java/com/owncloud/android/operations/RemoveFileOperation.java index de6e886ee8..7c955de72b 100644 --- a/src/main/java/com/owncloud/android/operations/RemoveFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/RemoveFileOperation.java @@ -39,14 +39,13 @@ import com.owncloud.android.operations.common.SyncOperation; * Remote operation performing the removal of a remote file or folder in the ownCloud server. */ public class RemoveFileOperation extends SyncOperation { - - // private static final String TAG = RemoveFileOperation.class.getSimpleName(); - private OCFile mFileToRemove; - private String mRemotePath; - private boolean mOnlyLocalCopy; - private Account mAccount; - private Context mContext; + private OCFile fileToRemove; + private String remotePath; + private boolean onlyLocalCopy; + private Account account; + private boolean inBackground; + private Context context; /** @@ -57,11 +56,13 @@ public class RemoveFileOperation extends SyncOperation { * @param onlyLocalCopy When 'true', and a local copy of the file exists, only this is * removed. */ - public RemoveFileOperation(String remotePath, boolean onlyLocalCopy, Account account, Context context) { - mRemotePath = remotePath; - mOnlyLocalCopy = onlyLocalCopy; - mAccount = account; - mContext = context; + public RemoveFileOperation(String remotePath, boolean onlyLocalCopy, Account account, boolean inBackground, + Context context) { + this.remotePath = remotePath; + this.onlyLocalCopy = onlyLocalCopy; + this.account = account; + this.inBackground = inBackground; + this.context = context; } @@ -71,7 +72,11 @@ public class RemoveFileOperation extends SyncOperation { * @return File to remove or already removed. */ public OCFile getFile() { - return mFileToRemove; + return fileToRemove; + } + + public boolean isInBackground() { + return inBackground; } /** @@ -83,30 +88,30 @@ public class RemoveFileOperation extends SyncOperation { protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; RemoteOperation operation; - - mFileToRemove = getStorageManager().getFileByPath(mRemotePath); + + fileToRemove = getStorageManager().getFileByPath(remotePath); // store resized image - ThumbnailsCacheManager.generateResizedImage(mFileToRemove); + ThumbnailsCacheManager.generateResizedImage(fileToRemove); boolean localRemovalFailed = false; - if (!mOnlyLocalCopy) { + if (!onlyLocalCopy) { - if (mFileToRemove.isEncrypted() && + if (fileToRemove.isEncrypted() && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { - OCFile parent = getStorageManager().getFileByPath(mFileToRemove.getParentRemotePath()); - operation = new RemoveRemoteEncryptedFileOperation(mRemotePath, parent.getLocalId(), mAccount, mContext, - mFileToRemove.getEncryptedFileName()); + OCFile parent = getStorageManager().getFileByPath(fileToRemove.getParentRemotePath()); + operation = new RemoveRemoteEncryptedFileOperation(remotePath, parent.getLocalId(), account, context, + fileToRemove.getEncryptedFileName()); } else { - operation = new RemoveRemoteFileOperation(mRemotePath); + operation = new RemoveRemoteFileOperation(remotePath); } result = operation.execute(client); if (result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND) { - localRemovalFailed = !(getStorageManager().removeFile(mFileToRemove, true, true)); + localRemovalFailed = !(getStorageManager().removeFile(fileToRemove, true, true)); } } else { - localRemovalFailed = !(getStorageManager().removeFile(mFileToRemove, false, true)); + localRemovalFailed = !(getStorageManager().removeFile(fileToRemove, false, true)); if (!localRemovalFailed) { result = new RemoteOperationResult(ResultCode.OK); } diff --git a/src/main/java/com/owncloud/android/services/OperationsService.java b/src/main/java/com/owncloud/android/services/OperationsService.java index 946d35f1f4..141320b268 100644 --- a/src/main/java/com/owncloud/android/services/OperationsService.java +++ b/src/main/java/com/owncloud/android/services/OperationsService.java @@ -104,6 +104,7 @@ public class OperationsService extends Service { public static final String EXTRA_SHARE_PUBLIC_UPLOAD = "SHARE_PUBLIC_UPLOAD"; public static final String EXTRA_SHARE_ID = "SHARE_ID"; public static final String EXTRA_USER_ID = "USER_ID"; + public static final String EXTRA_IN_BACKGROUND = "IN_BACKGROUND"; public static final String EXTRA_COOKIE = "COOKIE"; @@ -656,7 +657,9 @@ public class OperationsService extends Service { // Remove file or folder String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false); - operation = new RemoveFileOperation(remotePath, onlyLocalCopy, account, getApplicationContext()); + boolean inBackground = operationIntent.getBooleanExtra(EXTRA_IN_BACKGROUND, false); + operation = new RemoveFileOperation(remotePath, onlyLocalCopy, account, inBackground, + getApplicationContext()); } else if (action.equals(ACTION_CREATE_FOLDER)) { // Create Folder diff --git a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 2ce34dd135..4cb0f7af76 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1762,9 +1762,11 @@ public class FileDisplayActivity extends HookActivity */ private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) { - DisplayUtils.showSnackMessage( - this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()) - ); + + if (!operation.isInBackground()) { + DisplayUtils.showSnackMessage(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, + getResources())); + } if (result.isSuccess()) { OCFile removedFile = operation.getFile(); @@ -1797,10 +1799,14 @@ public class FileDisplayActivity extends HookActivity if (result.isSuccess()) { OCFile file = getFile(); + // delete old local copy if (file.isDown()) { List list = new ArrayList<>(); list.add(file); getFileOperationsHelper().removeFiles(list, true, true); + + // download new version, only if file was previously download + getFileOperationsHelper().syncFile(file); } OCFile parent = getStorageManager().getFileById(file.getParentId()); @@ -1810,9 +1816,10 @@ public class FileDisplayActivity extends HookActivity FileDetailFragment fileDetailFragment = (FileDetailFragment) getSecondFragment(); fileDetailFragment.getFileDetailActivitiesFragment().reload(); } + + DisplayUtils.showSnackMessage(this, R.string.file_version_restored_successfully); } else { - Snackbar.make(getSecondFragment().getView(), R.string.file_version_restored_error, - Snackbar.LENGTH_LONG).show(); + DisplayUtils.showSnackMessage(this, R.string.file_version_restored_error); } } diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java index babc758dc7..a4f5fca1f5 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java @@ -63,7 +63,6 @@ import com.owncloud.android.ui.adapter.ActivityAndVersionListAdapter; import com.owncloud.android.ui.helpers.FileOperationsHelper; import com.owncloud.android.ui.interfaces.ActivityListInterface; import com.owncloud.android.ui.interfaces.VersionListInterface; -import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.ThemeUtils; import java.io.IOException; @@ -386,17 +385,6 @@ public class FileDetailActivitiesFragment extends Fragment implements ActivityLi outState.putParcelable(FileActivity.EXTRA_ACCOUNT, account); } - @Override - public void onSuccess(String message) { - DisplayUtils.showSnackMessage(recyclerView, message); - fetchAndSetData(null); - } - - @Override - public void onError(String message) { - DisplayUtils.showSnackMessage(recyclerView, message); - } - @Override public void onRestoreClicked(FileVersion fileVersion) { operationsHelper.restoreFileVersion(fileVersion, userId); diff --git a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index 0469071470..bb4d7e5ba8 100755 --- a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -869,6 +869,7 @@ public class FileOperationsHelper { service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); service.putExtra(OperationsService.EXTRA_REMOVE_ONLY_LOCAL, onlyLocalCopy); + service.putExtra(OperationsService.EXTRA_IN_BACKGROUND, inBackground); mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service); } diff --git a/src/main/java/com/owncloud/android/ui/interfaces/VersionListInterface.java b/src/main/java/com/owncloud/android/ui/interfaces/VersionListInterface.java index 0443679eb8..878b482714 100644 --- a/src/main/java/com/owncloud/android/ui/interfaces/VersionListInterface.java +++ b/src/main/java/com/owncloud/android/ui/interfaces/VersionListInterface.java @@ -27,9 +27,5 @@ public interface VersionListInterface { interface View { void onRestoreClicked(FileVersion fileVersion); - - void onSuccess(String message); - - void onError(String message); } } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index ecddcaaf42..b0a21e0adb 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -799,5 +799,6 @@ Use anything like a pattern, password, pin or your fingerprint to keep your data safe. Restore file New version was created + Successfully restored file version. Error restoring file version!