Browse Source

non-downloaded file will first downloaded and then used for "set as"

tobiasKaminsky 7 years ago
parent
commit
852252717b

+ 5 - 2
src/main/java/com/owncloud/android/files/services/FileDownloader.java

@@ -54,6 +54,7 @@ import com.owncloud.android.lib.resources.files.FileUtils;
 import com.owncloud.android.operations.DownloadFileOperation;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
+import com.owncloud.android.ui.fragment.OCFileListFragment;
 import com.owncloud.android.ui.notifications.NotificationUtils;
 import com.owncloud.android.ui.preview.PreviewImageActivity;
 import com.owncloud.android.ui.preview.PreviewImageFragment;
@@ -174,9 +175,10 @@ public class FileDownloader extends Service
         } else {
             final Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
             final OCFile file = intent.getParcelableExtra(EXTRA_FILE);
+            final String behaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR);
             AbstractList<String> requestedDownloads = new Vector<String>();
             try {
-                DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
+                DownloadFileOperation newDownload = new DownloadFileOperation(account, file, behaviour);
                 newDownload.addDatatransferProgressListener(this);
                 newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
                 Pair<String, String> putResult = mPendingDownloads.putIfAbsent(
@@ -490,7 +492,7 @@ public class FileDownloader extends Service
         file.setFileLength((new File(mCurrentDownload.getSavePath()).length()));
         file.setRemoteId(mCurrentDownload.getFile().getRemoteId());
         mStorageManager.saveFile(file);
-        mStorageManager.triggerMediaScan(file.getStoragePath());
+        FileDataStorageManager.triggerMediaScan(file.getStoragePath());
         mStorageManager.saveConflict(file, null);
     }
 
@@ -639,6 +641,7 @@ public class FileDownloader extends Service
         end.putExtra(ACCOUNT_NAME, download.getAccount().name);
         end.putExtra(EXTRA_REMOTE_PATH, download.getRemotePath());
         end.putExtra(EXTRA_FILE_PATH, download.getSavePath());
+        end.putExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR, download.getBehaviour());
         if (unlinkedFromRemotePath != null) {
             end.putExtra(EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath);
         }

+ 8 - 2
src/main/java/com/owncloud/android/operations/DownloadFileOperation.java

@@ -49,6 +49,7 @@ public class DownloadFileOperation extends RemoteOperation {
 
     private Account mAccount;
     private OCFile mFile;
+    private String mBehaviour;
     private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
     private long mModificationTimestamp = 0;
     private String mEtag = "";
@@ -56,8 +57,8 @@ public class DownloadFileOperation extends RemoteOperation {
     
     private DownloadRemoteFileOperation mDownloadOperation;
 
-    
-    public DownloadFileOperation(Account account, OCFile file) {
+
+    public DownloadFileOperation(Account account, OCFile file, String behaviour) {
         if (account == null) {
             throw new IllegalArgumentException("Illegal null account in DownloadFileOperation " +
                     "creation");
@@ -69,6 +70,7 @@ public class DownloadFileOperation extends RemoteOperation {
         
         mAccount = account;
         mFile = file;
+        mBehaviour = behaviour;
     }
 
 
@@ -80,6 +82,10 @@ public class DownloadFileOperation extends RemoteOperation {
         return mFile;
     }
 
+    public String getBehaviour() {
+        return mBehaviour;
+    }
+
     public String getSavePath() {
         if (mFile.getStoragePath() != null) {
             File path = new File(mFile.getStoragePath());  // re-downloads should be done over the original file

+ 27 - 14
src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -83,12 +83,12 @@ import com.owncloud.android.services.observer.FileObserverService;
 import com.owncloud.android.syncadapter.FileSyncAdapter;
 import com.owncloud.android.ui.dialog.SortingOrderDialogFragment;
 import com.owncloud.android.ui.events.TokenPushEvent;
-import com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment;
 import com.owncloud.android.ui.fragment.ExtendedListFragment;
 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.fragment.TaskRetainerFragment;
+import com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment;
 import com.owncloud.android.ui.helpers.UriUploader;
 import com.owncloud.android.ui.preview.PreviewImageActivity;
 import com.owncloud.android.ui.preview.PreviewImageFragment;
@@ -1373,28 +1373,35 @@ public class FileDisplayActivity extends HookActivity
         public void onReceive(Context context, Intent intent) {
             try {
                 boolean sameAccount = isSameAccount(intent);
-                String downloadedRemotePath =
-                        intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
+                String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
+                String downloadBehaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR);
                 boolean isDescendant = isDescendant(downloadedRemotePath);
 
                 if (sameAccount && isDescendant) {
-                    String linkedToRemotePath =
-                            intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH);
+                    String linkedToRemotePath = intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH);
                     if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
                         refreshListOfFilesFragment(false);
                     }
                     refreshSecondFragment(
                             intent.getAction(),
                             downloadedRemotePath,
-                            intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false)
-                    );
+                            intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
                 }
 
                 if (mWaitingToSend != null) {
-                    mWaitingToSend =
-                            getStorageManager().getFileByPath(mWaitingToSend.getRemotePath());
-                    if (mWaitingToSend.isDown()) {
-                        sendDownloadedFile();
+                    mWaitingToSend = getStorageManager().getFileByPath(mWaitingToSend.getRemotePath());
+                    if (mWaitingToSend.isDown() && downloadBehaviour != null) {
+                        switch (downloadBehaviour) {
+                            case OCFileListFragment.DOWNLOAD_SEND:
+                                sendDownloadedFile();
+                                break;
+                            case OCFileListFragment.DOWNLOAD_SET_AS:
+                                setPictureAs();
+                                break;
+                            default:
+                                // do nothing
+                                break;
+                        }
                     }
                 }
 
@@ -1872,12 +1879,13 @@ public class FileDisplayActivity extends HookActivity
         }
     }
 
-    private void requestForDownload(OCFile file) {
+    private void requestForDownload(OCFile file, String downloadBehaviour) {
         Account account = getAccount();
         if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) {
             Intent i = new Intent(this, FileDownloader.class);
             i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
             i.putExtra(FileDownloader.EXTRA_FILE, file);
+            i.putExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR, downloadBehaviour);
             startService(i);
         }
     }
@@ -1887,6 +1895,11 @@ public class FileDisplayActivity extends HookActivity
         mWaitingToSend = null;
     }
 
+    private void setPictureAs() {
+        getFileOperationsHelper().setPictureAs(mWaitingToSend);
+        mWaitingToSend = null;
+    }
+
 
     /**
      * Requests the download of the received {@link OCFile} , updates the UI
@@ -1895,9 +1908,9 @@ public class FileDisplayActivity extends HookActivity
      *
      * @param file {@link OCFile} to download and preview.
      */
-    public void startDownloadForSending(OCFile file) {
+    public void startDownloadForSending(OCFile file, String downloadBehaviour) {
         mWaitingToSend = file;
-        requestForDownload(mWaitingToSend);
+        requestForDownload(mWaitingToSend, downloadBehaviour);
         boolean hasSecondFragment = (getSecondFragment() != null);
         updateFragmentsVisibility(hasSecondFragment);
     }

+ 2 - 1
src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -307,7 +307,8 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
                 // Obtain the file
                 if (!getFile().isDown()) {  // Download the file                    
                     Log_OC.d(TAG, getFile().getRemotePath() + " : File must be downloaded");
-                    ((FileDisplayActivity) mContainerActivity).startDownloadForSending(getFile());
+                    ((FileDisplayActivity) mContainerActivity).startDownloadForSending(getFile(),
+                            OCFileListFragment.DOWNLOAD_SEND);
                 }
                 else {
                     mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile());

+ 11 - 3
src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -120,6 +120,10 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
     public final static String ARG_ALLOW_CONTEXTUAL_ACTIONS = MY_PACKAGE + ".ALLOW_CONTEXTUAL";
     public final static String ARG_HIDE_FAB = MY_PACKAGE + ".HIDE_FAB";
 
+    public static final String DOWNLOAD_BEHAVIOUR = "DOWNLOAD_BEHAVIOUR";
+    public static final String DOWNLOAD_SEND = "DOWNLOAD_SEND";
+    public static final String DOWNLOAD_SET_AS = "DOWNLOAD_SET_AS";
+
     public static final String SEARCH_EVENT = "SEARCH_EVENT";
 
     private static final String KEY_FILE = MY_PACKAGE + ".extra.FILE";
@@ -867,15 +871,19 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
                     // Obtain the file
                     if (!singleFile.isDown()) {  // Download the file
                         Log_OC.d(TAG, singleFile.getRemotePath() + " : File must be downloaded");
-                        ((FileDisplayActivity) mContainerActivity).startDownloadForSending(singleFile);
-
+                        ((FileDisplayActivity) mContainerActivity).startDownloadForSending(singleFile, DOWNLOAD_SEND);
                     } else {
                         mContainerActivity.getFileOperationsHelper().sendDownloadedFile(singleFile);
                     }
                     return true;
                 }
                 case R.id.action_set_as_wallpaper: {
-                    mContainerActivity.getFileOperationsHelper().setPictureAs(singleFile);
+                    if (singleFile.isDown()) {
+                        mContainerActivity.getFileOperationsHelper().setPictureAs(singleFile);
+                    } else {
+                        Log_OC.d(TAG, singleFile.getRemotePath() + " : File must be downloaded");
+                        ((FileDisplayActivity) mContainerActivity).startDownloadForSending(singleFile, DOWNLOAD_SET_AS);
+                    }
                     return true;
                 }
             }