diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index 465881148f..b2f74f2f5a 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -119,7 +119,7 @@ public class FileOperationsHelper { } - public void shareFileWithLinkToApp(OCFile file, Intent sendIntent) { + public void shareFileWithLinkToApp(OCFile file, String password, Intent sendIntent) { if (file != null) { mFileActivity.showLoadingDialog(); @@ -128,6 +128,7 @@ public class FileOperationsHelper { service.setAction(OperationsService.ACTION_CREATE_SHARE); service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); + service.putExtra(OperationsService.EXTRA_PASSWORD_SHARE, password); service.putExtra(OperationsService.EXTRA_SEND_INTENT, sendIntent); mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service); diff --git a/src/com/owncloud/android/operations/CreateShareOperation.java b/src/com/owncloud/android/operations/CreateShareOperation.java index eb7ae7a9e6..70d6bf7b26 100644 --- a/src/com/owncloud/android/operations/CreateShareOperation.java +++ b/src/com/owncloud/android/operations/CreateShareOperation.java @@ -44,7 +44,6 @@ import com.owncloud.android.operations.common.SyncOperation; public class CreateShareOperation extends SyncOperation { private static final String TAG = CreateShareOperation.class.getSimpleName(); - protected FileDataStorageManager mStorageManager; @@ -76,8 +75,9 @@ public class CreateShareOperation extends SyncOperation { * To obtain combinations, add the desired values together. * For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27. */ - public CreateShareOperation(Context context, String path, ShareType shareType, String shareWith, boolean publicUpload, - String password, int permissions, Intent sendIntent) { + public CreateShareOperation(Context context, String path, ShareType shareType, String shareWith, + boolean publicUpload, String password, int permissions, + Intent sendIntent) { mContext = context; mPath = path; @@ -113,7 +113,30 @@ 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; } diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index 525fa41877..6a32af0627 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -85,6 +85,7 @@ public class OperationsService extends Service { public static final String EXTRA_RESULT = "RESULT"; public static final String EXTRA_NEW_PARENT_PATH = "NEW_PARENT_PATH"; public static final String EXTRA_FILE = "FILE"; + public static final String EXTRA_PASSWORD_SHARE = "PASSWORD_SHARE"; public static final String EXTRA_COOKIE = "COOKIE"; @@ -525,11 +526,12 @@ public class OperationsService extends Service { String action = operationIntent.getAction(); if (action.equals(ACTION_CREATE_SHARE)) { // Create Share String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); + String password = operationIntent.getStringExtra(EXTRA_PASSWORD_SHARE); Intent sendIntent = operationIntent.getParcelableExtra(EXTRA_SEND_INTENT); if (remotePath.length() > 0) { operation = new CreateShareOperation(OperationsService.this, remotePath, ShareType.PUBLIC_LINK, - "", false, "", 1, sendIntent); + "", 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 4fdadc1780..8eb20e4d0b 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -453,7 +453,8 @@ public class FileActivity extends SherlockFragmentActivity if (result.getCode() == ResultCode.UNAUTHORIZED) { dismissLoadingDialog(); - Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, + operation, getResources()), Toast.LENGTH_LONG); t.show(); } @@ -481,7 +482,8 @@ public class FileActivity extends SherlockFragmentActivity } - private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) { + private void onCreateShareOperationFinish(CreateShareOperation operation, + RemoteOperationResult result) { dismissLoadingDialog(); if (result.isSuccess()) { updateFileFromDB(); @@ -490,13 +492,15 @@ public class FileActivity extends SherlockFragmentActivity startActivity(sendIntent); } else { - // TODO Detect Failure (403) --> needs Password + // Detect Failure (403) --> needs Password if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { SharePasswordDialogFragment dialog = - SharePasswordDialogFragment.newInstance(getFile()); + SharePasswordDialogFragment.newInstance( new OCFile(operation.getPath()), + operation.getSendIntent()); dialog.show(getSupportFragmentManager(), DIALOG_SHARE_PASSWORD); } else { - Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast t = Toast.makeText(this, + ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), Toast.LENGTH_LONG); t.show(); } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 16c09eddfb..9c6f6dc57a 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -23,13 +23,10 @@ package com.owncloud.android.ui.activity; import java.io.File; -import java.io.IOException; import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AuthenticatorException; -import android.accounts.OperationCanceledException; -import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.AlertDialog; import android.app.Dialog; diff --git a/src/com/owncloud/android/ui/dialog/ShareLinkToDialog.java b/src/com/owncloud/android/ui/dialog/ShareLinkToDialog.java index e05f2165ca..fc88e5d180 100644 --- a/src/com/owncloud/android/ui/dialog/ShareLinkToDialog.java +++ b/src/com/owncloud/android/ui/dialog/ShareLinkToDialog.java @@ -147,7 +147,7 @@ public class ShareLinkToDialog extends SherlockDialogFragment { } else { // Create a new share resource ((ComponentsGetter)getSherlockActivity()).getFileOperationsHelper() - .shareFileWithLinkToApp(mFile, mIntent); + .shareFileWithLinkToApp(mFile, "", mIntent); } } }) diff --git a/src/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java b/src/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java index 73cc75cec3..a7e71b5bce 100644 --- a/src/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java +++ b/src/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java @@ -20,8 +20,8 @@ package com.owncloud.android.ui.dialog; import android.app.AlertDialog; import android.app.Dialog; -import android.app.DialogFragment; import android.content.DialogInterface; +import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -33,6 +33,7 @@ import android.widget.Toast; import com.actionbarsherlock.app.SherlockDialogFragment; import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.ui.activity.FileActivity; /** * Dialog to input the password for sharing a file/folder. @@ -43,23 +44,35 @@ import com.owncloud.android.datamodel.OCFile; public class SharePasswordDialogFragment extends SherlockDialogFragment implements DialogInterface.OnClickListener { - public static final String PASSWORD_FRAGMENT = "PASSWORD_FRAGMENT"; + private static final String ARG_FILE = "FILE"; + private static final String ARG_SEND_INTENT = "SEND_INTENT"; + + public static final String PASSWORD_FRAGMENT = "PASSWORD_FRAGMENT"; + + private OCFile mFile; + private Intent mSendIntent; /** * Public factory method to create new SharePasswordDialogFragment instances. * - * @param file File to share - * @return Dialog ready to show. + * @param file + * @param sendIntent + * @return Dialog ready to show. */ - public static SharePasswordDialogFragment newInstance(OCFile file) { + public static SharePasswordDialogFragment newInstance(OCFile file, Intent sendIntent) { SharePasswordDialogFragment frag = new SharePasswordDialogFragment(); Bundle args = new Bundle(); + args.putParcelable(ARG_FILE, file); + args.putParcelable(ARG_SEND_INTENT, sendIntent); frag.setArguments(args); return frag; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { + mFile = getArguments().getParcelable(ARG_FILE); + mSendIntent = getArguments().getParcelable(ARG_SEND_INTENT); + // Inflate the layout for the dialog LayoutInflater inflater = getActivity().getLayoutInflater(); View v = inflater.inflate(R.layout.password_dialog, null); @@ -96,8 +109,9 @@ public class SharePasswordDialogFragment extends SherlockDialogFragment return; } - // TODO // Share the file + ((FileActivity)getSherlockActivity()).getFileOperationsHelper() + .shareFileWithLinkToApp(mFile, password, mSendIntent); } }