import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.res.Resources.NotFoundException;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.operations.CreateFolderOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.syncadapter.FileSyncAdapter;
import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
import com.owncloud.android.ui.fragment.FileFragment;
-import com.owncloud.android.ui.fragment.MoveFileListFragment;
+import com.owncloud.android.ui.fragment.OCFileListFragment;
import com.owncloud.android.utils.DisplayUtils;
+import com.owncloud.android.utils.ErrorMessageAdapter;
import com.owncloud.android.utils.Log_OC;
public class MoveActivity extends HookActivity implements FileFragment.ContainerActivity,
- OnClickListener{
+ 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;
}
if (!stateWasRecovered) {
- MoveFileListFragment listOfFolders = getListOfFilesFragment();
+ OCFileListFragment listOfFolders = getListOfFilesFragment();
listOfFolders.listDirectory(folder);
startSyncFolderOperation(folder);
}
private void createFragments() {
- MoveFileListFragment listOfFiles = new MoveFileListFragment();
+ OCFileListFragment listOfFiles = new OCFileListFragment();
+ Bundle args = new Bundle();
+ args.putBoolean(OCFileListFragment.ARG_JUST_FOLDERS, true);
+ args.putBoolean(OCFileListFragment.ARG_ALLOW_CONTEXTUAL_ACTIONS, false);
+ listOfFiles.setArguments(args);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, listOfFiles, TAG_LIST_OF_FOLDERS);
transaction.commit();
* loading or folder is empty
*/
private void setBackgroundText() {
- MoveFileListFragment MoveFileListFragment = getListOfFilesFragment();
- if (MoveFileListFragment != null) {
+ OCFileListFragment listFragment = getListOfFilesFragment();
+ if (listFragment != null) {
int message = R.string.file_list_loading;
if (!mSyncInProgress) {
// In case folder list is empty
message = R.string.file_list_empty_moving;
}
- MoveFileListFragment.setMessageForEmptyList(getString(message));
+ listFragment.setMessageForEmptyList(getString(message));
} else {
- Log.e(TAG, "MoveFileListFragment is null");
+ Log.e(TAG, "OCFileListFragment is null");
}
}
- private MoveFileListFragment getListOfFilesFragment() {
+ private OCFileListFragment getListOfFilesFragment() {
Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag(MoveActivity.TAG_LIST_OF_FOLDERS);
if (listOfFiles != null) {
- return (MoveFileListFragment)listOfFiles;
+ return (OCFileListFragment)listOfFiles;
}
Log_OC.wtf(TAG, "Access to unexisting list of files fragment!!");
return null;
}
protected void refreshListOfFilesFragment() {
- MoveFileListFragment fileListFragment = getListOfFilesFragment();
+ OCFileListFragment fileListFragment = getListOfFilesFragment();
if (fileListFragment != null) {
fileListFragment.listDirectory();
}
}
public void browseToRoot() {
- MoveFileListFragment listOfFiles = getListOfFilesFragment();
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
if (listOfFiles != null) { // should never be null, indeed
OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
listOfFiles.listDirectory(root);
@Override
public void onBackPressed() {
- MoveFileListFragment listOfFiles = getListOfFilesFragment();
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
if (listOfFiles != null) { // should never be null, indeed
int levelsUp = listOfFiles.onBrowseUp();
if (levelsUp == 0) {
if (v == mCancelBtn) {
finish();
} else if (v == mChooseBtn) {
- // TODO request to move, OR save selected folder as a result and let request for caller
- Toast.makeText( MoveActivity.this,
- "TODO: MOVE IMPLEMENTATION",
- Toast.LENGTH_LONG)
- .show();
+ Intent data = new Intent();
+ data.putExtra(EXTRA_CURRENT_FOLDER, getCurrentFolder());
+ setResult(RESULT_OK_AND_MOVE, data);
finish();
}
}
+ @Override
+ public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
+ super.onRemoteOperationFinish(operation, result);
+
+ if (operation instanceof CreateFolderOperation) {
+ onCreateFolderOperationFinish((CreateFolderOperation)operation, result);
+
+ }
+ }
+
+
+ /**
+ * Updates the view associated to the activity after the finish of an operation trying
+ * to create a new folder.
+ *
+ * @param operation Creation operation performed.
+ * @param result Result of the creation.
+ */
+ private void onCreateFolderOperationFinish(
+ CreateFolderOperation operation, RemoteOperationResult result
+ ) {
+
+ if (result.isSuccess()) {
+ dismissLoadingDialog();
+ refreshListOfFilesFragment();
+ } else {
+ dismissLoadingDialog();
+ try {
+ Toast msg = Toast.makeText(MoveActivity.this,
+ ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
+ msg.show();
+
+ } catch (NotFoundException e) {
+ Log_OC.e(TAG, "Error while trying to show fail message " , e);
+ }
+ }
+ }
+
+
+
private class SyncBroadcastReceiver extends BroadcastReceiver {
/**
}
if (synchFolderRemotePath != null && currentDir.getRemotePath().equals(synchFolderRemotePath)) {
- MoveFileListFragment fileListFragment = getListOfFilesFragment();
+ OCFileListFragment fileListFragment = getListOfFilesFragment();
if (fileListFragment != null) {
fileListFragment.listDirectory(currentDir);
}
}
+ @Override
+ public void onRefresh() {
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (listOfFiles != null) {
+ OCFile folder = listOfFiles.getCurrentFile();
+ if (folder != null) {
+ startSyncFolderOperation(folder);
+ }
+ }
+ }
+
}