--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ownCloud Android client application
+
+ 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,
+ as published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <EditText
+ android:id="@+id/share_password"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:ems="10"
+ android:inputType="textPassword">
+ </EditText>
+
+</LinearLayout>
\ No newline at end of file
<string name="share_link_file_error">An error occurred while trying to share this file or folder</string>
<string name="unshare_link_file_no_exist">Unable to unshare. Please check whether the file exists</string>
<string name="unshare_link_file_error">An error occurred while trying to unshare this file or folder</string>
+ <string name="share_link_password_title">Enter a password</string>
+ <string name="share_link_empty_password">You must enter a password</string>
<string name="activity_chooser_send_file_title">Send</string>
}
- public void shareFileWithLinkToApp(OCFile file, Intent sendIntent) {
+ public void shareFileWithLinkToApp(OCFile file, String password, Intent sendIntent) {
if (file != null) {
mFileActivity.showLoadingDialog();
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);
public class CreateShareOperation extends SyncOperation {
private static final String TAG = CreateShareOperation.class.getSimpleName();
-
protected FileDataStorageManager mStorageManager;
* 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;
RemoteOperationResult result = ((GetRemoteSharesForFileOperation)operation).execute(client);
if (!result.isSuccess() || result.getData().size() <= 0) {
- operation = new CreateRemoteShareOperation(mPath, mShareType, mShareWith, mPublicUpload, mPassword, mPermissions);
+ operation = new CreateRemoteShareOperation(mPath, mShareType, mShareWith, mPublicUpload,
+ mPassword, mPermissions);
result = ((CreateRemoteShareOperation)operation).execute(client);
}
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 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";
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);
+ operation = new CreateShareOperation(OperationsService.this, remotePath,
+ ShareType.PUBLIC_LINK,
+ "", false, password, 1, sendIntent);
}
} else if (action.equals(ACTION_UNSHARE)) { // Unshare file
import com.owncloud.android.operations.UnshareLinkOperation;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
+import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
import com.owncloud.android.ui.dialog.LoadingDialog;
+import com.owncloud.android.ui.dialog.SharePasswordDialogFragment;
import com.owncloud.android.utils.ErrorMessageAdapter;
public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT";
public static final String EXTRA_WAITING_TO_PREVIEW = "com.owncloud.android.ui.activity.WAITING_TO_PREVIEW";
- public static final String EXTRA_FROM_NOTIFICATION= "com.owncloud.android.ui.activity.FROM_NOTIFICATION";
+ public static final String EXTRA_FROM_NOTIFICATION = "com.owncloud.android.ui.activity.FROM_NOTIFICATION";
public static final String TAG = FileActivity.class.getSimpleName();
private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";
private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";
+ private static final String DIALOG_SHARE_PASSWORD = "DIALOG_SHARE_PASSWORD";
+ private static final String KEY_TRY_SHARE_AGAIN = "TRY_SHARE_AGAIN";
protected static final long DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS = 200;
protected FileDownloaderBinder mDownloaderBinder = null;
protected FileUploaderBinder mUploaderBinder = null;
private ServiceConnection mDownloadServiceConnection, mUploadServiceConnection = null;
+
+ private boolean mTryShareAgain = false;
/**
mFileOperationsHelper.setOpIdWaitingFor(
savedInstanceState.getLong(KEY_WAITING_FOR_OP_ID, Long.MAX_VALUE)
);
+ mTryShareAgain = savedInstanceState.getBoolean(KEY_TRY_SHARE_AGAIN);
} else {
account = getIntent().getParcelableExtra(FileActivity.EXTRA_ACCOUNT);
mFile = getIntent().getParcelableExtra(FileActivity.EXTRA_FILE);
outState.putParcelable(FileActivity.EXTRA_ACCOUNT, mAccount);
outState.putBoolean(FileActivity.EXTRA_FROM_NOTIFICATION, mFromNotification);
outState.putLong(KEY_WAITING_FOR_OP_ID, mFileOperationsHelper.getOpIdWaitingFor());
+ outState.putBoolean(KEY_TRY_SHARE_AGAIN, mTryShareAgain);
}
protected boolean isRedirectingToSetupAccount() {
return mRedirectingToSetupAccount;
}
-
+
+ public boolean isTryShareAgain(){
+ return mTryShareAgain;
+ }
+
+ public void setTryShareAgain(boolean tryShareAgain) {
+ mTryShareAgain = tryShareAgain;
+ }
public OperationsServiceBinder getOperationsServiceBinder() {
return mOperationsServiceBinder;
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();
}
}
- private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) {
+ private void onCreateShareOperationFinish(CreateShareOperation operation,
+ RemoteOperationResult result) {
dismissLoadingDialog();
if (result.isSuccess()) {
+ mTryShareAgain = false;
updateFileFromDB();
Intent sendIntent = operation.getSendIntent();
startActivity(sendIntent);
-
- } else {
- Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
- Toast.LENGTH_LONG);
- t.show();
+ } else {
+ // Detect Failure (403) --> needs Password
+ if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
+ if (!isTryShareAgain()) {
+ SharePasswordDialogFragment dialog =
+ 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.LENGTH_LONG);
+ t.show();
+ mTryShareAgain = false;
+ }
+ } else {
+ Toast t = Toast.makeText(this,
+ ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
+ t.show();
+ }
}
}
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;
} else {
// Create a new share resource
((ComponentsGetter)getSherlockActivity()).getFileOperationsHelper()
- .shareFileWithLinkToApp(mFile, mIntent);
+ .shareFileWithLinkToApp(mFile, "", mIntent);
}
}
})
--- /dev/null
+/**
+ * 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,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package com.owncloud.android.ui.dialog;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.EditText;
+import android.widget.TextView;
+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.
+ *
+ * Triggers the share when the password is introduced.
+ */
+
+public class SharePasswordDialogFragment extends SherlockDialogFragment
+ implements DialogInterface.OnClickListener {
+
+ 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
+ * @param sendIntent
+ * @return Dialog ready to show.
+ */
+ 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);
+
+ // Setup layout
+ EditText inputText = ((EditText)v.findViewById(R.id.share_password));
+ inputText.setText("");
+ inputText.requestFocus();
+
+ // Build the dialog
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setView(v)
+ .setPositiveButton(R.string.common_ok, this)
+ .setNegativeButton(R.string.common_cancel, this)
+ .setTitle(R.string.share_link_password_title);
+ Dialog d = builder.create();
+ d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+ return d;
+ }
+
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (which == AlertDialog.BUTTON_POSITIVE) {
+ // Enable the flag "Share again"
+ ((FileActivity) getSherlockActivity()).setTryShareAgain(true);
+
+ String password =
+ ((TextView)(getDialog().findViewById(R.id.share_password)))
+ .getText().toString();
+
+ if (password.length() <= 0) {
+ Toast.makeText(
+ getActivity(),
+ R.string.share_link_empty_password,
+ Toast.LENGTH_LONG).show();
+ return;
+ }
+
+ // Share the file
+ ((FileActivity)getSherlockActivity()).getFileOperationsHelper()
+ .shareFileWithLinkToApp(mFile, password, mSendIntent);
+
+ } else {
+ // Disable the flag "Share again"
+ ((FileActivity) getSherlockActivity()).setTryShareAgain(false);
+ }
+ }
+}