From eb7bbebc089ddd878442f1d7127974e56493e9ce Mon Sep 17 00:00:00 2001 From: masensio Date: Fri, 7 Feb 2014 12:54:52 +0100 Subject: [PATCH] OC-2868: Fix bug: Unshare a file that does not exist any more, no message is shown --- res/values/strings.xml | 1 + .../android/files/FileOperationsHelper.java | 2 +- .../operations/UnshareLinkOperation.java | 20 +++++++++++++++++-- .../android/ui/activity/FileActivity.java | 5 ++++- .../ui/activity/FileDisplayActivity.java | 2 +- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index b86d608580..f6871a6a63 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -250,5 +250,6 @@ Sorry, sharing is not enabled on your server. Please contact your administrator. Unable to share this file or folder. Please, make sure it exists An error occurred while trying to share this file or folder + Unable to unshare this file or folder. It does not exist. An error occurred while trying to unshare this file or folder diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index 1c0db87bd4..f88e34b19c 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -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(), diff --git a/src/com/owncloud/android/operations/UnshareLinkOperation.java b/src/com/owncloud/android/operations/UnshareLinkOperation.java index ad23427f0a..6e273c87a8 100644 --- a/src/com/owncloud/android/operations/UnshareLinkOperation.java +++ b/src/com/owncloud/android/operations/UnshareLinkOperation.java @@ -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(); + } } diff --git a/src/com/owncloud/android/ui/activity/FileActivity.java b/src/com/owncloud/android/ui/activity/FileActivity.java index fac275cac1..7bb984e133 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -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(); diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index da3ced908e..672853118e 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -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(); }