- /**
- * Once the file upload has finished -> update view
- *
- * Being notified about the finish of an upload is necessary for the next sequence:
- * 1. Upload a big file.
- * 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
- * of its containing folder; the the server includes it in the PROPFIND requests although it's not fully upload.
- * 3. Click the file in the list to see its details.
- * 4. Wait for the upload finishes; at this moment, the details view must be refreshed to enable the action buttons.
- */
- private class UploadFinishReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
-
- if (!isEmpty() && accountName.equals(mAccount.name)) {
- boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false);
- String uploadRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH);
- boolean renamedInUpload = getFile().getRemotePath().equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
- if (getFile().getRemotePath().equals(uploadRemotePath) ||
- renamedInUpload) {
- if (uploadWasFine) {
- setFile(mStorageManager.getFileByPath(uploadRemotePath));
- }
- if (renamedInUpload) {
- String newName = (new File(uploadRemotePath)).getName();
- Toast msg = Toast.makeText(getActivity().getApplicationContext(), String.format(getString(R.string.filedetails_renamed_in_upload_msg), newName), Toast.LENGTH_LONG);
- msg.show();
- }
- getSherlockActivity().removeStickyBroadcast(intent); // not the best place to do this; a small refactorization of BroadcastReceivers should be done
-
- updateFileDetails(false, false); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server
-
- // Force the preview if the file is an image
- if (uploadWasFine && PreviewImageFragment.canBePreviewed(getFile())) {
- ((FileDisplayActivity) mContainerActivity).startImagePreview(getFile());
- }
- }
- }
- }
- }
-
-
- public void onDismiss(EditNameDialog dialog) {
- if (dialog.getResult()) {
- String newFilename = dialog.getNewFilename();
- Log_OC.d(TAG, "name edit dialog dismissed with new name " + newFilename);
- mLastRemoteOperation = new RenameFileOperation( getFile(),
- mAccount,
- newFilename,
- new FileDataStorageManager(mAccount, getActivity().getContentResolver()));
- mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
- ((FileDisplayActivity) getActivity()).showLoadingDialog();
- }
- }
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
- if (operation.equals(mLastRemoteOperation)) {
- if (operation instanceof RemoveFileOperation) {
- onRemoveFileOperationFinish((RemoveFileOperation)operation, result);
-
- } else if (operation instanceof RenameFileOperation) {
- onRenameFileOperationFinish((RenameFileOperation)operation, result);
-
- } else if (operation instanceof SynchronizeFileOperation) {
- onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result);
- }
- }
- }
-
-
- private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
- ((FileDisplayActivity) getActivity()).dismissLoadingDialog();
- if (result.isSuccess()) {
- Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
- msg.show();
- ((FileDisplayActivity)getActivity()).cleanSecondFragment();
-
- } else {
- Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG);
- msg.show();
- if (result.isSslRecoverableException()) {
- // TODO show the SSL warning dialog
- }
- }
- }
-
- private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
- ((FileDisplayActivity) getActivity()).dismissLoadingDialog();
-
- if (result.isSuccess()) {
- updateFileDetails(((RenameFileOperation)operation).getFile(), mAccount);
- mContainerActivity.onFileStateChanged();
-
- } else {
- if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
- Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG);
- msg.show();
- // TODO throw again the new rename dialog
- } if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) {
- Toast msg = Toast.makeText(getActivity(), R.string.filename_forbidden_characters, Toast.LENGTH_LONG);
- msg.show();
- } else {
- Toast msg = Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG);
- msg.show();
- if (result.isSslRecoverableException()) {
- // TODO show the SSL warning dialog
- }
- }
- }
- }
-
- private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
- ((FileDisplayActivity) getActivity()).dismissLoadingDialog();
- OCFile file = getFile();
- if (!result.isSuccess()) {
- if (result.getCode() == ResultCode.SYNC_CONFLICT) {
- Intent i = new Intent(getActivity(), ConflictsResolveActivity.class);
- i.putExtra(ConflictsResolveActivity.EXTRA_FILE, file);
- i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, mAccount);
- startActivity(i);
-
- }
-
- if (file.isDown()) {
- setButtonsForDown();
-
- } else {
- setButtonsForRemote();
- }
-
- } else {
- if (operation.transferWasRequested()) {
- setButtonsForTransferring();
- mContainerActivity.onFileStateChanged(); // this is not working; FileDownloader won't do NOTHING at all until this method finishes, so
- // checking the service to see if the file is downloading results in FALSE
- } else {
- Toast msg = Toast.makeText(getActivity(), R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG);
- msg.show();
- if (file.isDown()) {
- setButtonsForDown();
-
- } else {
- setButtonsForRemote();
- }
- }
- }
- }
-
-