OC-2967: Grant that files are downloaded automatically when the action is triggered...
authormasensio <masensio@solidgear.es>
Mon, 17 Feb 2014 11:44:08 +0000 (12:44 +0100)
committermasensio <masensio@solidgear.es>
Mon, 17 Feb 2014 11:44:08 +0000 (12:44 +0100)
src/com/owncloud/android/files/FileOperationsHelper.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/fragment/OCFileListFragment.java
src/com/owncloud/android/ui/preview/PreviewImageFragment.java

index 4b37a3b..82e0aaa 100644 (file)
@@ -139,7 +139,7 @@ public class FileOperationsHelper {
         }
         return false;
     }
-
+    
     
     public void unshareFileWithLink(OCFile file, FileActivity callerActivity) {
         
@@ -160,4 +160,25 @@ public class FileOperationsHelper {
             
         }
     }
+    
+    public void sendFile(OCFile file, FileActivity callerActivity) {
+        // Obtain the file
+        if (!file.isDown()) {  // Download the file
+            Log_OC.d(TAG, file.getRemotePath() + " : File must be downloaded");           
+        } else {
+            sendDownloadedFile(file, callerActivity);
+        }
+        
+        
+    }
+    
+    public void sendDownloadedFile(OCFile file, FileActivity callerActivity) {
+        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
+        // set MimeType
+        sharingIntent.setType(file.getMimetype());
+        sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getStoragePath()));
+        callerActivity.startActivity(Intent.createChooser(sharingIntent, callerActivity.getString(R.string.send_file_title_intent))); 
+    }
+
+    
 }
index e696352..6769857 100644 (file)
@@ -86,7 +86,6 @@ import com.owncloud.android.ui.fragment.FileDetailFragment;
 import com.owncloud.android.ui.fragment.FileFragment;
 import com.owncloud.android.ui.fragment.OCFileListFragment;
 import com.owncloud.android.ui.preview.PreviewImageActivity;
-import com.owncloud.android.ui.preview.PreviewImageFragment;
 import com.owncloud.android.ui.preview.PreviewMediaFragment;
 import com.owncloud.android.ui.preview.PreviewVideoActivity;
 import com.owncloud.android.utils.DisplayUtils;
@@ -142,6 +141,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");
@@ -1023,6 +1024,11 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
                 refreshSecondFragment(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
             }
 
+            if (mWaitingToSend != null && mWaitingToSend.isDown()) {
+                
+                sendDownloadedFile();
+                
+            }
             removeStickyBroadcast(intent);
         }
 
@@ -1602,4 +1608,33 @@ 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);
+        updateFragmentsVisibility(true);
+    }
+    
+    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 5c6817e..43f3734 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;
@@ -362,11 +360,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, getResources().getString(R.string.send_file_title_intent))); 
+                // 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 +476,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 80d5d1e..5560c27 100644 (file)
@@ -311,7 +311,8 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
                 return true;
             }
             case R.id.action_send_file: {
-                sendFile();
+                FileActivity act = (FileActivity)getSherlockActivity();
+                act.getFileOperationsHelper().sendDownloadedFile(getFile(), act);
                 return true;
             }
             
@@ -320,15 +321,6 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
         }
     }
     
-    private void sendFile(){
-        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, getResources().getString(R.string.send_file_title_intent)));
-    }
-
-    
 
     private void seeDetails() {
         ((FileFragment.ContainerActivity)getActivity()).showDetails(getFile());