Эх сурвалжийг харах

Create password dialog: SharePasswordDialog.java

masensio 10 жил өмнө
parent
commit
b08e9e35e6

+ 2 - 0
res/values/strings.xml

@@ -275,6 +275,8 @@
 	<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">Password is empty</string>
 
 	<string name="activity_chooser_send_file_title">Send</string>
 

+ 2 - 1
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);
         }
         

+ 2 - 1
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);
                     }
                     

+ 9 - 4
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();
+            }
         } 
     }
     

+ 104 - 0
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 <http://www.gnu.org/licenses/>.
+ *
+ */
+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
+
+        }
+    }
+}