X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/0b7c37671fe97fafaa177cbea22a1d169d52deb8..33a9d1f44728895239d79ed3b74df29c2827bdda:/src/com/owncloud/android/operations/CreateShareOperation.java diff --git a/src/com/owncloud/android/operations/CreateShareOperation.java b/src/com/owncloud/android/operations/CreateShareOperation.java index fc44f530..e65f2c36 100644 --- a/src/com/owncloud/android/operations/CreateShareOperation.java +++ b/src/com/owncloud/android/operations/CreateShareOperation.java @@ -1,5 +1,8 @@ -/* ownCloud Android client application - * Copyright (C) 2014 ownCloud Inc. +/** + * ownCloud Android client application + * + * @author masensio + * Copyright (C) 2015 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -19,11 +22,9 @@ package com.owncloud.android.operations; /** * Creates a new share from a given file - * - * @author masensio - * */ + import android.content.Context; import android.content.Intent; @@ -31,24 +32,22 @@ import com.owncloud.android.R; 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.files.FileUtils; +import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation; import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation; +import com.owncloud.android.lib.resources.shares.OCShare; 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; public class CreateShareOperation extends SyncOperation { private static final String TAG = CreateShareOperation.class.getSimpleName(); - protected FileDataStorageManager mStorageManager; - private Context mContext; private String mPath; private ShareType mShareType; private String mShareWith; @@ -56,16 +55,19 @@ public class CreateShareOperation extends SyncOperation { private String mPassword; private int mPermissions; private Intent mSendIntent; + private String mFileName; /** * Constructor - * @param context The context that the share is coming from. * @param path Full path of the file/folder being shared. Mandatory argument * @param shareType 0 = user, 1 = group, 3 = Public link. Mandatory argument - * @param shareWith User/group ID with who the file should be shared. This is mandatory for shareType of 0 or 1 + * @param shareWith User/group ID with who the file should be shared. + * This is mandatory for shareType of 0 or 1 * @param publicUpload If false (default) public cannot upload to a public shared folder. - * If true public can upload to a shared folder. Only available for public link shares - * @param password Password to protect a public link share. Only available for public link shares + * If true public can upload to a shared folder. + * Only available for public link shares + * @param password Password to protect a public link share. + * Only available for public link shares * @param permissions 1 - Read only - Default for public shares * 2 - Update * 4 - Create @@ -75,31 +77,34 @@ public class CreateShareOperation extends SyncOperation { * For user or group shares. * To obtain combinations, add the desired values together. * For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27. + * @param sendIntent Optional Intent with the information of an app where the link to the new share (if public) + * should be posted later. */ - public CreateShareOperation(Context context, String path, ShareType shareType, String shareWith, boolean publicUpload, - String password, int permissions, Intent sendIntent) { + public CreateShareOperation(String path, ShareType shareType, String shareWith, + boolean publicUpload, String password, int permissions, Intent sendIntent) { - mContext = context; mPath = path; mShareType = shareType; - mShareWith = shareWith; + mShareWith = shareWith != null ? shareWith : ""; mPublicUpload = publicUpload; mPassword = password; mPermissions = permissions; mSendIntent = sendIntent; + mFileName = null; } @Override protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperation operation = null; - // Check if the share link already exists - operation = new GetRemoteSharesForFileOperation(mPath, false, false); - RemoteOperationResult result = ((GetRemoteSharesForFileOperation)operation).execute(client); + RemoteOperation operation = new GetRemoteSharesForFileOperation(mPath, false, false); + RemoteOperationResult result = operation.execute(client); if (!result.isSuccess() || result.getData().size() <= 0) { - operation = new CreateRemoteShareOperation(mPath, mShareType, mShareWith, mPublicUpload, mPassword, mPermissions); - result = ((CreateRemoteShareOperation)operation).execute(client); + operation = new CreateRemoteShareOperation( + mPath, mShareType, mShareWith, + mPublicUpload, mPassword, mPermissions + ); + result = operation.execute(client); } if (result.isSuccess()) { @@ -112,11 +117,55 @@ public class CreateShareOperation extends SyncOperation { return result; } - + public String getPath() { + return mPath; + } + + public ShareType getShareType() { + return mShareType; + } + + public String getShareWith() { + return mShareWith; + } + + public boolean getPublicUpload() { + return mPublicUpload; + } + + public String getPassword() { + return mPassword; + } + + public int getPermissions() { + return mPermissions; + } + public Intent getSendIntent() { return mSendIntent; } - + + public Intent getSendIntentWithSubject(Context context) { + if (context != null && mSendIntent != null && mSendIntent.getStringExtra(Intent.EXTRA_SUBJECT) != null) { + if (getClient() == null || getClient().getCredentials().getUsername() == null) { + mSendIntent.putExtra( + Intent.EXTRA_SUBJECT, + context.getString(R.string.subject_shared_with_you, mFileName) + ); + } else { + mSendIntent.putExtra( + Intent.EXTRA_SUBJECT, + context.getString( + R.string.subject_user_shared_with_you, + getClient().getCredentials().getUsername(), + mFileName + ) + ); + } + } + return mSendIntent; + } + private void updateData(OCShare share) { // Update DB with the response share.setPath(mPath); @@ -133,14 +182,9 @@ public class CreateShareOperation extends SyncOperation { OCFile file = getStorageManager().getFileByPath(mPath); if (file!=null) { mSendIntent.putExtra(Intent.EXTRA_TEXT, share.getShareLink()); - mSendIntent.putExtra(Intent.EXTRA_SUBJECT, String.format(mContext.getString(R.string.subject_token), - getClient().getCredentials().getUsername(), mContext.getString(R.string.shared_subject_header), - file.getFileName(), mContext.getString(R.string.with_you_subject_header))); file.setPublicLink(share.getShareLink()); - file.setShareByLink(true); + file.setShareViaLink(true); getStorageManager().saveFile(file); - Log_OC.d(TAG, "Public Link = " + file.getPublicLink()); - } }