X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/e4bc3bdadc47c01e88dd1de94a4666d3753ee90e..a7cbc53251aac878a9a356166d388685523f26bc:/src/com/owncloud/android/ui/activity/FileDisplayActivity.java diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 1f34ae5f..4a5b5cb3 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -74,7 +74,13 @@ import com.owncloud.android.files.services.FileObserverService; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.network.OwnCloudClientUtils; +import com.owncloud.android.operations.OnRemoteOperationListener; +import com.owncloud.android.operations.RemoteOperation; import com.owncloud.android.operations.RemoteOperationResult; +import com.owncloud.android.operations.RemoveFileOperation; +import com.owncloud.android.operations.RenameFileOperation; +import com.owncloud.android.operations.SynchronizeFileOperation; +import com.owncloud.android.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.syncadapter.FileSyncService; import com.owncloud.android.ui.dialog.SslValidatorDialog; import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener; @@ -92,7 +98,7 @@ import eu.alefzero.webdav.WebdavClient; */ public class FileDisplayActivity extends SherlockFragmentActivity implements - OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener { + OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener { private ArrayAdapter mDirectories; private OCFile mCurrentDir = null; @@ -332,7 +338,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements break; } default: - retval = false; + retval = super.onOptionsItemSelected(item); } return retval; } @@ -896,16 +902,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements */ @Override public void onReceive(Context context, Intent intent) { - long parentDirId = intent.getLongExtra(FileUploader.EXTRA_PARENT_DIR_ID, -1); - OCFile parentDir = mStorageManager.getFileById(parentDirId); + String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME); - - if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) && - parentDir != null && - ( (mCurrentDir == null && parentDir.getFileName().equals("/")) || - parentDir.equals(mCurrentDir) - ) - ) { + boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name); + boolean isDescendant = (mCurrentDir != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(mCurrentDir.getRemotePath())); + if (sameAccount && isDescendant) { OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); if (fileListFragment != null) { fileListFragment.listDirectory(); @@ -924,9 +925,9 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements public void onReceive(Context context, Intent intent) { String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME); - - if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) && - mCurrentDir != null && mCurrentDir.getFileId() == mStorageManager.getFileByPath(downloadedRemotePath).getParentId()) { + boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name); + boolean isDescendant = (mCurrentDir != null) && (downloadedRemotePath != null) && (downloadedRemotePath.startsWith(mCurrentDir.getRemotePath())); + if (sameAccount && isDescendant) { OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); if (fileListFragment != null) { fileListFragment.listDirectory(); @@ -1051,7 +1052,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements if (mDualPane) { FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); if (fragment != null) - fragment.updateFileDetails(); + fragment.updateFileDetails(false); } } @@ -1096,4 +1097,151 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } + /** + * Updates the view associated to the activity after the finish of some operation over files + * in the current account. + * + * @param operation Removal operation performed. + * @param result Result of the removal. + */ + @Override + public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { + 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); + } + } + + + /** + * Updates the view associated to the activity after the finish of an operation trying to remove a + * file. + * + * @param operation Removal operation performed. + * @param result Result of the removal. + */ + private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) { + dismissDialog(DIALOG_SHORT_WAIT); + if (result.isSuccess()) { + Toast msg = Toast.makeText(this, R.string.remove_success_msg, Toast.LENGTH_LONG); + msg.show(); + OCFile removedFile = operation.getFile(); + if (mDualPane) { + FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); + if (details != null && removedFile.equals(details.getDisplayedFile()) ) { + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment + transaction.commit(); + } + } + if (mStorageManager.getFileById(removedFile.getParentId()).equals(mCurrentDir)) { + mFileList.listDirectory(); + } + + } else { + Toast msg = Toast.makeText(this, R.string.remove_fail_msg, Toast.LENGTH_LONG); + msg.show(); + if (result.isSslRecoverableException()) { + mLastSslUntrustedServerResult = result; + showDialog(DIALOG_SSL_VALIDATOR); + } + } + } + + /** + * Updates the view associated to the activity after the finish of an operation trying to rename a + * file. + * + * @param operation Renaming operation performed. + * @param result Result of the renaming. + */ + private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) { + dismissDialog(DIALOG_SHORT_WAIT); + OCFile renamedFile = operation.getFile(); + if (result.isSuccess()) { + if (mDualPane) { + FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); + if (details != null && renamedFile.equals(details.getDisplayedFile()) ) { + details.updateFileDetails(renamedFile, AccountUtils.getCurrentOwnCloudAccount(this)); + } + } + if (mStorageManager.getFileById(renamedFile.getParentId()).equals(mCurrentDir)) { + mFileList.listDirectory(); + } + + } else { + if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) { + Toast msg = Toast.makeText(this, R.string.rename_local_fail_msg, Toast.LENGTH_LONG); + msg.show(); + // TODO throw again the new rename dialog + } else { + Toast msg = Toast.makeText(this, R.string.rename_server_fail_msg, Toast.LENGTH_LONG); + msg.show(); + if (result.isSslRecoverableException()) { + mLastSslUntrustedServerResult = result; + showDialog(DIALOG_SSL_VALIDATOR); + } + } + } + } + + + private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) { + dismissDialog(DIALOG_SHORT_WAIT); + OCFile syncedFile = operation.getLocalFile(); + if (!result.isSuccess()) { + if (result.getCode() == ResultCode.SYNC_CONFLICT) { + Intent i = new Intent(this, ConflictsResolveActivity.class); + i.putExtra(ConflictsResolveActivity.EXTRA_FILE, syncedFile); + i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this)); + startActivity(i); + + } else { + Toast msg = Toast.makeText(this, R.string.sync_file_fail_msg, Toast.LENGTH_LONG); + msg.show(); + } + + } else { + if (operation.transferWasRequested()) { + mFileList.listDirectory(); + onTransferStateChanged(syncedFile, true, true); + + } else { + Toast msg = Toast.makeText(this, R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG); + msg.show(); + } + } + } + + + /** + * {@inheritDoc} + */ + @Override + public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) { + /*OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); + if (fileListFragment != null) { + fileListFragment.listDirectory(); + }*/ + if (mDualPane) { + FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); + if (details != null && file.equals(details.getDisplayedFile()) ) { + if (downloading || uploading) { + details.updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this)); + } else { + details.updateFileDetails(downloading || uploading); + } + } + } + } + + + + + }