Filter only '/' character in user input when version of server is 8.1 or later
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / dialog / ShareLinkToDialog.java
index f4af7e1..fc88e5d 100644 (file)
@@ -1,5 +1,8 @@
-/* ownCloud Android client application
- *   Copyright (C) 2012-2014 ownCloud Inc.
+/**
+ *   ownCloud Android client application
+ *
+ *   @author David A. Velasco
+ *   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,
@@ -42,16 +45,14 @@ import android.widget.TextView;
 import com.actionbarsherlock.app.SherlockDialogFragment;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.files.FileOperationsHelper;
+import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.ui.activity.ComponentsGetter;
 import com.owncloud.android.ui.activity.CopyToClipboardActivity;
 import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.utils.Log_OC;
 
 /**
  * Dialog showing a list activities able to resolve a given Intent, 
  * filtering out the activities matching give package names.
- * 
- * @author David A. Velasco
  */
 public class ShareLinkToDialog  extends SherlockDialogFragment {
     
@@ -111,48 +112,47 @@ public class ShareLinkToDialog  extends SherlockDialogFragment {
         Collections.sort(activities, new ResolveInfo.DisplayNameComparator(pm)); 
         mAdapter = new ActivityAdapter(getSherlockActivity(), pm, activities);
         
-       
-        
-        if (sendAction) {
+        return createSelector(sendAction);
         
-            return new AlertDialog.Builder(getSherlockActivity())
-                       .setTitle(R.string.activity_chooser_send_file_title)
-                       .setAdapter(mAdapter, new DialogInterface.OnClickListener() {
-                               @Override
-                               public void onClick(DialogInterface dialog, int which) {
-                                   // Add the information of the chosen activity to the intent to send 
-                                   ResolveInfo chosen = mAdapter.getItem(which);
-                                   ActivityInfo actInfo = chosen.activityInfo;
-                                   ComponentName name=new ComponentName(actInfo.applicationInfo.packageName, actInfo.name);
-                                   mIntent.setComponent(name);                               
-                                   
-                                   // Send the file
-                                   ((FileActivity)getSherlockActivity()).startActivity(mIntent);
+    }
 
-                               }
-                           })
-                       .create();
+    private AlertDialog createSelector(final boolean sendAction) {
+    
+        int titleId;
+        if (sendAction) {
+            titleId = R.string.activity_chooser_send_file_title;
         } else {
-            return new AlertDialog.Builder(getSherlockActivity())
-                       .setTitle(R.string.activity_chooser_title)
-                       .setAdapter(mAdapter, new DialogInterface.OnClickListener() {
-                               @Override
-                               public void onClick(DialogInterface dialog, int which) {
-                                   // Add the information of the chosen activity to the intent to send 
-                                   ResolveInfo chosen = mAdapter.getItem(which);
-                                   ActivityInfo actInfo = chosen.activityInfo;
-                                   ComponentName name=new ComponentName(actInfo.applicationInfo.packageName, actInfo.name);
-                                   mIntent.setComponent(name);                               
-                            
-                                   // Create a new share resource
-                                   FileOperationsHelper foh = new FileOperationsHelper();
-                                   foh.shareFileWithLinkToApp(mFile, mIntent, (FileActivity)getSherlockActivity()); 
-                               }
-                           })
-                       .create();
+            titleId = R.string.activity_chooser_title;
         }
-    }
+        
+        return new AlertDialog.Builder(getSherlockActivity())
+                    .setTitle(titleId)
+                    .setAdapter(mAdapter, new DialogInterface.OnClickListener() {
+                        @Override
+                        public void onClick(DialogInterface dialog, int which) {
+                            // Add the information of the chosen activity to the intent to send 
+                            ResolveInfo chosen = mAdapter.getItem(which);
+                            ActivityInfo actInfo = chosen.activityInfo;
+                            ComponentName name=new ComponentName(
+                                    actInfo.applicationInfo.packageName, 
+                                    actInfo.name);
+                            mIntent.setComponent(name);                               
 
+                            if (sendAction) {
+                                dialog.dismiss();    // explicitly added for Android 2.x devices
+
+                                // Send the file
+                                ((FileActivity)getSherlockActivity()).startActivity(mIntent);
+
+                            } else {
+                                // Create a new share resource
+                                ((ComponentsGetter)getSherlockActivity()).getFileOperationsHelper()
+                                    .shareFileWithLinkToApp(mFile, "", mIntent);
+                            }
+                        }
+        })
+        .create();
+    }
     
     class ActivityAdapter extends ArrayAdapter<ResolveInfo> {