remove local copy

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2018-06-06 09:06:51 +02:00 committed by AndyScherzinger
parent 075b0f52b8
commit 74b832c958
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
4 changed files with 39 additions and 13 deletions

View file

@ -95,7 +95,7 @@ implements ConfirmationDialogFragmentListener {
if (storageManager.getFileById(mTargetFile.getFileId()) != null) {
ArrayList<OCFile> list = new ArrayList<>();
list.add(mTargetFile);
cg.getFileOperationsHelper().removeFiles(list, false);
cg.getFileOperationsHelper().removeFiles(list, false, false);
}
}
@ -107,7 +107,7 @@ implements ConfirmationDialogFragmentListener {
ComponentsGetter cg = (ComponentsGetter)getActivity();
ArrayList<OCFile> list = new ArrayList<>();
list.add(mTargetFile);
cg.getFileOperationsHelper().removeFiles(list, true);
cg.getFileOperationsHelper().removeFiles(list, true, false);
FileDataStorageManager storageManager = cg.getStorageManager();

View file

@ -141,7 +141,7 @@ implements ConfirmationDialogFragmentListener {
@Override
public void onConfirmation(String callerTag) {
ComponentsGetter cg = (ComponentsGetter) getActivity();
cg.getFileOperationsHelper().removeFiles(mTargetFiles, false);
cg.getFileOperationsHelper().removeFiles(mTargetFiles, false, false);
}
/**
@ -150,7 +150,7 @@ implements ConfirmationDialogFragmentListener {
@Override
public void onCancel(String callerTag) {
ComponentsGetter cg = (ComponentsGetter) getActivity();
cg.getFileOperationsHelper().removeFiles(mTargetFiles, true);
cg.getFileOperationsHelper().removeFiles(mTargetFiles, true, false);
}
@Override

View file

@ -60,14 +60,17 @@ import com.owncloud.android.lib.resources.files.ReadFileVersionsOperation;
import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.operations.RestoreFileVersionOperation;
import com.owncloud.android.ui.activity.ComponentsGetter;
import com.owncloud.android.ui.activity.FileActivity;
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.ThemeUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindString;
import butterknife.BindView;
@ -121,6 +124,8 @@ public class FileDetailActivitiesFragment extends Fragment implements ActivityLi
public String noResultsMessage;
private boolean restoreFileVersionSupported;
private String userId;
private FileOperationsHelper operationsHelper;
private FileDataStorageManager storageManager;
public static FileDetailActivitiesFragment newInstance(OCFile file, Account account) {
FileDetailActivitiesFragment fragment = new FileDetailActivitiesFragment();
@ -189,7 +194,8 @@ public class FileDetailActivitiesFragment extends Fragment implements ActivityLi
}
private void setupView() {
FileDataStorageManager storageManager = new FileDataStorageManager(account, getActivity().getContentResolver());
storageManager = new FileDataStorageManager(account, getActivity().getContentResolver());
operationsHelper = ((ComponentsGetter) getActivity()).getFileOperationsHelper();
OCCapability capability = storageManager.getCapability(account.name);
OwnCloudVersion serverVersion = AccountUtils.getServerVersion(account);
@ -388,22 +394,31 @@ public class FileDetailActivitiesFragment extends Fragment implements ActivityLi
@Override
public void onRestoreClicked(FileVersion fileVersion, VersionListInterface.Callback callback) {
new RestoreFileVersionTask(fileVersion, userId, ownCloudClient, callback).execute();
new RestoreFileVersionTask(fileVersion, userId, ownCloudClient, storageManager, operationsHelper, file,
callback).execute();
}
// TODO extract according to MVP, will be in following PR
private static class RestoreFileVersionTask extends AsyncTask<Void, Void, Boolean> {
private FileVersion file;
private FileVersion fileVersion;
private String userId;
private OwnCloudClient client;
private FileOperationsHelper operationsHelper;
private FileDataStorageManager storageManager;
private OCFile ocFile;
private VersionListInterface.Callback callback;
private RestoreFileVersionTask(FileVersion file, String userId, OwnCloudClient client,
private RestoreFileVersionTask(FileVersion fileVersion, String userId, OwnCloudClient client,
FileDataStorageManager storageManager, FileOperationsHelper operationsHelper,
OCFile ocFile,
VersionListInterface.Callback callback) {
this.file = file;
this.fileVersion = fileVersion;
this.userId = userId;
this.client = client;
this.storageManager = storageManager;
this.operationsHelper = operationsHelper;
this.ocFile = ocFile;
this.callback = callback;
}
@ -411,10 +426,18 @@ public class FileDetailActivitiesFragment extends Fragment implements ActivityLi
protected Boolean doInBackground(Void... voids) {
RestoreFileVersionOperation restoreFileVersionOperation = new RestoreFileVersionOperation(
file.getRemoteId(), file.getFileName(), userId);
fileVersion.getRemoteId(), fileVersion.getFileName(), userId);
RemoteOperationResult result = restoreFileVersionOperation.execute(client);
if (result.isSuccess()) {
if (ocFile.isDown()) {
List<OCFile> list = new ArrayList<>();
list.add(ocFile);
operationsHelper.removeFiles(list, true, true);
}
}
return result.isSuccess();
}
@ -423,7 +446,7 @@ public class FileDetailActivitiesFragment extends Fragment implements ActivityLi
super.onPostExecute(success);
if (success) {
callback.onSuccess(file);
callback.onSuccess(fileVersion);
} else {
callback.onError("error");

View file

@ -836,8 +836,9 @@ public class FileOperationsHelper {
* @param files Files to delete
* @param onlyLocalCopy When 'true' only local copy of the files is removed; otherwise files are also deleted
* in the server.
* @param inBackground When 'true', do not show any loading dialog
*/
public void removeFiles(Collection<OCFile> files, boolean onlyLocalCopy) {
public void removeFiles(Collection<OCFile> files, boolean onlyLocalCopy, boolean inBackground) {
for (OCFile file : files) {
// RemoveFile
Intent service = new Intent(mFileActivity, OperationsService.class);
@ -848,8 +849,10 @@ public class FileOperationsHelper {
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
}
if (!inBackground) {
mFileActivity.showLoadingDialog(mFileActivity.getString(R.string.wait_a_moment));
}
}
public void createFolder(String remotePath, boolean createFullPath) {