From: masensio Date: Tue, 18 Mar 2014 11:51:15 +0000 (+0100) Subject: OC-3314: Modify CreateShareOperation#run in the application so that it uses GetRemote... X-Git-Tag: oc-android-1.5.5~5^2~6^2~8 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/a043bcd8de7734396d2168cc2d0f1ad8aad8a116?hp=--cc OC-3314: Modify CreateShareOperation#run in the application so that it uses GetRemoteSharesForFileOperation() to get a remote link in the server (if exists) and use it without creating a new one --- a043bcd8de7734396d2168cc2d0f1ad8aad8a116 diff --git a/owncloud-android-library b/owncloud-android-library index 30acd487..b7c13628 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit 30acd4875dda3fd0bec83daaad522f3d5a02ead6 +Subproject commit b7c136286e8f2ef17f99da891f3e9fc600c25aed diff --git a/src/com/owncloud/android/operations/CreateShareOperation.java b/src/com/owncloud/android/operations/CreateShareOperation.java index 7277b3a7..17151abf 100644 --- a/src/com/owncloud/android/operations/CreateShareOperation.java +++ b/src/com/owncloud/android/operations/CreateShareOperation.java @@ -30,7 +30,9 @@ 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.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; @@ -40,6 +42,9 @@ import com.owncloud.android.utils.Log_OC; public class CreateShareOperation extends SyncOperation { private static final String TAG = CreateShareOperation.class.getSimpleName(); + + // String to build the link with the token of a share: server address + "/public.php?service=files&t=" + token + private final String SHARING_LINK_TOKEN = "/public.php?service=files&t="; protected FileDataStorageManager mStorageManager; @@ -83,39 +88,31 @@ 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()) { - 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()); - + // Update the link, build it with the token: server address + "/public.php?service=files&t=" + token + share.setShareLink(client.getBaseUri() + SHARING_LINK_TOKEN + share.getToken()); + Log_OC.d(TAG, "Build Share link= " + share.getShareLink()); + updateData(share); + } else { + 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); + updateData(share); + } } } } - - return result; } @@ -123,5 +120,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()); + + } + } }