OC-2868: Fix bug: Unshare a file that does not exist any more, no message is shown

This commit is contained in:
masensio 2014-02-07 12:54:52 +01:00
parent ebbc1793e2
commit eb7bbebc08
5 changed files with 25 additions and 5 deletions

View file

@ -250,5 +250,6 @@
<string name="share_link_no_support_share_api">Sorry, sharing is not enabled on your server. Please contact your administrator.</string>
<string name="share_link_file_no_exist">Unable to share this file or folder. Please, make sure it exists</string>
<string name="share_link_file_error">An error occurred while trying to share this file or folder</string>
<string name="unshare_link_file_no_exist">Unable to unshare this file or folder. It does not exist.</string>
<string name="unshare_link_file_error">An error occurred while trying to unshare this file or folder</string>
</resources>

View file

@ -146,7 +146,7 @@ public class FileOperationsHelper {
if (isSharedSupported(callerActivity)) {
// Unshare the file
UnshareLinkOperation unshare = new UnshareLinkOperation(file);
UnshareLinkOperation unshare = new UnshareLinkOperation(file, callerActivity);
unshare.execute(callerActivity.getStorageManager(),
callerActivity,
callerActivity.getRemoteOperationListener(),

View file

@ -17,11 +17,14 @@
package com.owncloud.android.operations;
import android.content.Context;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.network.OwnCloudClient;
import com.owncloud.android.lib.operations.common.OCShare;
import com.owncloud.android.lib.operations.common.RemoteOperationResult;
import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.operations.remote.ExistenceCheckRemoteOperation;
import com.owncloud.android.lib.operations.remote.RemoveRemoteShareOperation;
import com.owncloud.android.operations.common.SyncOperation;
import com.owncloud.android.utils.Log_OC;
@ -37,9 +40,12 @@ public class UnshareLinkOperation extends SyncOperation {
private static final String TAG = UnshareLinkOperation.class.getSimpleName();
private OCFile mFile;
private Context mContext;
public UnshareLinkOperation(OCFile file) {
public UnshareLinkOperation(OCFile file, Context context) {
mFile = file;
mContext = context;
}
@Override
@ -66,7 +72,11 @@ public class UnshareLinkOperation extends SyncOperation {
getStorageManager().removeShare(share);
if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
result = new RemoteOperationResult(ResultCode.OK);
if (existsFile(client, mFile.getRemotePath())) {
result = new RemoteOperationResult(ResultCode.OK);
} else {
getStorageManager().removeFile(mFile, true, true);
}
}
}
@ -76,5 +86,11 @@ public class UnshareLinkOperation extends SyncOperation {
return result;
}
private boolean existsFile(OwnCloudClient client, String remotePath){
ExistenceCheckRemoteOperation existsOperation = new ExistenceCheckRemoteOperation(remotePath, mContext, false);
RemoteOperationResult result = existsOperation.execute(client);
return result.isSuccess();
}
}

View file

@ -381,7 +381,10 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) {
dismissLoadingDialog();
if (!result.isSuccess()){ // Generic error
if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND
Toast t = Toast.makeText(this, getString(R.string.unshare_link_file_no_exist), Toast.LENGTH_LONG);
t.show();
} else if (!result.isSuccess()){ // Generic error
// Show a Message, operation finished without success
Toast t = Toast.makeText(this, getString(R.string.unshare_link_file_error), Toast.LENGTH_LONG);
t.show();

View file

@ -1350,7 +1350,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) {
if (result.isSuccess()) {
if (result.isSuccess() || result.getCode() == ResultCode.SHARE_NOT_FOUND) {
refreshShowDetails();
refeshListOfFilesFragment();
}