- mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT);
- mFile = intent.getParcelableExtra(EXTRA_FILE);
-
- if (ACTION_CANCEL_FILE_DOWNLOAD.equals(intent.getAction())) {
-
- new Thread(new Runnable() {
- public void run() {
- // Cancel the download
- cancel(mAccount,mFile);
- }
- }).start();
-
- } else {
-
- AbstractList<String> requestedDownloads = new Vector<String>(); // dvelasco: now this always contains just one element, but that can change in a near future (download of multiple selection)
- String downloadKey = buildRemoteName(mAccount, mFile);
- try {
- DownloadFileOperation newDownload = new DownloadFileOperation(mAccount, mFile);
- mPendingDownloads.putIfAbsent(downloadKey, newDownload);
- newDownload.addDatatransferProgressListener(this);
- newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
- requestedDownloads.add(downloadKey);
- sendBroadcastNewDownload(newDownload);
-
- } catch (IllegalArgumentException e) {
- Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
- return START_NOT_STICKY;
- }
+ final Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
+ final OCFile file = intent.getParcelableExtra(EXTRA_FILE);
+ AbstractList<String> requestedDownloads = new Vector<String>();
+ try {
+ DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
+ newDownload.addDatatransferProgressListener(this);
+ newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
+ Pair<String, String> putResult = mPendingDownloads.putIfAbsent(
+ account, file.getRemotePath(), newDownload
+ );
+ String downloadKey = putResult.first;
+ requestedDownloads.add(downloadKey);
+
+ // Store file on db with state 'downloading'
+ /*
+ TODO - check if helps with UI responsiveness,
+ letting only folders use FileDownloaderBinder to check
+ FileDataStorageManager storageManager =
+ new FileDataStorageManager(account, getContentResolver());
+ file.setDownloading(true);
+ storageManager.saveFile(file);
+ */
+
+ sendBroadcastNewDownload(newDownload, putResult.second);
+
+ } catch (IllegalArgumentException e) {
+ Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
+ return START_NOT_STICKY;
+ }