X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/e81bff7679a9b84cd920e940396578a181a75d66..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 ade575ce..e65f2c36 100644 --- a/src/com/owncloud/android/operations/CreateShareOperation.java +++ b/src/com/owncloud/android/operations/CreateShareOperation.java @@ -24,6 +24,7 @@ package com.owncloud.android.operations; * Creates a new share from a given file */ + import android.content.Context; import android.content.Intent; @@ -47,7 +48,6 @@ public class CreateShareOperation extends SyncOperation { protected FileDataStorageManager mStorageManager; - private Context mContext; private String mPath; private ShareType mShareType; private String mShareWith; @@ -55,10 +55,10 @@ 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. @@ -77,34 +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()) { @@ -144,7 +144,28 @@ public class CreateShareOperation extends SyncOperation { 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); @@ -161,21 +182,9 @@ public class CreateShareOperation extends SyncOperation { OCFile file = getStorageManager().getFileByPath(mPath); if (file!=null) { mSendIntent.putExtra(Intent.EXTRA_TEXT, share.getShareLink()); - if (getClient().getCredentials().getUsername() == null) { - //in saml is null - mSendIntent.putExtra(Intent.EXTRA_SUBJECT, - String.format(mContext.getString(R.string.saml_subject_token), - file.getFileName())); - } else { - mSendIntent.putExtra(Intent.EXTRA_SUBJECT, - String.format(mContext.getString(R.string.subject_token), - getClient().getCredentials().getUsername(), file.getFileName())); - } file.setPublicLink(share.getShareLink()); file.setShareViaLink(true); getStorageManager().saveFile(file); - Log_OC.d(TAG, "Public Link = " + file.getPublicLink()); - } }