X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/f63996d115bffe07cc59a376866e39402826de8b..a6afe6efd24d35d02dc9720432a2daa47b58ffdd:/src/com/owncloud/android/ui/activity/MoveActivity.java diff --git a/src/com/owncloud/android/ui/activity/MoveActivity.java b/src/com/owncloud/android/ui/activity/MoveActivity.java index 89de5e9a..07f25bb5 100644 --- a/src/com/owncloud/android/ui/activity/MoveActivity.java +++ b/src/com/owncloud/android/ui/activity/MoveActivity.java @@ -1,3 +1,20 @@ +/* ownCloud Android client application + * Copyright (C) 2012-2014 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package com.owncloud.android.ui.activity; import java.io.IOException; @@ -10,9 +27,11 @@ import android.content.BroadcastReceiver; 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; @@ -34,16 +53,22 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundExce 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; @@ -116,7 +141,7 @@ public class MoveActivity extends HookActivity implements FileFragment.Container } if (!stateWasRecovered) { - MoveFileListFragment listOfFolders = getListOfFilesFragment(); + OCFileListFragment listOfFolders = getListOfFilesFragment(); listOfFolders.listDirectory(folder); startSyncFolderOperation(folder); @@ -127,7 +152,11 @@ public class MoveActivity extends HookActivity implements FileFragment.Container } 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(); @@ -138,23 +167,23 @@ public class MoveActivity extends HookActivity implements FileFragment.Container * 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; @@ -280,14 +309,14 @@ public class MoveActivity extends HookActivity implements FileFragment.Container } 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); @@ -299,7 +328,7 @@ public class MoveActivity extends HookActivity implements FileFragment.Container @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) { @@ -339,16 +368,55 @@ public class MoveActivity extends HookActivity implements FileFragment.Container 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 { /** @@ -388,7 +456,7 @@ public class MoveActivity extends HookActivity implements FileFragment.Container } if (synchFolderRemotePath != null && currentDir.getRemotePath().equals(synchFolderRemotePath)) { - MoveFileListFragment fileListFragment = getListOfFilesFragment(); + OCFileListFragment fileListFragment = getListOfFilesFragment(); if (fileListFragment != null) { fileListFragment.listDirectory(currentDir); } @@ -481,4 +549,15 @@ public class MoveActivity extends HookActivity implements FileFragment.Container } + @Override + public void onRefresh() { + OCFileListFragment listOfFiles = getListOfFilesFragment(); + if (listOfFiles != null) { + OCFile folder = listOfFiles.getCurrentFile(); + if (folder != null) { + startSyncFolderOperation(folder); + } + } + } + }