Merge branch 'develop' into send_file_pr311_with_develop
authormasensio <masensio@solidgear.es>
Thu, 27 Feb 2014 07:40:17 +0000 (08:40 +0100)
committermasensio <masensio@solidgear.es>
Thu, 27 Feb 2014 07:40:17 +0000 (08:40 +0100)
12 files changed:
AndroidManifest.xml
res/values/setup.xml
res/values/strings.xml
src/com/owncloud/android/files/FileOperationsHelper.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/dialog/ShareLinkToDialog.java
src/com/owncloud/android/ui/fragment/FileDetailFragment.java
src/com/owncloud/android/ui/fragment/OCFileListFragment.java
src/com/owncloud/android/ui/preview/PreviewImageActivity.java
src/com/owncloud/android/ui/preview/PreviewImageFragment.java
src/com/owncloud/android/ui/preview/PreviewMediaFragment.java
src/com/owncloud/android/ui/preview/PreviewVideoActivity.java

index c92af06..8700e58 100644 (file)
@@ -51,7 +51,7 @@
         <activity
             android:name=".ui.activity.FileDisplayActivity"
             android:label="@string/app_name"
-            >
+            android:configChanges="orientation" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
         <activity android:name=".ui.activity.PreferencesNewSessionewSession" >
         </activity>
         
-        <activity      android:name=".ui.preview.PreviewImageActivity" />
+        <activity      
+            android:name=".ui.preview.PreviewImageActivity" 
+            android:configChanges="orientation" />
                        
-        <activity      android:name=".ui.preview.PreviewVideoActivity"
-                                       android:label="@string/app_name"
-                                       android:theme="@style/Theme.ownCloud.Fullscreen" >
+        <activity      
+            android:name=".ui.preview.PreviewVideoActivity"
+                       android:label="@string/app_name"
+                       android:theme="@style/Theme.ownCloud.Fullscreen" 
+                       android:configChanges="orientation">
                </activity>        
 
         <service
index 948b4d3..932612e 100644 (file)
     <string name="auth_method_oauth2">off</string>
     <string name="auth_method_saml_web_sso">off</string>
     
+    <!-- Flags to enable/disable some features -->
+    <string name = "send_files_to_other_apps">on</string>
+    
+    
     <!-- Colors -->
     <color name="login_background_color">#FFFFFF</color>
     <color name="login_logo_background_color">#FFFFFF</color>
index b59e987..60e4eca 100644 (file)
        <string name="unshare_link_file_no_exist">Unable to unshare this file or folder. It does not exist.</string>
        <string name="unshare_link_file_error">An error occurred while trying to unshare this file or folder</string>
 
+       <string name="activity_chooser_send_file_title">Send</string>
+
        <string name="copy_link">Copy link</string>     
        <string name="clipboard_text_copied">Copied to clipboard</string>
 </resources>
index 8843897..5b74dc8 100644 (file)
@@ -145,7 +145,7 @@ public class FileOperationsHelper {
         }
         return false;
     }
-
+    
     
     public void unshareFileWithLink(OCFile file, FileActivity callerActivity) {
         
@@ -166,4 +166,23 @@ public class FileOperationsHelper {
             
         }
     }
+    
+    public void sendDownloadedFile(OCFile file, FileActivity callerActivity) {
+        if (file != null) {
+            Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
+            // set MimeType
+            sendIntent.setType(file.getMimetype());
+            sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getStoragePath()));
+            sendIntent.putExtra(Intent.ACTION_SEND, true);      // Send Action
+            
+            // Show dialog, without the own app
+            String[] packagesToExclude = new String[] { callerActivity.getPackageName() };
+            DialogFragment chooserDialog = ShareLinkToDialog.newInstance(sendIntent, packagesToExclude, file);
+            chooserDialog.show(callerActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
+
+        } else {
+            Log_OC.wtf(TAG, "Trying to send a NULL OCFile");
+        }
+    }
+
 }
index 76ba0c0..6429e87 100644 (file)
@@ -34,6 +34,7 @@ import android.content.IntentFilter;
 import android.content.ServiceConnection;
 import android.content.SharedPreferences;
 import android.content.SyncRequest;
+import android.content.res.Configuration;
 import android.content.res.Resources.NotFoundException;
 import android.database.Cursor;
 import android.net.Uri;
@@ -120,6 +121,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
     private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS";
     //private static final String KEY_REFRESH_SHARES_IN_PROGRESS = "SHARES_IN_PROGRESS";
+    private static final String KEY_WAITING_TO_SEND = "WAITING_TO_SEND";
 
     public static final int DIALOG_SHORT_WAIT = 0;
     private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 1;
@@ -141,6 +143,8 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     private boolean mSyncInProgress = false;
     //private boolean mRefreshSharesInProgress = false;
 
+    private OCFile mWaitingToSend;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         Log_OC.d(TAG, "onCreate() start");
@@ -171,11 +175,13 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
             mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW);
             mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS);
             //mRefreshSharesInProgress = savedInstanceState.getBoolean(KEY_REFRESH_SHARES_IN_PROGRESS);
+            mWaitingToSend = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND);
            
         } else {
             mWaitingToPreview = null;
             mSyncInProgress = false;
             //mRefreshSharesInProgress = false;
+            mWaitingToSend = null;
         }        
 
         /// USER INTERFACE
@@ -218,6 +224,10 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
             unbindService(mUploadConnection);
     }
 
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+    }
 
     /**
      *  Called when the ownCloud {@link Account} associated to the Activity was just updated.
@@ -666,6 +676,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
         outState.putBoolean(FileDisplayActivity.KEY_SYNC_IN_PROGRESS, mSyncInProgress);
         //outState.putBoolean(FileDisplayActivity.KEY_REFRESH_SHARES_IN_PROGRESS, mRefreshSharesInProgress);
+        outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND, mWaitingToSend);
 
         Log_OC.d(TAG, "onSaveInstanceState() end");
     }
@@ -1022,6 +1033,13 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
                 refreshSecondFragment(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
             }
 
+            if (mWaitingToSend != null) {
+                mWaitingToSend = getStorageManager().getFileByPath(mWaitingToSend.getRemotePath()); // Update the file to send
+                if (mWaitingToSend.isDown() && mWaitingToSend.getStoragePath()!=null) {
+                    sendDownloadedFile();
+                }
+            }
+            
             removeStickyBroadcast(intent);
         }
 
@@ -1601,4 +1619,34 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     }
     */
 
+    /**
+     * Requests the download of the received {@link OCFile} , updates the UI
+     * to monitor the download progress and prepares the activity to send the file
+     * when the download finishes.
+     * 
+     * @param file          {@link OCFile} to download and preview.
+     */
+    @Override
+    public void startDownloadForSending(OCFile file) {
+        mWaitingToSend = file;
+        requestForDownload(mWaitingToSend);
+        boolean hasSecondFragment = (getSecondFragment()!= null);
+        updateFragmentsVisibility(hasSecondFragment);
+    }
+    
+    private void requestForDownload(OCFile file) {
+        Account account = getAccount();
+        if (!mDownloaderBinder.isDownloading(account, file)) {
+            Intent i = new Intent(this, FileDownloader.class);
+            i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
+            i.putExtra(FileDownloader.EXTRA_FILE, file);
+            startService(i);
+        }
+    }
+    
+    private void sendDownloadedFile(){
+        getFileOperationsHelper().sendDownloadedFile(mWaitingToSend, this);
+        mWaitingToSend = null;
+    }
+    
 }
index e0e76d1..f4af7e1 100644 (file)
@@ -97,33 +97,60 @@ public class ShareLinkToDialog  extends SherlockDialogFragment {
             }
         }
         
-        // add activity for copy to clipboard
-        Intent copyToClipboardIntent = new Intent(getSherlockActivity(), CopyToClipboardActivity.class);
-        List<ResolveInfo> copyToClipboard = pm.queryIntentActivities(copyToClipboardIntent, 0);
-        if (!copyToClipboard.isEmpty()) {
-            activities.add(copyToClipboard.get(0));
+        boolean sendAction = mIntent.getBooleanExtra(Intent.ACTION_SEND, false);
+        
+        if (!sendAction) {
+            // add activity for copy to clipboard
+            Intent copyToClipboardIntent = new Intent(getSherlockActivity(), CopyToClipboardActivity.class);
+            List<ResolveInfo> copyToClipboard = pm.queryIntentActivities(copyToClipboardIntent, 0);
+            if (!copyToClipboard.isEmpty()) {
+                activities.add(copyToClipboard.get(0));
+            }
         }
         
         Collections.sort(activities, new ResolveInfo.DisplayNameComparator(pm)); 
         mAdapter = new ActivityAdapter(getSherlockActivity(), pm, activities);
         
-        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();
+       
+        
+        if (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();
+        } 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();
+        }
     }
 
     
index af29cff..a567c43 100644 (file)
@@ -252,6 +252,17 @@ public class FileDetailFragment extends FileFragment implements
             item.setVisible(false);
             item.setEnabled(false);
         }
+        
+        // Send file
+        item = menu.findItem(R.id.action_send_file);
+        boolean sendEnabled = getString(R.string.send_files_to_other_apps).equalsIgnoreCase("on");
+        if (item != null  && sendEnabled) {
+            item.setVisible(true);
+            item.setEnabled(true);
+        } else {
+            item.setVisible(false);
+            item.setEnabled(false);
+        }
     }
 
     
@@ -376,6 +387,18 @@ public class FileDetailFragment extends FileFragment implements
                 synchronizeFile();
                 return true;
             }
+            case R.id.action_send_file: {
+                FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity();
+                // Obtain the file
+                if (!getFile().isDown()) {  // Download the file                    
+                    Log_OC.d(TAG, getFile().getRemotePath() + " : File must be downloaded");
+                    activity.startDownloadForSending(getFile());
+                    
+                } else {
+                    activity.getFileOperationsHelper().sendDownloadedFile(getFile(), activity);
+                }
+                return true;
+            }
             default:
                 return false;
         }
index 87fd686..cb37007 100644 (file)
@@ -44,8 +44,6 @@ import com.owncloud.android.utils.Log_OC;
 
 import android.accounts.Account;
 import android.app.Activity;
-import android.content.Intent;
-import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
 import android.view.ContextMenu;
@@ -222,7 +220,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
             toHide.add(R.id.action_cancel_upload);
             toHide.add(R.id.action_sync_file);
             toHide.add(R.id.action_see_details);
-            toHide.add(R.id.action_share_file);
+            toHide.add(R.id.action_send_file);
             if (    mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile) ||
                     mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)           ) {
                 toDisable.add(R.id.action_rename_file);
@@ -265,6 +263,12 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
             toHide.add(R.id.action_unshare_file);
         }
 
+        // Send file
+        boolean sendEnabled = getString(R.string.send_files_to_other_apps).equalsIgnoreCase("on");
+        if (!sendEnabled) {
+            toHide.add(R.id.action_send_file);
+        }
+        
         for (int i : toHide) {
             item = menu.findItem(i);
             if (item != null) {
@@ -362,11 +366,16 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
                 return true;
             }
             case R.id.action_send_file: {
-                Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
-                // set MimeType
-                sharingIntent.setType(mTargetFile.getMimetype());
-                sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+mTargetFile.getStoragePath()));
-                startActivity(Intent.createChooser(sharingIntent, "Share via")); 
+                // Obtain the file
+                if (!mTargetFile.isDown()) {  // Download the file
+                    Log_OC.d(TAG, mTargetFile.getRemotePath() + " : File must be downloaded");
+                    mContainerActivity.startDownloadForSending(mTargetFile);
+                    
+                } else {
+                
+                    FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity();
+                    activity.getFileOperationsHelper().sendDownloadedFile(mTargetFile, activity);
+                }
                 return true;
             }
             default:
@@ -473,6 +482,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
          * @param uploading     Flag signaling if the file is now uploading.
          */
         public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading);
+
+        void startDownloadForSending(OCFile file);
         
     }
     
index ece3991..82d2476 100644 (file)
@@ -23,6 +23,7 @@ import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.ServiceConnection;
 import android.content.SharedPreferences;
+import android.content.res.Configuration;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.preference.PreferenceManager;
@@ -245,6 +246,10 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
         super.onDestroy();
     }
     
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+    }
     
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
index 1582b6a..3a374e0 100644 (file)
@@ -250,6 +250,12 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
             toHide.add(R.id.action_unshare_file);
         }
 
+        // Send file
+        boolean sendEnabled = getString(R.string.send_files_to_other_apps).equalsIgnoreCase("on");
+        if (!sendEnabled) {
+            toHide.add(R.id.action_send_file);
+        }
+        
         for (int i : toHide) {
             item = menu.findItem(i);
             if (item != null) {
@@ -311,7 +317,8 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
                 return true;
             }
             case R.id.action_send_file: {
-                shareFile();
+                FileActivity act = (FileActivity)getSherlockActivity();
+                act.getFileOperationsHelper().sendDownloadedFile(getFile(), act);
                 return true;
             }
             
@@ -320,15 +327,6 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
         }
     }
     
-    private void shareFile(){
-        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
-        // set MimeType
-        sharingIntent.setType(getFile().getMimetype());
-        sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+getFile().getStoragePath()));
-        startActivity(Intent.createChooser(sharingIntent, "Share via"));
-    }
-
-    
 
     private void seeDetails() {
         ((FileFragment.ContainerActivity)getActivity()).showDetails(getFile());        
index 83f937a..7fa399a 100644 (file)
@@ -295,6 +295,12 @@ public class PreviewMediaFragment extends FileFragment implements
             toHide.add(R.id.action_unshare_file);
         }
         
+        // Send file
+        boolean sendEnabled = getString(R.string.send_files_to_other_apps).equalsIgnoreCase("on");
+        if (!sendEnabled) {
+            toHide.add(R.id.action_send_file);
+        }
+        
         for (int i : toHide) {
             item = menu.findItem(i);
             if (item != null) {
@@ -351,6 +357,9 @@ public class PreviewMediaFragment extends FileFragment implements
                 seeDetails();
                 return true;
             }
+            case R.id.action_send_file: {
+                sendFile();
+            }
             
             default:
                 return false;
@@ -380,6 +389,12 @@ public class PreviewMediaFragment extends FileFragment implements
         
     }
 
+    private void sendFile() {
+        stopPreview(false);
+        FileActivity activity = (FileActivity)((FileFragment.ContainerActivity)getActivity());
+        activity.getFileOperationsHelper().sendDownloadedFile(getFile(), activity);
+        
+    }
 
     private void seeDetails() {
         stopPreview(false);
index ba2c1eb..ec6a8cf 100644 (file)
@@ -27,6 +27,7 @@ import android.accounts.Account;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.res.Configuration;
 import android.media.MediaPlayer;
 import android.media.MediaPlayer.OnCompletionListener;
 import android.media.MediaPlayer.OnErrorListener;
@@ -188,6 +189,10 @@ public class PreviewVideoActivity extends FileActivity implements OnCompletionLi
         return true;
     }
     
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+    }
     
     @Override
     protected void onAccountSet(boolean stateWasRecovered) {