Merge pull request #442 from owncloud/share_link__reuse_link_shared_in_server

Reuse public link already existing in server when user tries to reshare a file.
This commit is contained in:
David A. Velasco 2014-03-20 17:43:07 +01:00
commit 4d3661299b
2 changed files with 41 additions and 29 deletions

@ -1 +1 @@
Subproject commit 30acd4875dda3fd0bec83daaad522f3d5a02ead6
Subproject commit ae2f5b48b86015642998bf515a978db380c88787

View file

@ -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,7 @@ 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());
}
}
}