<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>
if (isSharedSupported(callerActivity)) {
// Unshare the file
- UnshareLinkOperation unshare = new UnshareLinkOperation(file);
+ UnshareLinkOperation unshare = new UnshareLinkOperation(file, callerActivity);
unshare.execute(callerActivity.getStorageManager(),
callerActivity,
callerActivity.getRemoteOperationListener(),
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;
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
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);
+ }
}
}
return result;
}
+
+ private boolean existsFile(OwnCloudClient client, String remotePath){
+ ExistenceCheckRemoteOperation existsOperation = new ExistenceCheckRemoteOperation(remotePath, mContext, false);
+ RemoteOperationResult result = existsOperation.execute(client);
+ return result.isSuccess();
+ }
}
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();