From: David A. Velasco Date: Wed, 21 Oct 2015 08:31:30 +0000 (+0200) Subject: Get rid of dependency on Context in CreateShareOperation X-Git-Tag: oc-android-1.9^2~30^2~31 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/33a9d1f44728895239d79ed3b74df29c2827bdda Get rid of dependency on Context in CreateShareOperation --- diff --git a/res/values/strings.xml b/res/values/strings.xml index e6e2303e..591527d6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -348,8 +348,8 @@ shared with you - %1$s shared \"%2$s\" with you - \"%1$s\" has been shared with you + %1$s shared \"%2$s\" with you + \"%1$s\" has been shared with you Refresh connection Server address 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()); - } } diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index 8433db39..b6326446 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -555,9 +555,14 @@ public class OperationsService extends Service { String password = operationIntent.getStringExtra(EXTRA_PASSWORD_SHARE); Intent sendIntent = operationIntent.getParcelableExtra(EXTRA_SEND_INTENT); if (remotePath.length() > 0) { - operation = new CreateShareOperation(OperationsService.this, remotePath, + operation = new CreateShareOperation( + remotePath, ShareType.PUBLIC_LINK, - "", false, password, 1, sendIntent); + null, + false, + password, + 1, + sendIntent); } } else if (action.equals(ACTION_UNSHARE)) { // Unshare file diff --git a/src/com/owncloud/android/ui/activity/FileActivity.java b/src/com/owncloud/android/ui/activity/FileActivity.java index 92452395..0878682f 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -762,7 +762,7 @@ public class FileActivity extends AppCompatActivity mTryShareAgain = false; updateFileFromDB(); - Intent sendIntent = operation.getSendIntent(); + Intent sendIntent = operation.getSendIntentWithSubject(this); startActivity(sendIntent); } else { // Detect Failure (403) --> needs Password