* Creates a new share from a given file
*/
+
import android.content.Context;
import android.content.Intent;
protected FileDataStorageManager mStorageManager;
- private Context mContext;
private String mPath;
private ShareType mShareType;
private String mShareWith;
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.
* 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()) {
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);
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());
-
}
}