- if (getView()!=null && getView().findViewById(R.id.fdDownloadBtn) != null) \r
- getView().findViewById(R.id.fdDownloadBtn).setEnabled(true);\r
- \r
- if (intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false)) {\r
- mFile.setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH));\r
- updateFileDetails();\r
- } else if (intent.getAction().equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) {\r
- Toast.makeText(context, R.string.downloader_download_failed , Toast.LENGTH_SHORT).show();\r
+ String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);\r
+\r
+ if (!isEmpty() && accountName.equals(mAccount.name)) {\r
+ boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false);\r
+ String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);\r
+ if (mFile.getRemotePath().equals(downloadedRemotePath)) {\r
+ if (downloadWasFine) {\r
+ mFile.setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); // updates the local object without accessing the database again\r
+ }\r
+ updateFileDetails(); // it updates the buttons; must be called although !downloadWasFine\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ \r
+ /**\r
+ * Once the file upload has finished -> update view\r
+ * \r
+ * Being notified about the finish of an upload is necessary for the next sequence:\r
+ * 1. Upload a big file.\r
+ * 2. Force a synchronization; if it finished before the upload, the file in transfer will be included in the local database and in the file list\r
+ * of its containing folder; the the server includes it in the PROPFIND requests although it's not fully upload. \r
+ * 3. Click the file in the list to see its details.\r
+ * 4. Wait for the upload finishes; at this moment, the details view must be refreshed to enable the action buttons.\r
+ */\r
+ private class UploadFinishReceiver extends BroadcastReceiver {\r
+ @Override\r
+ public void onReceive(Context context, Intent intent) {\r
+ String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);\r
+\r
+ if (!isEmpty() && accountName.equals(mAccount.name)) {\r
+ boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false);\r
+ String uploadRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH);\r
+ if (mFile.getRemotePath().equals(uploadRemotePath)) {\r
+ if (uploadWasFine) {\r
+ FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());\r
+ mFile = fdsm.getFileByPath(mFile.getRemotePath());\r
+ }\r
+ updateFileDetails(); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server\r
+ }\r