mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:39:25 +03:00
Process share with password
This commit is contained in:
parent
82fa95fe43
commit
6f1fe5ad6d
7 changed files with 62 additions and 21 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ public class CreateShareOperation extends SyncOperation {
|
|||
|
||||
private static final String TAG = CreateShareOperation.class.getSimpleName();
|
||||
|
||||
|
||||
protected FileDataStorageManager mStorageManager;
|
||||
|
||||
private Context mContext;
|
||||
|
@ -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,6 +113,29 @@ 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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -147,7 +147,7 @@ public class ShareLinkToDialog extends SherlockDialogFragment {
|
|||
} else {
|
||||
// Create a new share resource
|
||||
((ComponentsGetter)getSherlockActivity()).getFileOperationsHelper()
|
||||
.shareFileWithLinkToApp(mFile, mIntent);
|
||||
.shareFileWithLinkToApp(mFile, "", mIntent);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -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 {
|
||||
|
||||
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
|
||||
* @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);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue