X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/37f0586c47ab5c2b8f47a4b286b5c0df06b27c12..18d4ff203f1bf39aa439a7580394f2bb05be439f:/src/com/owncloud/android/ui/activity/FileDisplayActivity.java diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index cfd9ae5e..c4cbe978 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1,9 +1,10 @@ /* ownCloud Android client application * Copyright (C) 2011 Bartek Przybylski + * Copyright (C) 2012-2013 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or + * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -65,7 +66,7 @@ import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.Window; import com.owncloud.android.AccountUtils; -import com.owncloud.android.authenticator.AccountAuthenticator; +import com.owncloud.android.authentication.AccountAuthenticator; import com.owncloud.android.datamodel.DataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; @@ -74,7 +75,7 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileObserverService; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; -import com.owncloud.android.network.OwnCloudClientUtils; +import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.operations.OnRemoteOperationListener; import com.owncloud.android.operations.RemoteOperation; import com.owncloud.android.operations.RemoteOperationResult; @@ -90,7 +91,6 @@ import com.owncloud.android.ui.fragment.FileDetailFragment; import com.owncloud.android.ui.fragment.OCFileListFragment; import com.owncloud.android.R; -import eu.alefzero.webdav.WebdavClient; /** * Displays, what files the user has available in his ownCloud. @@ -118,6 +118,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements private OCFileListFragment mFileList; private boolean mDualPane; + private Handler mHandler; private static final int DIALOG_SETUP_ACCOUNT = 0; private static final int DIALOG_CREATE_DIR = 1; @@ -140,12 +141,14 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements public void onCreate(Bundle savedInstanceState) { Log.d(getClass().toString(), "onCreate() start"); super.onCreate(savedInstanceState); + + mHandler = new Handler(); /// Load of parameters from received intent - mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); // no check necessary, mCurrenDir == null if the parameter is not in the intent Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT); - if (account != null) - AccountUtils.setCurrentOwnCloudAccount(this, account.name); + if (account != null && AccountUtils.setCurrentOwnCloudAccount(this, account.name)) { + mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); + } /// Load of saved instance state: keep this always before initDataFromCurrentAccount() if(savedInstanceState != null) { @@ -186,7 +189,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements // Drop-down navigation mDirectories = new CustomArrayAdapter(this, R.layout.sherlock_spinner_dropdown_item); OCFile currFile = mCurrentDir; - while(currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) { + while(mStorageManager != null && currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) { mDirectories.add(currFile.getFileName()); currFile = mStorageManager.getFileById(currFile.getParentId()); } @@ -211,7 +214,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements // show changelog, if needed - showChangeLog(); + //showChangeLog(); Log.d(getClass().toString(), "onCreate() end"); } @@ -248,7 +251,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements */ private void createFirstAccount() { Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT); - intent.putExtra(android.provider.Settings.EXTRA_AUTHORITIES, new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE }); + intent.putExtra(android.provider.Settings.EXTRA_AUTHORITIES, new String[] { AccountAuthenticator.AUTHORITY }); startActivity(intent); // the new activity won't be created until this.onStart() and this.onResume() are finished; } @@ -377,12 +380,12 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } private void startSynchronization() { - ContentResolver.cancelSync(null, AccountAuthenticator.AUTH_TOKEN_TYPE); // cancel the current synchronizations of any ownCloud account + ContentResolver.cancelSync(null, AccountAuthenticator.AUTHORITY); // cancel the current synchronizations of any ownCloud account Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync( AccountUtils.getCurrentOwnCloudAccount(this), - AccountAuthenticator.AUTH_TOKEN_TYPE, bundle); + AccountAuthenticator.AUTHORITY, bundle); } @@ -685,8 +688,12 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements // Create directory path += directoryName + OCFile.PATH_SEPARATOR; - Thread thread = new Thread(new DirectoryCreator(path, AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this), new Handler())); - thread.start(); + RemoteOperation operation = new CreateFolderOperation(path, mCurrentDir.getFileId(), mStorageManager); + operation.execute( AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this), + FileDisplayActivity.this, + FileDisplayActivity.this, + mHandler, + FileDisplayActivity.this); dialog.dismiss(); @@ -804,56 +811,6 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements return !mDirectories.isEmpty(); } - private class DirectoryCreator implements Runnable { - private String mTargetPath; - private Account mAccount; - private Handler mHandler; - - public DirectoryCreator(String targetPath, Account account, Handler handler) { - mTargetPath = targetPath; - mAccount = account; - mHandler = handler; - } - - @Override - public void run() { - WebdavClient wdc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext()); - boolean created = wdc.createDirectory(mTargetPath); - if (created) { - mHandler.post(new Runnable() { - @Override - public void run() { - dismissDialog(DIALOG_SHORT_WAIT); - - // Save new directory in local database - OCFile newDir = new OCFile(mTargetPath); - newDir.setMimetype("DIR"); - newDir.setParentId(mCurrentDir.getFileId()); - mStorageManager.saveFile(newDir); - - // Display the new folder right away - mFileList.listDirectory(); - } - }); - - } else { - mHandler.post(new Runnable() { - @Override - public void run() { - dismissDialog(DIALOG_SHORT_WAIT); - try { - Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG); - msg.show(); - - } catch (NotFoundException e) { - Log.e(TAG, "Error while trying to show fail message " , e); - } - } - }); - } - } - - } // Custom array adapter to override text colors private class CustomArrayAdapter extends ArrayAdapter { @@ -1154,6 +1111,32 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } else if (operation instanceof SynchronizeFileOperation) { onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result); + + } else if (operation instanceof CreateFolderOperation) { + onCreateFolderOperationFinish((CreateFolderOperation)operation, result); + } + } + + /** + * Updates the view associated to the activity after the finish of an operation trying 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()) { + dismissDialog(DIALOG_SHORT_WAIT); + mFileList.listDirectory(); + + } else { + dismissDialog(DIALOG_SHORT_WAIT); + try { + Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG); + msg.show(); + + } catch (NotFoundException e) { + Log.e(TAG, "Error while trying to show fail message " , e); + } } }