From: masensio Date: Thu, 5 Mar 2015 16:54:03 +0000 (+0100) Subject: Create password dialog: SharePasswordDialog.java X-Git-Tag: oc-android-1.7.1_signed^2~27^2~10 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/b08e9e35e6817188bfa802bb3b8397bbb98b7548?ds=inline;hp=-c Create password dialog: SharePasswordDialog.java --- b08e9e35e6817188bfa802bb3b8397bbb98b7548 diff --git a/res/values/strings.xml b/res/values/strings.xml index 1ad9d8d3..fac026e1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -275,6 +275,8 @@ An error occurred while trying to share this file or folder Unable to unshare. Please check whether the file exists An error occurred while trying to unshare this file or folder + Enter a password + Password is empty Send diff --git a/src/com/owncloud/android/operations/CreateShareOperation.java b/src/com/owncloud/android/operations/CreateShareOperation.java index 6d9a253c..e1bc0abb 100644 --- a/src/com/owncloud/android/operations/CreateShareOperation.java +++ b/src/com/owncloud/android/operations/CreateShareOperation.java @@ -98,7 +98,8 @@ public class CreateShareOperation extends SyncOperation { 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); } diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index baf163a2..2c30ae04 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -525,7 +525,8 @@ public class OperationsService extends Service { String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); Intent sendIntent = operationIntent.getParcelableExtra(EXTRA_SEND_INTENT); if (remotePath.length() > 0) { - operation = new CreateShareOperation(OperationsService.this, remotePath, ShareType.PUBLIC_LINK, + operation = new CreateShareOperation(OperationsService.this, remotePath, + ShareType.PUBLIC_LINK, "", false, "", 1, sendIntent); } diff --git a/src/com/owncloud/android/ui/activity/FileActivity.java b/src/com/owncloud/android/ui/activity/FileActivity.java index 97c5606e..3591d636 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -487,10 +487,15 @@ public class FileActivity extends SherlockFragmentActivity Intent sendIntent = operation.getSendIntent(); startActivity(sendIntent); - } else { - Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), - Toast.LENGTH_LONG); - t.show(); + } else { + // TODO Detect Failure (403) --> needs Password + if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { + + } else { + Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast.LENGTH_LONG); + t.show(); + } } } diff --git a/src/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java b/src/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java new file mode 100644 index 00000000..73cc75ce --- /dev/null +++ b/src/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java @@ -0,0 +1,104 @@ +/** + * 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 . + * + */ +package com.owncloud.android.ui.dialog; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.DialogInterface; +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; + +/** + * 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 { + + public static final String PASSWORD_FRAGMENT = "PASSWORD_FRAGMENT"; + + /** + * Public factory method to create new SharePasswordDialogFragment instances. + * + * @param file File to share + * @return Dialog ready to show. + */ + public static SharePasswordDialogFragment newInstance(OCFile file) { + SharePasswordDialogFragment frag = new SharePasswordDialogFragment(); + Bundle args = new Bundle(); + frag.setArguments(args); + return frag; + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // 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) { + 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; + } + + // TODO + // Share the file + + } + } +}