*/\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
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
import java.io.File;
+import android.accounts.Account;
import android.content.Intent;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
+import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.MenuItem;
+import com.owncloud.android.ui.dialog.IndeterminateProgressDialog;
+import com.owncloud.android.ui.fragment.ConfirmationDialogFragment;
import com.owncloud.android.ui.fragment.LocalFileListFragment;
+import com.owncloud.android.ui.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
+import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.R;
*/
public class UploadFilesActivity extends SherlockFragmentActivity implements
- LocalFileListFragment.ContainerActivity, OnNavigationListener, OnClickListener {
+ LocalFileListFragment.ContainerActivity, OnNavigationListener, OnClickListener, ConfirmationDialogFragmentListener {
private ArrayAdapter<String> mDirectories;
private File mCurrentDir = null;
private LocalFileListFragment mFileListFragment;
private Button mCancelBtn;
private Button mUploadBtn;
+ private Account mAccount;
+ private DialogFragment mCurrentDialog;
- public static final String EXTRA_DIRECTORY_PATH = "com.owncloud.android.Directory";
- public static final String EXTRA_CHOSEN_FILES = "com.owncloud.android.ChosenFiles";
+ public static final String EXTRA_ACCOUNT = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_ACCOUNT";
+ public static final String EXTRA_CHOSEN_FILES = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CHOSEN_FILES";
+
+ public static final int RESULT_OK_AND_MOVE = RESULT_FIRST_USER;
+ private static final String KEY_DIRECTORY_PATH = UploadFilesActivity.class.getCanonicalName() + ".KEY_DIRECTORY_PATH";
private static final String TAG = "UploadFilesActivity";
+ private static final String WAIT_DIALOG_TAG = "WAIT";
+ private static final String QUERY_TO_MOVE_DIALOG_TAG = "QUERY_TO_MOVE";
@Override
super.onCreate(savedInstanceState);
if(savedInstanceState != null) {
- mCurrentDir = new File(savedInstanceState.getString(UploadFilesActivity.EXTRA_DIRECTORY_PATH));
+ mCurrentDir = new File(savedInstanceState.getString(UploadFilesActivity.KEY_DIRECTORY_PATH));
} else {
mCurrentDir = Environment.getExternalStorageDirectory();
}
+ mAccount = getIntent().getParcelableExtra(EXTRA_ACCOUNT);
+
/// USER INTERFACE
// Drop-down navigation
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setListNavigationCallbacks(mDirectories, this);
+
+ // wait dialog
+ if (mCurrentDialog != null) {
+ mCurrentDialog.dismiss();
+ mCurrentDialog = null;
+ }
Log.d(TAG, "onCreate() end");
}
// responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
Log.d(TAG, "onSaveInstanceState() start");
super.onSaveInstanceState(outState);
- outState.putString(UploadFilesActivity.EXTRA_DIRECTORY_PATH, mCurrentDir.getAbsolutePath());
+ outState.putString(UploadFilesActivity.KEY_DIRECTORY_PATH, mCurrentDir.getAbsolutePath());
Log.d(TAG, "onSaveInstanceState() end");
}
/**
* Performs corresponding action when user presses 'Cancel' or 'Upload' button
+ *
+ * TODO Make here the real request to the Upload service ; will require to receive the account and
+ * target folder where the upload must be done in the received intent.
*/
@Override
public void onClick(View v) {
finish();
} else if (v.getId() == R.id.upload_files_btn_upload) {
+ new CheckAvailableSpaceTask().execute();
+ }
+ }
+
+
+ /**
+ * Asynchronous task checking if there is space enough to copy all the files chosen
+ * to upload into the ownCloud local folder.
+ *
+ * Maybe an AsyncTask is not strictly necessary, but who really knows.
+ *
+ * @author David A. Velasco
+ */
+ private class CheckAvailableSpaceTask extends AsyncTask<Void, Void, Boolean> {
+
+ /**
+ * Updates the UI before trying the movement
+ */
+ @Override
+ protected void onPreExecute () {
+ /// progress dialog and disable 'Move' button
+ mCurrentDialog = IndeterminateProgressDialog.newInstance(R.string.wait_a_moment, false);
+ mCurrentDialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);
+ }
+
+
+ /**
+ * Checks the available space
+ *
+ * @return 'True' if there is space enough.
+ */
+ @Override
+ protected Boolean doInBackground(Void... params) {
+ String[] checkedFilePaths = mFileListFragment.getCheckedFilePaths();
+ long total = 0;
+ for (int i=0; i < checkedFilePaths.length ; i++) {
+ String localPath = checkedFilePaths[i];
+ File localFile = new File(localPath);
+ total += localFile.length();
+ }
+ String savePath = FileStorageUtils.getSavePath(mAccount.name);
+ File saveDir = new File(savePath);
+ return (saveDir.getUsableSpace() >= total);
+ }
+
+ /**
+ * Updates the activity UI after the check of space is done.
+ *
+ * If there is not space enough. shows a new dialog to query the user if wants to move the files instead
+ * of copy them.
+ *
+ * @param result 'True' when there is space enough to copy all the selected files.
+ */
+ @Override
+ protected void onPostExecute(Boolean result) {
+ mCurrentDialog.dismiss();
+ mCurrentDialog = null;
+
+ if (result) {
+ // return the list of selected files (success)
+ Intent data = new Intent();
+ data.putExtra(EXTRA_CHOSEN_FILES, mFileListFragment.getCheckedFilePaths());
+ setResult(RESULT_OK, data);
+ finish();
+
+ } else {
+ // show a dialog to query the user if wants to move the selected files to the ownCloud folder instead of copying
+ String[] args = {getString(R.string.app_name)};
+ ConfirmationDialogFragment dialog = ConfirmationDialogFragment.newInstance(R.string.upload_query_move_foreign_files, args, R.string.common_yes, -1, R.string.common_no);
+ dialog.setOnConfirmationListener(UploadFilesActivity.this);
+ mCurrentDialog = dialog;
+ mCurrentDialog.show(getSupportFragmentManager(), QUERY_TO_MOVE_DIALOG_TAG);
+ }
+ }
+ }
+
+ @Override
+ public void onConfirmation(String callerTag) {
+ Log.d(TAG, "Positive button in dialog was clicked; dialog tag is " + callerTag);
+ if (callerTag.equals(QUERY_TO_MOVE_DIALOG_TAG)) {
+ // return the list of selected files to the caller activity (success), signaling that they should be moved to the ownCloud folder, instead of copied
Intent data = new Intent();
data.putExtra(EXTRA_CHOSEN_FILES, mFileListFragment.getCheckedFilePaths());
- setResult(RESULT_OK, data);
+ setResult(RESULT_OK_AND_MOVE, data);
finish();
}
+ //mCurrentDialog.dismiss();
+ mCurrentDialog = null;
}
+
+
+ @Override
+ public void onNeutral(String callerTag) {
+ Log.d(TAG, "Phantom neutral button in dialog was clicked; dialog tag is " + callerTag);
+ //mCurrentDialog.dismiss();
+ mCurrentDialog = null;
+ }
+
+
+ @Override
+ public void onCancel(String callerTag) {
+ /// nothing to do; don't finish, let the user change the selection
+ Log.d(TAG, "Negative button in dialog was clicked; dialog tag is " + callerTag);
+ //mCurrentDialog.dismiss();
+ mCurrentDialog = null;
+ }
+
}