import com.owncloud.android.files.services.FileObserverService;\r
import com.owncloud.android.files.services.FileUploader;\r
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
-import com.owncloud.android.network.OwnCloudClientUtils;\r
+import com.owncloud.android.operations.CreateFolderOperation;\r
+import com.owncloud.android.operations.OnRemoteOperationListener;\r
+import com.owncloud.android.operations.RemoteOperation;\r
import com.owncloud.android.operations.RemoteOperationResult;\r
+import com.owncloud.android.operations.RemoveFileOperation;\r
+import com.owncloud.android.operations.RenameFileOperation;\r
+import com.owncloud.android.operations.SynchronizeFileOperation;\r
+import com.owncloud.android.operations.RemoteOperationResult.ResultCode;\r
import com.owncloud.android.syncadapter.FileSyncService;\r
import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
import com.owncloud.android.ui.fragment.OCFileListFragment;\r
\r
import com.owncloud.android.R;\r
-import eu.alefzero.webdav.WebdavClient;\r
\r
/**\r
* Displays, what files the user has available in his ownCloud.\r
*/\r
\r
public class FileDisplayActivity extends SherlockFragmentActivity implements\r
- OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener {\r
+ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener {\r
\r
private ArrayAdapter<String> mDirectories;\r
private OCFile mCurrentDir = null;\r
private OCFileListFragment mFileList;\r
\r
private boolean mDualPane;\r
+ private Handler mHandler;\r
\r
private static final int DIALOG_SETUP_ACCOUNT = 0;\r
private static final int DIALOG_CREATE_DIR = 1;\r
public void onCreate(Bundle savedInstanceState) {\r
Log.d(getClass().toString(), "onCreate() start");\r
super.onCreate(savedInstanceState);\r
+ \r
+ mHandler = new Handler();\r
\r
/// Load of parameters from received intent\r
mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); // no check necessary, mCurrenDir == null if the parameter is not in the intent\r
*/\r
private void createFirstAccount() {\r
Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);\r
- intent.putExtra(android.provider.Settings.EXTRA_AUTHORITIES, new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE });\r
+ intent.putExtra(android.provider.Settings.EXTRA_AUTHORITIES, new String[] { AccountAuthenticator.AUTHORITY });\r
startActivity(intent); // the new activity won't be created until this.onStart() and this.onResume() are finished;\r
}\r
\r
break;\r
}\r
default:\r
- retval = false;\r
+ retval = super.onOptionsItemSelected(item);\r
}\r
return retval;\r
}\r
\r
private void startSynchronization() {\r
- ContentResolver.cancelSync(null, AccountAuthenticator.AUTH_TOKEN_TYPE); // cancel the current synchronizations of any ownCloud account\r
+ ContentResolver.cancelSync(null, AccountAuthenticator.AUTHORITY); // cancel the current synchronizations of any ownCloud account\r
Bundle bundle = new Bundle();\r
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
ContentResolver.requestSync(\r
AccountUtils.getCurrentOwnCloudAccount(this),\r
- AccountAuthenticator.AUTH_TOKEN_TYPE, bundle);\r
+ AccountAuthenticator.AUTHORITY, bundle);\r
}\r
\r
\r
*/\r
public void onActivityResult(int requestCode, int resultCode, Intent data) {\r
\r
- if (requestCode == ACTION_SELECT_CONTENT_FROM_APPS && resultCode == RESULT_OK) {\r
- requestSimpleUpload(data);\r
+ if (requestCode == ACTION_SELECT_CONTENT_FROM_APPS && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {\r
+ requestSimpleUpload(data, resultCode);\r
\r
- } else if (requestCode == ACTION_SELECT_MULTIPLE_FILES && resultCode == RESULT_OK) {\r
- requestMultipleUpload(data);\r
+ } else if (requestCode == ACTION_SELECT_MULTIPLE_FILES && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {\r
+ requestMultipleUpload(data, resultCode);\r
\r
}\r
}\r
\r
- private void requestMultipleUpload(Intent data) {\r
+ private void requestMultipleUpload(Intent data, int resultCode) {\r
String[] filePaths = data.getStringArrayExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES);\r
if (filePaths != null) {\r
String[] remotePaths = new String[filePaths.length];\r
i.putExtra(FileUploader.KEY_LOCAL_FILE, filePaths);\r
i.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths);\r
i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES);\r
+ if (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)\r
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);\r
startService(i);\r
\r
} else {\r
}\r
\r
\r
- private void requestSimpleUpload(Intent data) {\r
+ private void requestSimpleUpload(Intent data, int resultCode) {\r
String filepath = null;\r
try {\r
Uri selectedImageUri = data.getData();\r
i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath);\r
i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath);\r
i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);\r
+ if (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)\r
+ i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);\r
startService(i);\r
}\r
\r
dialog.dismiss();\r
}\r
});\r
- builder.setNegativeButton(R.string.common_exit, new OnClickListener() {\r
+ String message = String.format(getString(R.string.common_exit), getString(R.string.app_name));\r
+ builder.setNegativeButton(message, new OnClickListener() {\r
public void onClick(DialogInterface dialog, int which) {\r
dialog.dismiss();\r
finish();\r
PackageInfo pkg;\r
try {\r
pkg = getPackageManager().getPackageInfo(getPackageName(), 0);\r
- builder.setMessage(String.format(getString(R.string.about_message), pkg.versionName));\r
+ builder.setMessage(String.format(getString(R.string.about_message), getString(R.string.app_name), pkg.versionName));\r
builder.setIcon(android.R.drawable.ic_menu_info_details);\r
dialog = builder.create();\r
} catch (NameNotFoundException e) {\r
\r
// Create directory\r
path += directoryName + OCFile.PATH_SEPARATOR;\r
- Thread thread = new Thread(new DirectoryCreator(path, AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this), new Handler()));\r
- thread.start();\r
+ RemoteOperation operation = new CreateFolderOperation(path, mCurrentDir.getFileId(), mStorageManager);\r
+ operation.execute( AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this), \r
+ FileDisplayActivity.this, \r
+ FileDisplayActivity.this, \r
+ mHandler,\r
+ FileDisplayActivity.this);\r
\r
dialog.dismiss();\r
\r
if (item == 0) {\r
//if (!mDualPane) { \r
Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class);\r
+ action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this));\r
startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);\r
//} else {\r
// TODO create and handle new fragment LocalFileListFragment\r
return !mDirectories.isEmpty();\r
}\r
\r
- private class DirectoryCreator implements Runnable {\r
- private String mTargetPath;\r
- private Account mAccount;\r
- private Handler mHandler; \r
- \r
- public DirectoryCreator(String targetPath, Account account, Handler handler) {\r
- mTargetPath = targetPath;\r
- mAccount = account;\r
- mHandler = handler;\r
- }\r
- \r
- @Override\r
- public void run() {\r
- WebdavClient wdc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext());\r
- boolean created = wdc.createDirectory(mTargetPath);\r
- if (created) {\r
- mHandler.post(new Runnable() {\r
- @Override\r
- public void run() { \r
- dismissDialog(DIALOG_SHORT_WAIT);\r
- \r
- // Save new directory in local database\r
- OCFile newDir = new OCFile(mTargetPath);\r
- newDir.setMimetype("DIR");\r
- newDir.setParentId(mCurrentDir.getFileId());\r
- mStorageManager.saveFile(newDir);\r
- \r
- // Display the new folder right away\r
- mFileList.listDirectory();\r
- }\r
- });\r
- \r
- } else {\r
- mHandler.post(new Runnable() {\r
- @Override\r
- public void run() {\r
- dismissDialog(DIALOG_SHORT_WAIT);\r
- try {\r
- Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG); \r
- msg.show();\r
- \r
- } catch (NotFoundException e) {\r
- Log.e(TAG, "Error while trying to show fail message " , e);\r
- }\r
- }\r
- });\r
- }\r
- }\r
- \r
- }\r
\r
// Custom array adapter to override text colors\r
private class CustomArrayAdapter<T> extends ArrayAdapter<T> {\r
}\r
\r
setSupportProgressBarIndeterminateVisibility(inProgress);\r
+ removeStickyBroadcast(intent);\r
\r
}\r
\r
*/\r
@Override\r
public void onReceive(Context context, Intent intent) {\r
- long parentDirId = intent.getLongExtra(FileUploader.EXTRA_PARENT_DIR_ID, -1);\r
- OCFile parentDir = mStorageManager.getFileById(parentDirId);\r
+ String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);\r
String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);\r
-\r
- if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) &&\r
- parentDir != null && \r
- ( (mCurrentDir == null && parentDir.getFileName().equals("/")) ||\r
- parentDir.equals(mCurrentDir)\r
- )\r
- ) {\r
+ boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name);\r
+ boolean isDescendant = (mCurrentDir != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(mCurrentDir.getRemotePath()));\r
+ if (sameAccount && isDescendant) {\r
OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
if (fileListFragment != null) { \r
fileListFragment.listDirectory();\r
public void onReceive(Context context, Intent intent) {\r
String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);\r
String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);\r
-\r
- if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) &&\r
- mCurrentDir != null && mCurrentDir.getFileId() == mStorageManager.getFileByPath(downloadedRemotePath).getParentId()) {\r
+ boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name);\r
+ boolean isDescendant = (mCurrentDir != null) && (downloadedRemotePath != null) && (downloadedRemotePath.startsWith(mCurrentDir.getRemotePath()));\r
+ if (sameAccount && isDescendant) {\r
OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
if (fileListFragment != null) { \r
fileListFragment.listDirectory();\r
if (mDualPane) {\r
FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
if (fragment != null)\r
- fragment.updateFileDetails();\r
+ fragment.updateFileDetails(false);\r
}\r
}\r
\r
}\r
\r
\r
+ /**\r
+ * Updates the view associated to the activity after the finish of some operation over files\r
+ * in the current account.\r
+ * \r
+ * @param operation Removal operation performed.\r
+ * @param result Result of the removal.\r
+ */\r
+ @Override\r
+ public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {\r
+ if (operation instanceof RemoveFileOperation) {\r
+ onRemoveFileOperationFinish((RemoveFileOperation)operation, result);\r
+ \r
+ } else if (operation instanceof RenameFileOperation) {\r
+ onRenameFileOperationFinish((RenameFileOperation)operation, result);\r
+ \r
+ } else if (operation instanceof SynchronizeFileOperation) {\r
+ onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result);\r
+ \r
+ } else if (operation instanceof CreateFolderOperation) {\r
+ onCreateFolderOperationFinish((CreateFolderOperation)operation, result);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Updates the view associated to the activity after the finish of an operation trying create a new folder\r
+ * \r
+ * @param operation Creation operation performed.\r
+ * @param result Result of the creation.\r
+ */\r
+ private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) {\r
+ if (result.isSuccess()) {\r
+ dismissDialog(DIALOG_SHORT_WAIT);\r
+ mFileList.listDirectory();\r
+ \r
+ } else {\r
+ dismissDialog(DIALOG_SHORT_WAIT);\r
+ try {\r
+ Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ \r
+ } catch (NotFoundException e) {\r
+ Log.e(TAG, "Error while trying to show fail message " , e);\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ /**\r
+ * Updates the view associated to the activity after the finish of an operation trying to remove a \r
+ * file. \r
+ * \r
+ * @param operation Removal operation performed.\r
+ * @param result Result of the removal.\r
+ */\r
+ private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {\r
+ dismissDialog(DIALOG_SHORT_WAIT);\r
+ if (result.isSuccess()) {\r
+ Toast msg = Toast.makeText(this, R.string.remove_success_msg, Toast.LENGTH_LONG);\r
+ msg.show();\r
+ OCFile removedFile = operation.getFile();\r
+ if (mDualPane) {\r
+ FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
+ if (details != null && removedFile.equals(details.getDisplayedFile()) ) {\r
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\r
+ transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment\r
+ transaction.commit();\r
+ }\r
+ }\r
+ if (mStorageManager.getFileById(removedFile.getParentId()).equals(mCurrentDir)) {\r
+ mFileList.listDirectory();\r
+ }\r
+ \r
+ } else {\r
+ Toast msg = Toast.makeText(this, R.string.remove_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ if (result.isSslRecoverableException()) {\r
+ mLastSslUntrustedServerResult = result;\r
+ showDialog(DIALOG_SSL_VALIDATOR); \r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Updates the view associated to the activity after the finish of an operation trying to rename a \r
+ * file. \r
+ * \r
+ * @param operation Renaming operation performed.\r
+ * @param result Result of the renaming.\r
+ */\r
+ private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {\r
+ dismissDialog(DIALOG_SHORT_WAIT);\r
+ OCFile renamedFile = operation.getFile();\r
+ if (result.isSuccess()) {\r
+ if (mDualPane) {\r
+ FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
+ if (details != null && renamedFile.equals(details.getDisplayedFile()) ) {\r
+ details.updateFileDetails(renamedFile, AccountUtils.getCurrentOwnCloudAccount(this));\r
+ }\r
+ }\r
+ if (mStorageManager.getFileById(renamedFile.getParentId()).equals(mCurrentDir)) {\r
+ mFileList.listDirectory();\r
+ }\r
+ \r
+ } else {\r
+ if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {\r
+ Toast msg = Toast.makeText(this, R.string.rename_local_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ // TODO throw again the new rename dialog\r
+ } else {\r
+ Toast msg = Toast.makeText(this, R.string.rename_server_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ if (result.isSslRecoverableException()) {\r
+ mLastSslUntrustedServerResult = result;\r
+ showDialog(DIALOG_SSL_VALIDATOR); \r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {\r
+ dismissDialog(DIALOG_SHORT_WAIT);\r
+ OCFile syncedFile = operation.getLocalFile();\r
+ if (!result.isSuccess()) {\r
+ if (result.getCode() == ResultCode.SYNC_CONFLICT) {\r
+ Intent i = new Intent(this, ConflictsResolveActivity.class);\r
+ i.putExtra(ConflictsResolveActivity.EXTRA_FILE, syncedFile);\r
+ i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));\r
+ startActivity(i);\r
+ \r
+ } else {\r
+ Toast msg = Toast.makeText(this, R.string.sync_file_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ }\r
+ \r
+ } else {\r
+ if (operation.transferWasRequested()) {\r
+ mFileList.listDirectory();\r
+ onTransferStateChanged(syncedFile, true, true);\r
+ \r
+ } else {\r
+ Toast msg = Toast.makeText(this, R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {\r
+ /*OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+ if (fileListFragment != null) { \r
+ fileListFragment.listDirectory();\r
+ }*/\r
+ if (mDualPane) {\r
+ FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
+ if (details != null && file.equals(details.getDisplayedFile()) ) {\r
+ if (downloading || uploading) {\r
+ details.updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this));\r
+ } else {\r
+ details.updateFileDetails(downloading || uploading);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ \r
+\r
+\r
}\r