-import android.widget.Button;
-import android.widget.Toast;
-
-import com.actionbarsherlock.app.ActionBar;
-import com.actionbarsherlock.view.Menu;
-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.OCFile;
-import com.owncloud.android.lib.common.OwnCloudAccount;
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
-import com.owncloud.android.lib.common.OwnCloudCredentials;
-import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
-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.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.utils.DisplayUtils;
-import com.owncloud.android.utils.Log_OC;
-
-public class MoveActivity extends HookActivity implements FileFragment.ContainerActivity,
- OnClickListener{
-
- private SyncBroadcastReceiver mSyncBroadcastReceiver;
-
- private static final String TAG = MoveActivity.class.getSimpleName();
-
- private static final String TAG_LIST_OF_FOLDERS = "LIST_OF_FOLDERS";
-
- private boolean mSyncInProgress = false;
-
- private Button mCancelBtn;
- private Button mChooseBtn;
-
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- Log_OC.d(TAG, "onCreate() start");
- requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
-
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.files_move);
-
- if (savedInstanceState == null) {
- createFragments();
- }
-
- // sets callback listeners for UI elements
- initControls();
-
- // Action bar setup
- ActionBar actionBar = getSupportActionBar();
- actionBar.setDisplayShowTitleEnabled(true);
- actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
- setSupportProgressBarIndeterminateVisibility(mSyncInProgress);
- // always AFTER setContentView(...) ; to work around bug in its implementation
-
- // sets message for empty list of folders
- setBackgroundText();
-
- Log_OC.d(TAG, "onCreate() end");
-
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId());
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- }
-
- /**
- * Called when the ownCloud {@link Account} associated to the Activity was just updated.
- */
- @Override
- protected void onAccountSet(boolean stateWasRecovered) {
- super.onAccountSet(stateWasRecovered);
- if (getAccount() != null) {
-
- updateFileFromDB();
-
- OCFile folder = getFile();
- if (folder == null || !folder.isFolder()) {
- // fall back to root folder
- setFile(getStorageManager().getFileByPath(OCFile.ROOT_PATH));
- folder = getFile();
- }
-
- if (!stateWasRecovered) {
- MoveFileListFragment listOfFolders = getListOfFilesFragment();
- listOfFolders.listDirectory(folder);
-
- startSyncFolderOperation(folder);
- }
-
- updateNavigationElementsInActionBar();
- }
- }
-
- private void createFragments() {
- MoveFileListFragment listOfFiles = new MoveFileListFragment();
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.add(R.id.fragment_container, listOfFiles, TAG_LIST_OF_FOLDERS);
- transaction.commit();
- }
-
- /**
- * Show a text message on screen view for notifying user if content is
- * loading or folder is empty
- */
- private void setBackgroundText() {
- MoveFileListFragment MoveFileListFragment = getListOfFilesFragment();
- if (MoveFileListFragment != 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));
- } else {
- Log.e(TAG, "MoveFileListFragment is null");
- }
- }
-
- private MoveFileListFragment getListOfFilesFragment() {
- Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag(MoveActivity.TAG_LIST_OF_FOLDERS);
- if (listOfFiles != null) {
- return (MoveFileListFragment)listOfFiles;
- }
- Log_OC.wtf(TAG, "Access to unexisting list of files fragment!!");
- return null;
- }
-
-
- /**
- * {@inheritDoc}
- *
- * Updates action bar and second fragment, if in dual pane mode.
- */
- @Override
- public void onBrowsedDownTo(OCFile directory) {
- setFile(directory);
- updateNavigationElementsInActionBar();
- // Sync Folder
- startSyncFolderOperation(directory);
-
- }
-
-
- public void startSyncFolderOperation(OCFile folder) {
- long currentSyncTime = System.currentTimeMillis();
-
- mSyncInProgress = true;
-
- // perform folder synchronization
- RemoteOperation synchFolderOp = new SynchronizeFolderOperation( folder,
- currentSyncTime,
- false,
- getFileOperationsHelper().isSharedSupported(),
- getStorageManager(),
- getAccount(),
- getApplicationContext()
- );
- synchFolderOp.execute(getAccount(), this, null, null);
-
- setSupportProgressBarIndeterminateVisibility(true);
-
- setBackgroundText();
- }