--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012 Bartek Przybylski
+ *
+ * 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
+ * (at your option) any later version.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.operations;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;
+//import org.apache.jackrabbit.webdav.client.methods.MoveMethod;
+
+import android.util.Log;
+
+import com.owncloud.android.datamodel.DataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.files.services.FileDownloader;
+import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
+
+import eu.alefzero.webdav.WebdavClient;
+import eu.alefzero.webdav.WebdavUtils;
+
+/**
+ * Remote operation performing the rename of a remote file (or folder?) in the ownCloud server.
+ *
+ * @author David A. Velasco
+ */
+public class RenameFileOperation extends RemoteOperation {
+
+ private static final String TAG = RemoveFileOperation.class.getCanonicalName();
+
+ private static final int RENAME_READ_TIMEOUT = 10000;
+ private static final int RENAME_CONNECTION_TIMEOUT = 5000;
+
+
+ private OCFile mFile;
+ private String mNewName;
+ private DataStorageManager mStorageManager;
+
+
+ /**
+ * Constructor
+ *
+ * @param file OCFile instance describing the remote file or folder to rename
+ * @param newName New name to set as the name of file.
+ * @param storageManager Reference to the local database corresponding to the account where the file is contained.
+ */
+ public RenameFileOperation(OCFile file, String newName, DataStorageManager storageManager) {
+ mFile = file;
+ mNewName = newName;
+ mStorageManager = storageManager;
+ }
+
+ public OCFile getFile() {
+ return mFile;
+ }
+
+
+ /**
+ * Performs the rename operation.
+ *
+ * @param client Client object to communicate with the remote ownCloud server.
+ */
+ @Override
+ protected RemoteOperationResult run(WebdavClient client) {
+ RemoteOperationResult result = null;
+
+ LocalMoveMethod move = null;
+ //MoveMethod move = null; // TODO find out why not use this
+ String newRemotePath = null;
+ try {
+ if (mNewName.equals(mFile.getFileName())) {
+ return new RemoteOperationResult(ResultCode.OK);
+ }
+
+ newRemotePath = (new File(mFile.getRemotePath())).getParent() + mNewName;
+
+ // check if the new name is valid in the local file system
+ if (!isValidNewName()) {
+ return new RemoteOperationResult(ResultCode.INVALID_LOCAL_FILE_NAME);
+ }
+
+ // check if a remote file with the new name already exists
+ if (client.existsFile(newRemotePath)) {
+ return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
+ }
+ /*move = new MoveMethod( client.getBaseUri() + WebdavUtils.encodePath(mFile.getRemotePath()),
+ client.getBaseUri() + WebdavUtils.encodePath(newRemotePath),
+ false);*/
+ move = new LocalMoveMethod( client.getBaseUri() + WebdavUtils.encodePath(mFile.getRemotePath()),
+ client.getBaseUri() + WebdavUtils.encodePath(newRemotePath));
+ int status = client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT);
+ if (move.succeeded()) {
+
+ // create new OCFile instance for the renamed file
+ OCFile newFile = obtainUpdatedFile();
+ OCFile oldFile = mFile;
+ mFile = newFile;
+
+ // try to rename the local copy of the file
+ if (oldFile.isDown()) {
+ File f = new File(oldFile.getStoragePath());
+ String newStoragePath = f.getParent() + mNewName;
+ if (f.renameTo(new File(newStoragePath))) {
+ mFile.setStoragePath(newStoragePath);
+ }
+ // else - NOTHING: the link to the local file is kept although the local name can't be updated
+ // TODO - study conditions when this could be a problem
+ }
+
+ mStorageManager.removeFile(oldFile, false);
+ mStorageManager.saveFile(mFile);
+
+ }
+
+ move.getResponseBodyAsString(); // exhaust response, although not interesting
+ result = new RemoteOperationResult(move.succeeded(), status);
+ Log.i(TAG, "Rename " + mFile.getRemotePath() + " to " + newRemotePath + ": " + result.getLogMessage());
+
+ } catch (Exception e) {
+ result = new RemoteOperationResult(e);
+ Log.e(TAG, "Rename " + mFile.getRemotePath() + " to " + ((newRemotePath==null) ? mNewName : newRemotePath) + ": " + result.getLogMessage(), e);
+
+ } finally {
+ if (move != null)
+ move.releaseConnection();
+ }
+ return result;
+ }
+
+
+ /**
+ * Checks if the new name to set is valid in the file system
+ *
+ * The only way to be sure is trying to create a file with that name. It's made in the temporal directory
+ * for downloads, out of any account, and then removed.
+ *
+ * IMPORTANT: The test must be made in the same file system where files are download. The internal storage
+ * could be formatted with a different file system.
+ *
+ * @return 'True' if a temporal file named with the name to set could be created in the file system where
+ * local files are stored.
+ */
+ private boolean isValidNewName() {
+ // check tricky names
+ if (mNewName == null || mNewName.length() <= 0 || mNewName.contains(File.separator)) {
+ return false;
+ }
+ // create a test file
+ String tmpFolder = FileDownloader.getTemporalPath("");
+ File testFile = new File(tmpFolder + mNewName);
+ try {
+ testFile.createNewFile(); // return value is ignored; it could be 'false' because the file already existed, that doesn't invalidate the name
+ } catch (IOException e) {
+ Log.i(TAG, "Test for validity of name " + mNewName + " in the file system failed");
+ return false;
+ }
+ boolean result = (testFile.exists() && testFile.isFile());
+
+ // cleaning ; result is ignored, since there is not much we could do in case of failure, but repeat and repeat...
+ testFile.delete();
+
+ return result;
+ }
+
+
+ /**
+ * Creates a new OCFile for the new remote name of the renamed file.
+ *
+ * @return OCFile object with the same information than mFile, but the renamed remoteFile and the storagePath (empty)
+ */
+ private OCFile obtainUpdatedFile() {
+ OCFile file = new OCFile(mStorageManager.getFileById(mFile.getParentId()).getRemotePath() + mNewName);
+ file.setCreationTimestamp(mFile.getCreationTimestamp());
+ file.setFileId(mFile.getFileId());
+ file.setFileLength(mFile.getFileLength());
+ file.setKeepInSync(mFile.keepInSync());
+ file.setLastSyncDate(mFile.getLastSyncDate());
+ file.setMimetype(mFile.getMimetype());
+ file.setModificationTimestamp(mFile.getModificationTimestamp());
+ file.setParentId(mFile.getParentId());
+ return file;
+ }
+
+
+ // move operation - TODO: find out why org.apache.jackrabbit.webdav.client.methods.MoveMethod is not used instead ¿?
+ private class LocalMoveMethod extends DavMethodBase {
+
+ public LocalMoveMethod(String uri, String dest) {
+ super(uri);
+ addRequestHeader(new org.apache.commons.httpclient.Header("Destination", dest));
+ }
+
+ @Override
+ public String getName() {
+ return "MOVE";
+ }
+
+ @Override
+ protected boolean isSuccess(int status) {
+ return status == 201 || status == 204;
+ }
+
+ }
+
+
+}
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2011 Bartek Przybylski
+ *
+ * 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
+ * (at your option) any later version.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+package com.owncloud.android.ui.dialog;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnClickListener;
+import android.view.WindowManager.LayoutParams;
+import android.widget.Button;
+import android.widget.TextView;
+
+import com.actionbarsherlock.app.SherlockDialogFragment;
+import com.owncloud.android.R;
+
+
+/**
+ * Dialog to request the user about a certificate that could not be validated with the certificates store in the system.
+ *
+ * @author Bartek Przybylski
+ */
+public class EditNameDialog extends SherlockDialogFragment implements OnClickListener {
+
+ private String mNewFilename;
+ private boolean mResult;
+ private EditNameDialogListener mListener;
+
+ static public EditNameDialog newInstance(String filename) {
+ EditNameDialog f = new EditNameDialog();
+ Bundle args = new Bundle();
+ args.putString("filename", filename);
+ f.setArguments(args);
+ return f;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View v = inflater.inflate(R.layout.edit_box_dialog, container, false);
+
+ String currentName = getArguments().getString("filename");
+ if (currentName == null)
+ currentName = "";
+
+ ((Button)v.findViewById(R.id.cancel)).setOnClickListener(this);
+ ((Button)v.findViewById(R.id.ok)).setOnClickListener(this);
+ ((TextView)v.findViewById(R.id.user_input)).setText(currentName);
+ ((TextView)v.findViewById(R.id.user_input)).requestFocus();
+ getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+
+ mResult = false;
+ return v;
+ }
+
+ @Override
+ public void onClick(View view) {
+ switch (view.getId()) {
+ case R.id.ok: {
+ mNewFilename = ((TextView)getView().findViewById(R.id.user_input)).getText().toString();
+ mResult = true;
+ }
+ case R.id.cancel: { // fallthought
+ dismiss();
+ if (mListener != null)
+ mListener.onDismiss(this);
+ }
+ }
+ }
+
+ public void setOnDismissListener(EditNameDialogListener listener) {
+ mListener = listener;
+ }
+
+ public String getNewFilename() {
+ return mNewFilename;
+ }
+
+ // true if user clicked ok
+ public boolean getResult() {
+ return mResult;
+ }
+
+
+ public interface EditNameDialogListener {
+ public void onDismiss(EditNameDialog dialog);
+ }
+
+}
+
package com.owncloud.android.ui.fragment;\r
\r
import java.io.File;\r
-import java.io.IOException;\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
-import org.apache.commons.httpclient.HttpException;\r
import org.apache.commons.httpclient.methods.GetMethod;\r
import org.apache.commons.httpclient.methods.PostMethod;\r
import org.apache.commons.httpclient.methods.StringRequestEntity;\r
import org.apache.http.client.utils.URLEncodedUtils;\r
import org.apache.http.message.BasicNameValuePair;\r
import org.apache.http.protocol.HTTP;\r
-import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;\r
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;\r
import org.json.JSONObject;\r
\r
import android.content.Context;\r
import android.content.Intent;\r
import android.content.IntentFilter;\r
-import android.content.res.Resources.NotFoundException;\r
import android.graphics.Bitmap;\r
import android.graphics.BitmapFactory;\r
import android.graphics.BitmapFactory.Options;\r
import android.view.View;\r
import android.view.View.OnClickListener;\r
import android.view.ViewGroup;\r
-import android.view.WindowManager.LayoutParams;\r
import android.webkit.MimeTypeMap;\r
import android.widget.Button;\r
import android.widget.CheckBox;\r
import android.widget.TextView;\r
import android.widget.Toast;\r
\r
-import com.actionbarsherlock.app.SherlockDialogFragment;\r
import com.actionbarsherlock.app.SherlockFragment;\r
import com.owncloud.android.AccountUtils;\r
import com.owncloud.android.DisplayUtils;\r
import com.owncloud.android.operations.OnRemoteOperationListener;\r
import com.owncloud.android.operations.RemoteOperation;\r
import com.owncloud.android.operations.RemoteOperationResult;\r
+import com.owncloud.android.operations.RemoteOperationResult.ResultCode;\r
import com.owncloud.android.operations.RemoveFileOperation;\r
+import com.owncloud.android.operations.RenameFileOperation;\r
import com.owncloud.android.ui.activity.FileDetailActivity;\r
import com.owncloud.android.ui.activity.FileDisplayActivity;\r
import com.owncloud.android.ui.activity.TransferServiceGetter;\r
+import com.owncloud.android.ui.dialog.EditNameDialog;\r
+import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;\r
import com.owncloud.android.utils.OwnCloudVersion;\r
\r
import com.owncloud.android.R;\r
* \r
*/\r
public class FileDetailFragment extends SherlockFragment implements\r
- OnClickListener, ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener {\r
+ OnClickListener, ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener {\r
\r
public static final String EXTRA_FILE = "FILE";\r
public static final String EXTRA_ACCOUNT = "ACCOUNT";\r
break;\r
}\r
case R.id.fdRenameBtn: {\r
- EditNameFragment dialog = EditNameFragment.newInstance(mFile.getFileName());\r
- dialog.show(getFragmentManager(), "nameeditdialog");\r
+ EditNameDialog dialog = EditNameDialog.newInstance(mFile.getFileName());\r
dialog.setOnDismissListener(this);\r
+ dialog.show(getFragmentManager(), "nameeditdialog");\r
break;\r
} \r
case R.id.fdRemoveBtn: {\r
}\r
}\r
\r
- public void onDismiss(EditNameFragment dialog) {\r
- if (dialog instanceof EditNameFragment) {\r
- if (((EditNameFragment)dialog).getResult()) {\r
- String newFilename = ((EditNameFragment)dialog).getNewFilename();\r
- Log.d(TAG, "name edit dialog dismissed with new name " + newFilename);\r
- if (!newFilename.equals(mFile.getFileName())) {\r
- FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver());\r
- if (fdsm.getFileById(mFile.getFileId()) != null) {\r
- OCFile newFile = new OCFile(fdsm.getFileById(mFile.getParentId()).getRemotePath() + newFilename);\r
- newFile.setCreationTimestamp(mFile.getCreationTimestamp());\r
- newFile.setFileId(mFile.getFileId());\r
- newFile.setFileLength(mFile.getFileLength());\r
- newFile.setKeepInSync(mFile.keepInSync());\r
- newFile.setLastSyncDate(mFile.getLastSyncDate());\r
- newFile.setMimetype(mFile.getMimetype());\r
- newFile.setModificationTimestamp(mFile.getModificationTimestamp());\r
- newFile.setParentId(mFile.getParentId());\r
- boolean localRenameFails = false;\r
- if (mFile.isDown()) {\r
- File f = new File(mFile.getStoragePath());\r
- Log.e(TAG, f.getAbsolutePath());\r
- localRenameFails = !(f.renameTo(new File(f.getParent() + File.separator + newFilename)));\r
- Log.e(TAG, f.getParent() + File.separator + newFilename);\r
- newFile.setStoragePath(f.getParent() + File.separator + newFilename);\r
- }\r
- \r
- if (localRenameFails) {\r
- Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG); \r
- msg.show();\r
- \r
- } else {\r
- new Thread(new RenameRunnable(mFile, newFile, mAccount, new Handler())).start();\r
- boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;\r
- getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);\r
- }\r
-\r
- }\r
- }\r
- }\r
- } else {\r
- Log.e(TAG, "Unknown dialog instance passed to onDismissDalog: " + dialog.getClass().getCanonicalName());\r
- }\r
- \r
- }\r
- \r
- private class RenameRunnable implements Runnable {\r
- \r
- Account mAccount;\r
- OCFile mOld, mNew;\r
- Handler mHandler;\r
- \r
- public RenameRunnable(OCFile oldFile, OCFile newFile, Account account, Handler handler) {\r
- mOld = oldFile;\r
- mNew = newFile;\r
- mAccount = account;\r
- mHandler = handler;\r
- }\r
- \r
- public void run() {\r
+ public void onDismiss(EditNameDialog dialog) {\r
+ if (dialog.getResult()) {\r
+ String newFilename = dialog.getNewFilename();\r
+ Log.d(TAG, "name edit dialog dismissed with new name " + newFilename);\r
+ mLastRemoteOperation = new RenameFileOperation( mFile, \r
+ newFilename, \r
+ new FileDataStorageManager(mAccount, getActivity().getContentResolver()));\r
WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());\r
- AccountManager am = AccountManager.get(getSherlockActivity());\r
- String baseUrl = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL);\r
- OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION));\r
- String webdav_path = AccountUtils.getWebdavPath(ocv);\r
- Log.d("ASD", ""+baseUrl + webdav_path + WebdavUtils.encodePath(mOld.getRemotePath()));\r
-\r
- Log.e("ASD", Uri.parse(baseUrl).getPath() == null ? "" : Uri.parse(baseUrl).getPath() + webdav_path + WebdavUtils.encodePath(mNew.getRemotePath()));\r
- LocalMoveMethod move = new LocalMoveMethod(baseUrl + webdav_path + WebdavUtils.encodePath(mOld.getRemotePath()),\r
- Uri.parse(baseUrl).getPath() == null ? "" : Uri.parse(baseUrl).getPath() + webdav_path + WebdavUtils.encodePath(mNew.getRemotePath()));\r
- \r
- boolean success = false;\r
- try {\r
- int status = wc.executeMethod(move);\r
- success = move.succeeded();\r
- move.getResponseBodyAsString(); // exhaust response, although not interesting\r
- Log.d(TAG, "Move returned status: " + status);\r
- \r
- } catch (HttpException e) {\r
- Log.e(TAG, "HTTP Exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(), e);\r
- \r
- } catch (IOException e) {\r
- Log.e(TAG, "I/O Exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(), e);\r
- \r
- } catch (Exception e) {\r
- Log.e(TAG, "Unexpected exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(), e);\r
- \r
- } finally {\r
- move.releaseConnection();\r
- } \r
- \r
- if (success) {\r
- FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver());\r
- fdsm.removeFile(mOld, false);\r
- fdsm.saveFile(mNew);\r
- mFile = mNew;\r
- mHandler.post(new Runnable() {\r
- @Override\r
- public void run() { \r
- boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;\r
- getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);\r
- updateFileDetails(mFile, mAccount);\r
- mContainerActivity.onFileStateChanged();\r
- }\r
- });\r
- \r
- } else {\r
- mHandler.post(new Runnable() {\r
- @Override\r
- public void run() {\r
- // undo the local rename\r
- if (mNew.isDown()) {\r
- File f = new File(mNew.getStoragePath());\r
- if (!f.renameTo(new File(mOld.getStoragePath()))) {\r
- // the local rename undoing failed; last chance: save the new local storage path in the old file\r
- mFile.setStoragePath(mNew.getStoragePath());\r
- FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver());\r
- fdsm.saveFile(mFile);\r
- }\r
- }\r
- boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;\r
- getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);\r
- try {\r
- Toast msg = Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG); \r
- msg.show();\r
- \r
- } catch (NotFoundException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- });\r
- }\r
- }\r
- private class LocalMoveMethod extends DavMethodBase {\r
-\r
- public LocalMoveMethod(String uri, String dest) {\r
- super(uri);\r
- addRequestHeader(new org.apache.commons.httpclient.Header("Destination", dest));\r
- }\r
-\r
- @Override\r
- public String getName() {\r
- return "MOVE";\r
- }\r
-\r
- @Override\r
- protected boolean isSuccess(int status) {\r
- return status == 201 || status == 204;\r
- }\r
- \r
+ mLastRemoteOperation.execute(wc, this, mHandler);\r
+ boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;\r
+ getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);\r
}\r
}\r
\r
- private static class EditNameFragment extends SherlockDialogFragment implements OnClickListener {\r
-\r
- private String mNewFilename;\r
- private boolean mResult;\r
- private FileDetailFragment mListener;\r
- \r
- static public EditNameFragment newInstance(String filename) {\r
- EditNameFragment f = new EditNameFragment();\r
- Bundle args = new Bundle();\r
- args.putString("filename", filename);\r
- f.setArguments(args);\r
- return f;\r
- }\r
- \r
- @Override\r
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {\r
- View v = inflater.inflate(R.layout.edit_box_dialog, container, false);\r
-\r
- String currentName = getArguments().getString("filename");\r
- if (currentName == null)\r
- currentName = "";\r
- \r
- ((Button)v.findViewById(R.id.cancel)).setOnClickListener(this);\r
- ((Button)v.findViewById(R.id.ok)).setOnClickListener(this);\r
- ((TextView)v.findViewById(R.id.user_input)).setText(currentName);\r
- ((TextView)v.findViewById(R.id.user_input)).requestFocus();\r
- getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);\r
-\r
- mResult = false;\r
- return v;\r
- }\r
- \r
- @Override\r
- public void onClick(View view) {\r
- switch (view.getId()) {\r
- case R.id.ok: {\r
- mNewFilename = ((TextView)getView().findViewById(R.id.user_input)).getText().toString();\r
- mResult = true;\r
- }\r
- case R.id.cancel: { // fallthought\r
- dismiss();\r
- mListener.onDismiss(this);\r
- }\r
- }\r
- }\r
- \r
- void setOnDismissListener(FileDetailFragment listener) {\r
- mListener = listener;\r
- }\r
- \r
- public String getNewFilename() {\r
- return mNewFilename;\r
- }\r
- \r
- // true if user click ok\r
- public boolean getResult() {\r
- return mResult;\r
- }\r
- \r
- }\r
\r
class BitmapLoader extends AsyncTask<String, Void, Bitmap> {\r
@SuppressLint({ "NewApi", "NewApi", "NewApi" }) // to avoid Lint errors since Android SDK r20\r
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {\r
if (operation.equals(mLastRemoteOperation)) {\r
if (operation instanceof RemoveFileOperation) {\r
- boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;\r
- getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);\r
- if (result.isSuccess()) {\r
- Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);\r
- msg.show();\r
- if (inDisplayActivity) {\r
- // double pane\r
- FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();\r
- transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment\r
- transaction.commit();\r
- mContainerActivity.onFileStateChanged();\r
- } else {\r
- getActivity().finish();\r
- }\r
- \r
- } else {\r
- Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); \r
- msg.show();\r
- if (result.isSslRecoverableException()) {\r
- // TODO\r
- }\r
+ onRemoveFileOperationFinish((RemoveFileOperation)operation, result);\r
+ \r
+ } else if (operation instanceof RenameFileOperation) {\r
+ onRenameFileOperationFinish((RenameFileOperation)operation, result);\r
+ }\r
+ }\r
+ }\r
+ \r
+ \r
+ private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {\r
+ boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;\r
+ getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);\r
+ \r
+ if (result.isSuccess()) {\r
+ Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);\r
+ msg.show();\r
+ if (inDisplayActivity) {\r
+ // double pane\r
+ FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();\r
+ transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment\r
+ transaction.commit();\r
+ mContainerActivity.onFileStateChanged();\r
+ } else {\r
+ getActivity().finish();\r
+ }\r
+ \r
+ } else {\r
+ Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ if (result.isSslRecoverableException()) {\r
+ // TODO show the SSL warning dialog\r
+ }\r
+ }\r
+ }\r
+ \r
+ private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {\r
+ boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;\r
+ getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);\r
+ \r
+ if (result.isSuccess()) {\r
+ updateFileDetails(((RenameFileOperation)operation).getFile(), mAccount);\r
+ mContainerActivity.onFileStateChanged();\r
+ \r
+ } else {\r
+ if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {\r
+ Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ // TODO throw again the new rename dialog\r
+ } else {\r
+ Toast msg = Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ if (result.isSslRecoverableException()) {\r
+ // TODO show the SSL warning dialog\r
}\r
}\r
}\r