- String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
- String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
- boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
- OCFile currentDir = getCurrentDir();
- boolean isDescendant = (currentDir != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(currentDir.getRemotePath()));
- if (sameAccount && isDescendant) {
- /*
- refeshListOfFilesFragment();
- */
+ try {
+ String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
+ String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
+ boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
+ OCFile currentDir = getCurrentDir();
+ boolean isDescendant = (currentDir != null) && (uploadedRemotePath != null) &&
+ (uploadedRemotePath.startsWith(currentDir.getRemotePath()));
+
+ if (sameAccount && isDescendant) {
+ refreshListOfFilesFragment();
+ }
+
+ boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false);
+ boolean renamedInUpload = getFile().getRemotePath().
+ equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
+ boolean sameFile = getFile().getRemotePath().equals(uploadedRemotePath) ||
+ renamedInUpload;
+ FileFragment details = getSecondFragment();
+ boolean detailFragmentIsShown = (details != null &&
+ details instanceof FileDetailFragment);
+
+ if (sameAccount && sameFile && detailFragmentIsShown) {
+ if (uploadWasFine) {
+ setFile(getStorageManager().getFileByPath(uploadedRemotePath));
+ }
+ if (renamedInUpload) {
+ String newName = (new File(uploadedRemotePath)).getName();
+ Toast msg = Toast.makeText(
+ context,
+ String.format(
+ getString(R.string.filedetails_renamed_in_upload_msg),
+ newName),
+ Toast.LENGTH_LONG);
+ msg.show();
+ }
+ if (uploadWasFine || getFile().fileExists()) {
+ ((FileDetailFragment)details).updateFileDetails(false, true);
+ } else {
+ cleanSecondFragment();
+ }
+
+ // Force the preview if the file is an image
+ if (uploadWasFine && PreviewImageFragment.canBePreviewed(getFile())) {
+ startImagePreview(getFile());
+ } // TODO what about other kind of previews?
+ }
+
+ } finally {
+ if (intent != null) {
+ removeStickyBroadcast(intent);
+ }