- removed m prefix

- in background for file deletion
- download new file version if file was previously downloaded
- show snackbar on success
- cleanup

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2018-06-14 14:04:49 +02:00 committed by AndyScherzinger
parent ddde216a4c
commit 818ec6473e
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
7 changed files with 47 additions and 46 deletions

View file

@ -40,13 +40,12 @@ import com.owncloud.android.operations.common.SyncOperation;
*/
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;
}
/**
@ -84,29 +89,29 @@ public class RemoveFileOperation extends SyncOperation {
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);
}

View file

@ -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

View file

@ -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<OCFile> 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);
}
}

View file

@ -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);

View file

@ -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);
}

View file

@ -27,9 +27,5 @@ public interface VersionListInterface {
interface View {
void onRestoreClicked(FileVersion fileVersion);
void onSuccess(String message);
void onError(String message);
}
}

View file

@ -799,5 +799,6 @@
<string name="whats_new_device_credentials_content">Use anything like a pattern, password, pin or your fingerprint to keep your data safe.</string>
<string name="restore">Restore file</string>
<string name="new_version_was_created">New version was created</string>
<string name="file_version_restored_successfully">Successfully restored file version.</string>
<string name="file_version_restored_error">Error restoring file version!</string>
</resources>