X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/9343650e8496e6b1c895e448ad91bc9682d3c2f2..e901b609baa4dd5f681e2a5257c9e504997e3377:/src/com/owncloud/android/operations/CreateShareOperation.java?ds=inline diff --git a/src/com/owncloud/android/operations/CreateShareOperation.java b/src/com/owncloud/android/operations/CreateShareOperation.java index 7277b3a7..c32c4771 100644 --- a/src/com/owncloud/android/operations/CreateShareOperation.java +++ b/src/com/owncloud/android/operations/CreateShareOperation.java @@ -30,16 +30,19 @@ import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.resources.shares.OCShare; +import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation; import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation; import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.operations.common.SyncOperation; -import com.owncloud.android.utils.Log_OC; public class CreateShareOperation extends SyncOperation { private static final String TAG = CreateShareOperation.class.getSimpleName(); + protected FileDataStorageManager mStorageManager; @@ -83,39 +86,24 @@ public class CreateShareOperation extends SyncOperation { @Override protected RemoteOperationResult run(OwnCloudClient client) { - CreateRemoteShareOperation operation = new CreateRemoteShareOperation(mPath, mShareType, mShareWith, mPublicUpload, mPassword, mPermissions); - RemoteOperationResult result = operation.execute(client); - + RemoteOperation operation = null; + + // Check if the share link already exists + operation = new GetRemoteSharesForFileOperation(mPath, false, false); + RemoteOperationResult result = ((GetRemoteSharesForFileOperation)operation).execute(client); + + if (!result.isSuccess() || result.getData().size() <= 0) { + operation = new CreateRemoteShareOperation(mPath, mShareType, mShareWith, mPublicUpload, mPassword, mPermissions); + result = ((CreateRemoteShareOperation)operation).execute(client); + } + if (result.isSuccess()) { - if (result.getData().size() > 0) { OCShare share = (OCShare) result.getData().get(0); - - // Update DB with the response - share.setPath(mPath); - if (mPath.endsWith(FileUtils.PATH_SEPARATOR)) { - share.setIsFolder(true); - } else { - share.setIsFolder(false); - } - share.setPermissions(mPermissions); - - getStorageManager().saveShare(share); - - // Update OCFile with data from share: ShareByLink and publicLink - OCFile file = getStorageManager().getFileByPath(mPath); - if (file!=null) { - mSendIntent.putExtra(Intent.EXTRA_TEXT, share.getShareLink()); - file.setPublicLink(share.getShareLink()); - file.setShareByLink(true); - getStorageManager().saveFile(file); - Log_OC.d(TAG, "Public Link = " + file.getPublicLink()); - - } - } + updateData(share); + } } - - + return result; } @@ -123,5 +111,29 @@ public class CreateShareOperation extends SyncOperation { public Intent getSendIntent() { return mSendIntent; } + + private void updateData(OCShare share) { + // Update DB with the response + share.setPath(mPath); + if (mPath.endsWith(FileUtils.PATH_SEPARATOR)) { + share.setIsFolder(true); + } else { + share.setIsFolder(false); + } + share.setPermissions(mPermissions); + + getStorageManager().saveShare(share); + + // Update OCFile with data from share: ShareByLink and publicLink + OCFile file = getStorageManager().getFileByPath(mPath); + if (file!=null) { + mSendIntent.putExtra(Intent.EXTRA_TEXT, share.getShareLink()); + file.setPublicLink(share.getShareLink()); + file.setShareByLink(true); + getStorageManager().saveFile(file); + Log_OC.d(TAG, "Public Link = " + file.getPublicLink()); + + } + } }