X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/7382fa84b046ebdd7fd79334ace16553b0bffc09..454f15138edf56b470b0cfe6fad7c09e46b9159b:/src/com/owncloud/android/ui/fragment/FileDetailFragment.java diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index 10b2fdb5..69715e02 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -18,11 +18,9 @@ package com.owncloud.android.ui.fragment; import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; @@ -32,8 +30,6 @@ import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; -import org.apache.jackrabbit.webdav.client.methods.DavMethodBase; -import org.apache.jackrabbit.webdav.client.methods.DeleteMethod; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; import org.json.JSONObject; @@ -46,7 +42,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.res.Resources.NotFoundException; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BitmapFactory.Options; @@ -62,7 +57,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.view.WindowManager.LayoutParams; import android.webkit.MimeTypeMap; import android.widget.Button; import android.widget.CheckBox; @@ -70,7 +64,6 @@ import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; -import com.actionbarsherlock.app.SherlockDialogFragment; import com.actionbarsherlock.app.SherlockFragment; import com.owncloud.android.AccountUtils; import com.owncloud.android.DisplayUtils; @@ -78,12 +71,22 @@ import com.owncloud.android.authenticator.AccountAuthenticator; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; +import com.owncloud.android.files.services.FileObserverService; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; +import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.network.OwnCloudClientUtils; +import com.owncloud.android.operations.OnRemoteOperationListener; +import com.owncloud.android.operations.RemoteOperation; +import com.owncloud.android.operations.RemoteOperationResult; +import com.owncloud.android.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.operations.RemoveFileOperation; +import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.ui.activity.FileDetailActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.activity.TransferServiceGetter; +import com.owncloud.android.ui.dialog.EditNameDialog; +import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener; import com.owncloud.android.utils.OwnCloudVersion; import com.owncloud.android.R; @@ -97,7 +100,7 @@ import eu.alefzero.webdav.WebdavUtils; * */ public class FileDetailFragment extends SherlockFragment implements - OnClickListener, ConfirmationDialogFragment.ConfirmationDialogFragmentListener { + OnClickListener, ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener { public static final String EXTRA_FILE = "FILE"; public static final String EXTRA_ACCOUNT = "ACCOUNT"; @@ -112,6 +115,9 @@ public class FileDetailFragment extends SherlockFragment implements private DownloadFinishReceiver mDownloadFinishReceiver; private UploadFinishReceiver mUploadFinishReceiver; + + private Handler mHandler; + private RemoteOperation mLastRemoteOperation; private static final String TAG = "FileDetailFragment"; public static final String FTAG = "FileDetails"; @@ -148,6 +154,13 @@ public class FileDetailFragment extends SherlockFragment implements } } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mHandler = new Handler(); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -187,7 +200,7 @@ public class FileDetailFragment extends SherlockFragment implements try { mContainerActivity = (ContainerActivity) activity; } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() + " must implement " + FileDetailFragment.ContainerActivity.class.getCanonicalName()); + throw new ClassCastException(activity.toString() + " must implement " + FileDetailFragment.ContainerActivity.class.getSimpleName()); } } @@ -246,6 +259,7 @@ public class FileDetailFragment extends SherlockFragment implements case R.id.fdDownloadBtn: { //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath())) { FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); + FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) { downloaderBinder.cancel(mAccount, mFile); if (mFile.isDown()) { @@ -253,6 +267,26 @@ public class FileDetailFragment extends SherlockFragment implements } else { setButtonsForRemote(); } + + } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) { + uploaderBinder.cancel(mAccount, mFile); + if (!mFile.fileExists()) { + // TODO make something better + if (getActivity() instanceof FileDisplayActivity) { + // double pane + FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); + transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FTAG); // empty FileDetailFragment + transaction.commit(); + mContainerActivity.onFileStateChanged(); + } else { + getActivity().finish(); + } + + } else if (mFile.isDown()) { + setButtonsForDown(); + } else { + setButtonsForRemote(); + } } else { Intent i = new Intent(getActivity(), FileDownloader.class); @@ -280,7 +314,7 @@ public class FileDetailFragment extends SherlockFragment implements } else { mContainerActivity.onFileStateChanged(); // put inside 'else' to not call it twice (here, and in the virtual click on fdDownloadBtn) } - /* + Intent intent = new Intent(getActivity().getApplicationContext(), FileObserverService.class); intent.putExtra(FileObserverService.KEY_FILE_CMD, @@ -288,14 +322,15 @@ public class FileDetailFragment extends SherlockFragment implements FileObserverService.CMD_ADD_OBSERVED_FILE: FileObserverService.CMD_DEL_OBSERVED_FILE)); intent.putExtra(FileObserverService.KEY_CMD_ARG, mFile.getStoragePath()); + Log.e(TAG, "starting observer service"); getActivity().startService(intent); - */ + break; } case R.id.fdRenameBtn: { - EditNameFragment dialog = EditNameFragment.newInstance(mFile.getFileName()); - dialog.show(getFragmentManager(), "nameeditdialog"); + EditNameDialog dialog = EditNameDialog.newInstance(mFile.getFileName()); dialog.setOnDismissListener(this); + dialog.show(getFragmentManager(), "nameeditdialog"); break; } case R.id.fdRemoveBtn: { @@ -366,7 +401,12 @@ public class FileDetailFragment extends SherlockFragment implements if (callerTag.equals(FTAG_CONFIRMATION)) { FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); if (fdsm.getFileById(mFile.getFileId()) != null) { - new Thread(new RemoveRunnable(mFile, mAccount, new Handler())).start(); + mLastRemoteOperation = new RemoveFileOperation( mFile, + true, + new FileDataStorageManager(mAccount, getActivity().getContentResolver())); + WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext()); + mLastRemoteOperation.execute(wc, this, mHandler); + boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); } @@ -445,7 +485,8 @@ public class FileDetailFragment extends SherlockFragment implements // configure UI for depending upon local state of the file //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) { FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); - if ((downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) { + FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); + if ((downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) { setButtonsForTransferring(); } else if (mFile.isDown()) { @@ -532,6 +573,7 @@ public class FileDetailFragment extends SherlockFragment implements ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false); ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(false); ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(false); + getView().findViewById(R.id.fdKeepInSync).setEnabled(false); } } @@ -547,6 +589,7 @@ public class FileDetailFragment extends SherlockFragment implements ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(true); ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true); ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true); + getView().findViewById(R.id.fdKeepInSync).setEnabled(true); } } @@ -561,6 +604,7 @@ public class FileDetailFragment extends SherlockFragment implements ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false); ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true); ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true); + getView().findViewById(R.id.fdKeepInSync).setEnabled(true); } } @@ -766,309 +810,20 @@ public class FileDetailFragment extends SherlockFragment implements } } - public void onDismiss(EditNameFragment dialog) { - if (dialog instanceof EditNameFragment) { - if (((EditNameFragment)dialog).getResult()) { - String newFilename = ((EditNameFragment)dialog).getNewFilename(); - Log.d(TAG, "name edit dialog dismissed with new name " + newFilename); - if (!newFilename.equals(mFile.getFileName())) { - FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); - if (fdsm.getFileById(mFile.getFileId()) != null) { - OCFile newFile = new OCFile(fdsm.getFileById(mFile.getParentId()).getRemotePath() + newFilename); - newFile.setCreationTimestamp(mFile.getCreationTimestamp()); - newFile.setFileId(mFile.getFileId()); - newFile.setFileLength(mFile.getFileLength()); - newFile.setKeepInSync(mFile.keepInSync()); - newFile.setLastSyncDate(mFile.getLastSyncDate()); - newFile.setMimetype(mFile.getMimetype()); - newFile.setModificationTimestamp(mFile.getModificationTimestamp()); - newFile.setParentId(mFile.getParentId()); - boolean localRenameFails = false; - if (mFile.isDown()) { - File f = new File(mFile.getStoragePath()); - Log.e(TAG, f.getAbsolutePath()); - localRenameFails = !(f.renameTo(new File(f.getParent() + File.separator + newFilename))); - Log.e(TAG, f.getParent() + File.separator + newFilename); - newFile.setStoragePath(f.getParent() + File.separator + newFilename); - } - - if (localRenameFails) { - Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG); - msg.show(); - - } else { - new Thread(new RenameRunnable(mFile, newFile, mAccount, new Handler())).start(); - boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; - getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); - } - - } - } - } - } else { - Log.e(TAG, "Unknown dialog instance passed to onDismissDalog: " + dialog.getClass().getCanonicalName()); - } - - } - - private class RenameRunnable implements Runnable { - - Account mAccount; - OCFile mOld, mNew; - Handler mHandler; - - public RenameRunnable(OCFile oldFile, OCFile newFile, Account account, Handler handler) { - mOld = oldFile; - mNew = newFile; - mAccount = account; - mHandler = handler; - } - - public void run() { + public void onDismiss(EditNameDialog dialog) { + if (dialog.getResult()) { + String newFilename = dialog.getNewFilename(); + Log.d(TAG, "name edit dialog dismissed with new name " + newFilename); + mLastRemoteOperation = new RenameFileOperation( mFile, + newFilename, + new FileDataStorageManager(mAccount, getActivity().getContentResolver())); WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext()); - AccountManager am = AccountManager.get(getSherlockActivity()); - String baseUrl = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL); - OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION)); - String webdav_path = AccountUtils.getWebdavPath(ocv); - Log.d("ASD", ""+baseUrl + webdav_path + WebdavUtils.encodePath(mOld.getRemotePath())); - - Log.e("ASD", Uri.parse(baseUrl).getPath() == null ? "" : Uri.parse(baseUrl).getPath() + webdav_path + WebdavUtils.encodePath(mNew.getRemotePath())); - LocalMoveMethod move = new LocalMoveMethod(baseUrl + webdav_path + WebdavUtils.encodePath(mOld.getRemotePath()), - Uri.parse(baseUrl).getPath() == null ? "" : Uri.parse(baseUrl).getPath() + webdav_path + WebdavUtils.encodePath(mNew.getRemotePath())); - - boolean success = false; - try { - int status = wc.executeMethod(move); - success = move.succeeded(); - move.getResponseBodyAsString(); // exhaust response, although not interesting - Log.d(TAG, "Move returned status: " + status); - - } catch (HttpException e) { - Log.e(TAG, "HTTP Exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(), e); - - } catch (IOException e) { - Log.e(TAG, "I/O Exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(), e); - - } catch (Exception e) { - Log.e(TAG, "Unexpected exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(), e); - - } finally { - move.releaseConnection(); - } - - if (success) { - FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); - fdsm.removeFile(mOld, false); - fdsm.saveFile(mNew); - mFile = mNew; - mHandler.post(new Runnable() { - @Override - public void run() { - boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; - getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); - updateFileDetails(mFile, mAccount); - mContainerActivity.onFileStateChanged(); - } - }); - - } else { - mHandler.post(new Runnable() { - @Override - public void run() { - // undo the local rename - if (mNew.isDown()) { - File f = new File(mNew.getStoragePath()); - if (!f.renameTo(new File(mOld.getStoragePath()))) { - // the local rename undoing failed; last chance: save the new local storage path in the old file - mFile.setStoragePath(mNew.getStoragePath()); - FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); - fdsm.saveFile(mFile); - } - } - boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; - getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); - try { - Toast msg = Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG); - msg.show(); - - } catch (NotFoundException e) { - e.printStackTrace(); - } - } - }); - } - } - 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; - } - - } - } - - private static class EditNameFragment extends SherlockDialogFragment implements OnClickListener { - - private String mNewFilename; - private boolean mResult; - private FileDetailFragment mListener; - - static public EditNameFragment newInstance(String filename) { - EditNameFragment f = new EditNameFragment(); - 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; + mLastRemoteOperation.execute(wc, this, mHandler); + boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; + getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); } - - @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(); - mListener.onDismiss(this); - } - } - } - - void setOnDismissListener(FileDetailFragment listener) { - mListener = listener; - } - - public String getNewFilename() { - return mNewFilename; - } - - // true if user click ok - public boolean getResult() { - return mResult; - } - } - private class RemoveRunnable implements Runnable { - - Account mAccount; - OCFile mFileToRemove; - Handler mHandler; - - public RemoveRunnable(OCFile fileToRemove, Account account, Handler handler) { - mFileToRemove = fileToRemove; - mAccount = account; - mHandler = handler; - } - - public void run() { - WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext()); - AccountManager am = AccountManager.get(getSherlockActivity()); - String baseUrl = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL); - OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION)); - String webdav_path = AccountUtils.getWebdavPath(ocv); - Log.d("ASD", ""+baseUrl + webdav_path + WebdavUtils.encodePath(mFileToRemove.getRemotePath())); - - DeleteMethod delete = new DeleteMethod(baseUrl + webdav_path + WebdavUtils.encodePath(mFileToRemove.getRemotePath())); - - boolean success = false; - int status = -1; - try { - status = wc.executeMethod(delete); - success = (delete.succeeded()); - delete.getResponseBodyAsString(); // exhaust the response, although not interesting - Log.d(TAG, "Delete: returned status " + status); - - } catch (HttpException e) { - Log.e(TAG, "HTTP Exception removing file " + mFileToRemove.getRemotePath(), e); - - } catch (IOException e) { - Log.e(TAG, "I/O Exception removing file " + mFileToRemove.getRemotePath(), e); - - } catch (Exception e) { - Log.e(TAG, "Unexpected exception removing file " + mFileToRemove.getRemotePath(), e); - - } finally { - delete.releaseConnection(); - } - - if (success) { - FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); - fdsm.removeFile(mFileToRemove, true); - mHandler.post(new Runnable() { - @Override - public void run() { - boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; - getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); - try { - Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG); - msg.show(); - if (inDisplayActivity) { - // double pane - FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); - transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment - transaction.commit(); - mContainerActivity.onFileStateChanged(); - - } else { - getActivity().finish(); - } - - } catch (NotFoundException e) { - e.printStackTrace(); - } - } - }); - - } else { - mHandler.post(new Runnable() { - @Override - public void run() { - boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; - getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); - try { - Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); - msg.show(); - - } catch (NotFoundException e) { - e.printStackTrace(); - } - } - }); - } - } - - } class BitmapLoader extends AsyncTask { @SuppressLint({ "NewApi", "NewApi", "NewApi" }) // to avoid Lint errors since Android SDK r20 @@ -1143,6 +898,71 @@ public class FileDetailFragment extends SherlockFragment implements } } + + /** + * {@inheritDoc} + */ + @Override + public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { + if (operation.equals(mLastRemoteOperation)) { + if (operation instanceof RemoveFileOperation) { + onRemoveFileOperationFinish((RemoveFileOperation)operation, result); + + } else if (operation instanceof RenameFileOperation) { + onRenameFileOperationFinish((RenameFileOperation)operation, result); + } + } + } + + + private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) { + boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; + getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); + + if (result.isSuccess()) { + Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG); + msg.show(); + if (inDisplayActivity) { + // double pane + FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); + transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment + transaction.commit(); + mContainerActivity.onFileStateChanged(); + } else { + getActivity().finish(); + } + + } else { + Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); + msg.show(); + if (result.isSslRecoverableException()) { + // TODO show the SSL warning dialog + } + } + } + + private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) { + boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; + getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); + + if (result.isSuccess()) { + updateFileDetails(((RenameFileOperation)operation).getFile(), mAccount); + mContainerActivity.onFileStateChanged(); + + } else { + if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) { + Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG); + msg.show(); + // TODO throw again the new rename dialog + } else { + Toast msg = Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG); + msg.show(); + if (result.isSslRecoverableException()) { + // TODO show the SSL warning dialog + } + } + } + } }