Updated handling of enforced password for public shares depending on server capabilities
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / dialog / SharePasswordDialogFragment.java
index 73cc75c..1b7def2 100644 (file)
  */
 package com.owncloud.android.ui.dialog;
 
-import android.app.AlertDialog;
+import android.support.v7.app.AlertDialog;
 import android.app.Dialog;
-import android.app.DialogFragment;
 import android.content.DialogInterface;
 import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.WindowManager;
@@ -30,9 +30,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 +40,39 @@ 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_CREATE_SHARE = "CREATE_SHARE";
+
+    public static final String PASSWORD_FRAGMENT = "PASSWORD_FRAGMENT";
+
+    private OCFile mFile;
+    private boolean mCreateShare;
 
     /**
      * Public factory method to create new SharePasswordDialogFragment instances.
      *
-     * @param file            File to share
-     * @return                Dialog ready to show.
+     * @param   file            OCFile bound to the public share that which password will be set or updated
+     * @param   createShare     When 'true', the public share will be created; when 'false', will be assumed
+     *                          that the public share already exists, and its state will be directly updated.
+     * @return                  Dialog ready to show.
      */
-    public static SharePasswordDialogFragment newInstance(OCFile file) {
+    public static SharePasswordDialogFragment newInstance(OCFile file, boolean createShare) {
         SharePasswordDialogFragment frag = new SharePasswordDialogFragment();
         Bundle args = new Bundle();
+        args.putParcelable(ARG_FILE, file);
+        args.putBoolean(ARG_CREATE_SHARE, createShare);
         frag.setArguments(args);
         return frag;
     }
 
     @Override
     public Dialog onCreateDialog(Bundle savedInstanceState) {
+        mFile = getArguments().getParcelable(ARG_FILE);
+        mCreateShare = getArguments().getBoolean(ARG_CREATE_SHARE, false);
+
         // Inflate the layout for the dialog
         LayoutInflater inflater = getActivity().getLayoutInflater();
         View v = inflater.inflate(R.layout.password_dialog, null);
@@ -96,9 +109,16 @@ public class SharePasswordDialogFragment extends SherlockDialogFragment
                 return;
             }
 
-            // TODO
-            // Share the file
+            if (mCreateShare) {
+                // Share the file
+                ((FileActivity) getActivity()).getFileOperationsHelper().
+                        shareFileViaLink(mFile, password);
 
+            } else {
+                // updat existing link
+                ((FileActivity) getActivity()).getFileOperationsHelper().
+                        setPasswordToShareViaLink(mFile, password);
+            }
         }
     }
 }