Merge pull request #1048 from owncloud/shareWithYou_icon_in_fileList
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / dialog / SharePasswordDialogFragment.java
index 73cc75c..d2d29fe 100644 (file)
@@ -20,9 +20,10 @@ 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.support.v4.app.DialogFragment;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.WindowManager;
@@ -30,9 +31,9 @@ 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.
@@ -40,26 +41,38 @@ import com.owncloud.android.datamodel.OCFile;
  * Triggers the share when the password is introduced.
  */
 
-public class SharePasswordDialogFragment extends SherlockDialogFragment
+public class SharePasswordDialogFragment extends DialogFragment
         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);
@@ -84,6 +97,9 @@ public class SharePasswordDialogFragment extends SherlockDialogFragment
     @Override
     public void onClick(DialogInterface dialog, int which) {
         if (which == AlertDialog.BUTTON_POSITIVE) {
+            // Enable the flag "Share again"
+            ((FileActivity) getActivity()).setTryShareAgain(true);
+
             String password =
                     ((TextView)(getDialog().findViewById(R.id.share_password)))
                         .getText().toString();
@@ -96,9 +112,13 @@ public class SharePasswordDialogFragment extends SherlockDialogFragment
                 return;
             }
 
-            // TODO
             // Share the file
+            ((FileActivity)getActivity()).getFileOperationsHelper()
+                                    .shareFileWithLinkToApp(mFile, password, mSendIntent);
 
+        } else {
+            // Disable the flag "Share again"
+            ((FileActivity) getActivity()).setTryShareAgain(false);
         }
     }
 }