mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:39:25 +03:00
Trigger MoveFileOperation when 'Choose' button is clicked
This commit is contained in:
parent
7d0e39f730
commit
59c0d67e68
5 changed files with 51 additions and 11 deletions
|
@ -265,7 +265,24 @@ public class FileOperationsHelper {
|
|||
} else if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) {
|
||||
uploaderBinder.cancel(account, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start move file operation
|
||||
* @param newfile File where it is going to be moved
|
||||
* @param currentFile File with the previous info
|
||||
*/
|
||||
public void moveFile(OCFile newfile, OCFile currentFile) {
|
||||
// Move files
|
||||
Intent service = new Intent(mFileActivity, OperationsService.class);
|
||||
service.setAction(OperationsService.ACTION_MOVE_FILE);
|
||||
service.putExtra(OperationsService.EXTRA_NEW_PARENT_PATH, newfile.getRemotePath());
|
||||
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, currentFile.getRemotePath());
|
||||
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
|
||||
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service);
|
||||
|
||||
mFileActivity.showLoadingDialog();
|
||||
}
|
||||
|
||||
|
||||
public long getOpIdWaitingFor() {
|
||||
|
|
|
@ -42,6 +42,7 @@ import com.owncloud.android.operations.common.SyncOperation;
|
|||
import com.owncloud.android.operations.CreateFolderOperation;
|
||||
import com.owncloud.android.operations.CreateShareOperation;
|
||||
import com.owncloud.android.operations.GetServerInfoOperation;
|
||||
import com.owncloud.android.operations.MoveFileOperation;
|
||||
import com.owncloud.android.operations.OAuth2GetAccessToken;
|
||||
import com.owncloud.android.operations.RemoveFileOperation;
|
||||
import com.owncloud.android.operations.RenameFileOperation;
|
||||
|
@ -79,6 +80,7 @@ public class OperationsService extends Service {
|
|||
public static final String EXTRA_CREATE_FULL_PATH = "CREATE_FULL_PATH";
|
||||
public static final String EXTRA_SYNC_FILE_CONTENTS = "SYNC_FILE_CONTENTS";
|
||||
public static final String EXTRA_RESULT = "RESULT";
|
||||
public static final String EXTRA_NEW_PARENT_PATH = "NEW_PARENT_PATH";
|
||||
|
||||
// TODO review if ALL OF THEM are necessary
|
||||
public static final String EXTRA_SUCCESS_IF_ABSENT = "SUCCESS_IF_ABSENT";
|
||||
|
@ -97,6 +99,7 @@ public class OperationsService extends Service {
|
|||
public static final String ACTION_REMOVE = "REMOVE";
|
||||
public static final String ACTION_CREATE_FOLDER = "CREATE_FOLDER";
|
||||
public static final String ACTION_SYNC_FILE = "SYNC_FILE";
|
||||
public static final String ACTION_MOVE_FILE = "MOVE_FILE";
|
||||
|
||||
public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED";
|
||||
public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED";
|
||||
|
@ -375,6 +378,11 @@ public class OperationsService extends Service {
|
|||
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
|
||||
boolean syncFileContents = operationIntent.getBooleanExtra(EXTRA_SYNC_FILE_CONTENTS, true);
|
||||
operation = new SynchronizeFileOperation(remotePath, account, syncFileContents, getApplicationContext());
|
||||
} else if (action.equals(ACTION_MOVE_FILE)) {
|
||||
// Move file/folder
|
||||
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
|
||||
String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
|
||||
operation = new MoveFileOperation(remotePath,newParentPath,account);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -136,6 +136,7 @@ OnSslUntrustedCertListener, SwipeRefreshLayout.OnRefreshListener {
|
|||
|
||||
private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
|
||||
private static final int ACTION_SELECT_MULTIPLE_FILES = 2;
|
||||
public static final int ACTION_MOVE_FILES = 3;
|
||||
|
||||
private static final String TAG = FileDisplayActivity.class.getSimpleName();
|
||||
|
||||
|
@ -552,6 +553,9 @@ OnSslUntrustedCertListener, SwipeRefreshLayout.OnRefreshListener {
|
|||
} else if (requestCode == ACTION_SELECT_MULTIPLE_FILES && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
|
||||
requestMultipleUpload(data, resultCode);
|
||||
|
||||
} else if (requestCode == ACTION_MOVE_FILES && (resultCode == RESULT_OK ||
|
||||
resultCode == MoveActivity.RESULT_OK_AND_MOVE)){
|
||||
requestMoveOperation(data, resultCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -632,6 +636,17 @@ OnSslUntrustedCertListener, SwipeRefreshLayout.OnRefreshListener {
|
|||
startService(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request the operation for moving the file/folder from one path to another
|
||||
*
|
||||
* @param data Intent received
|
||||
* @param resultCode Result code received
|
||||
*/
|
||||
private void requestMoveOperation(Intent data, int resultCode) {
|
||||
OCFile folderToMoveAt = (OCFile) data.getParcelableExtra(MoveActivity.EXTRA_CURRENT_FOLDER);
|
||||
getFileOperationsHelper().moveFile(folderToMoveAt, getCurrentDir());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
OCFileListFragment listOfFiles = getListOfFilesFragment();
|
||||
|
|
|
@ -44,7 +44,6 @@ import com.actionbarsherlock.view.MenuInflater;
|
|||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.actionbarsherlock.view.Window;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
|
@ -66,6 +65,10 @@ import com.owncloud.android.utils.Log_OC;
|
|||
|
||||
public class MoveActivity extends HookActivity implements FileFragment.ContainerActivity,
|
||||
OnClickListener, SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
public static final String EXTRA_CURRENT_FOLDER = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CURRENT_FOLDER";
|
||||
|
||||
public static final int RESULT_OK_AND_MOVE = 1;
|
||||
|
||||
private SyncBroadcastReceiver mSyncBroadcastReceiver;
|
||||
|
||||
|
@ -365,12 +368,10 @@ public class MoveActivity extends HookActivity implements FileFragment.Container
|
|||
if (v == mCancelBtn) {
|
||||
finish();
|
||||
} else if (v == mChooseBtn) {
|
||||
ComponentsGetter cg = (ComponentsGetter)getSherlockActivity();
|
||||
FileDataStorageManager storageManager = cg.getStorageManager();
|
||||
if (storageManager.getFileById(mTargetFile.getFileId()) != null) {
|
||||
cg.getFileOperationsHelper().removeFile(mTargetFile, false);
|
||||
}
|
||||
cg.getFileOperationsHelper.moveFile(m)
|
||||
Intent data = new Intent();
|
||||
data.putExtra(EXTRA_CURRENT_FOLDER, getCurrentFolder());
|
||||
setResult(RESULT_OK_AND_MOVE, data);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -321,9 +321,8 @@ public class OCFileListFragment extends ExtendedListFragment {
|
|||
return true;
|
||||
}
|
||||
case R.id.action_move: {
|
||||
Intent i = new Intent(getActivity(), MoveActivity.class);
|
||||
startActivity(i);
|
||||
|
||||
Intent action = new Intent(getActivity(), MoveActivity.class);
|
||||
getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_MOVE_FILES);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
|
|
Loading…
Reference in a new issue