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.DeleteMethod;\r
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;\r
-import org.json.JSONException;\r
import org.json.JSONObject;\r
\r
import android.accounts.Account;\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.datamodel.FileDataStorageManager;\r
import com.owncloud.android.datamodel.OCFile;\r
import com.owncloud.android.files.services.FileDownloader;\r
+import com.owncloud.android.files.services.FileObserverService;\r
import com.owncloud.android.files.services.FileUploader;\r
+import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;\r
+import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
+import com.owncloud.android.network.OwnCloudClientUtils;\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.operations.SynchronizeFileOperation;\r
+import com.owncloud.android.ui.activity.ConflictsResolveActivity;\r
import com.owncloud.android.ui.activity.FileDetailActivity;\r
import com.owncloud.android.ui.activity.FileDisplayActivity;\r
-import com.owncloud.android.utils.OwnCloudClientUtils;\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 {\r
+ OnClickListener, ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener {\r
\r
public static final String EXTRA_FILE = "FILE";\r
public static final String EXTRA_ACCOUNT = "ACCOUNT";\r
private View mView;\r
private OCFile mFile;\r
private Account mAccount;\r
+ private FileDataStorageManager mStorageManager;\r
private ImageView mPreview;\r
\r
private DownloadFinishReceiver mDownloadFinishReceiver;\r
private UploadFinishReceiver mUploadFinishReceiver;\r
+ \r
+ private Handler mHandler;\r
+ private RemoteOperation mLastRemoteOperation;\r
\r
- private static final String TAG = "FileDetailFragment";\r
+ private static final String TAG = FileDetailFragment.class.getSimpleName();\r
public static final String FTAG = "FileDetails"; \r
public static final String FTAG_CONFIRMATION = "REMOVE_CONFIRMATION_FRAGMENT";\r
\r
public FileDetailFragment() {\r
mFile = null;\r
mAccount = null;\r
+ mStorageManager = null;\r
mLayout = R.layout.file_details_empty;\r
}\r
\r
* @param fileToDetail An {@link OCFile} to show in the fragment\r
* @param ocAccount An ownCloud account; needed to start downloads\r
*/\r
- public FileDetailFragment(OCFile fileToDetail, Account ocAccount){\r
+ public FileDetailFragment(OCFile fileToDetail, Account ocAccount) {\r
mFile = fileToDetail;\r
mAccount = ocAccount;\r
+ mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment \r
mLayout = R.layout.file_details_empty;\r
\r
if(fileToDetail != null && ocAccount != null) {\r
}\r
}\r
\r
-\r
- /**\r
- * {@inheritDoc}\r
- */\r
+ \r
@Override\r
- public void onAttach(Activity activity) {\r
- super.onAttach(activity);\r
- try {\r
- mContainerActivity = (ContainerActivity) activity;\r
- } catch (ClassCastException e) {\r
- throw new ClassCastException(activity.toString() + " must implement FileListFragment.ContainerActivity");\r
- }\r
+ public void onCreate(Bundle savedInstanceState) {\r
+ super.onCreate(savedInstanceState);\r
+ mHandler = new Handler();\r
}\r
\r
- \r
+\r
@Override\r
public View onCreateView(LayoutInflater inflater, ViewGroup container,\r
Bundle savedInstanceState) {\r
}\r
\r
\r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void onAttach(Activity activity) {\r
+ super.onAttach(activity);\r
+ try {\r
+ mContainerActivity = (ContainerActivity) activity;\r
+ } catch (ClassCastException e) {\r
+ throw new ClassCastException(activity.toString() + " must implement " + FileDetailFragment.ContainerActivity.class.getSimpleName());\r
+ }\r
+ }\r
+ \r
+ \r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void onActivityCreated(Bundle savedInstanceState) {\r
+ super.onActivityCreated(savedInstanceState);\r
+ if (mAccount != null) {\r
+ mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());;\r
+ }\r
+ }\r
+ \r
+\r
@Override\r
public void onSaveInstanceState(Bundle outState) {\r
Log.i(getClass().toString(), "onSaveInstanceState() start");\r
public void onClick(View v) {\r
switch (v.getId()) {\r
case R.id.fdDownloadBtn: {\r
- Intent i = new Intent(getActivity(), FileDownloader.class);\r
- i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);\r
- i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath());\r
- i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath());\r
- i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength());\r
- \r
- // update ui \r
- setButtonsForTransferring();\r
+ //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath())) {\r
+ FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();\r
+ FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();\r
+ if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {\r
+ downloaderBinder.cancel(mAccount, mFile);\r
+ if (mFile.isDown()) {\r
+ setButtonsForDown();\r
+ } else {\r
+ setButtonsForRemote();\r
+ }\r
+\r
+ } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) {\r
+ uploaderBinder.cancel(mAccount, mFile);\r
+ if (!mFile.fileExists()) {\r
+ // TODO make something better\r
+ if (getActivity() instanceof FileDisplayActivity) {\r
+ // double pane\r
+ FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();\r
+ transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FTAG); // empty FileDetailFragment\r
+ transaction.commit();\r
+ mContainerActivity.onFileStateChanged();\r
+ } else {\r
+ getActivity().finish();\r
+ }\r
+ \r
+ } else if (mFile.isDown()) {\r
+ setButtonsForDown();\r
+ } else {\r
+ setButtonsForRemote();\r
+ }\r
+ \r
+ } else {\r
+ mLastRemoteOperation = new SynchronizeFileOperation(mFile, mStorageManager, mAccount, true, false, getActivity());\r
+ WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());\r
+ mLastRemoteOperation.execute(wc, this, mHandler);\r
\r
- getActivity().startService(i);\r
- mContainerActivity.onFileStateChanged(); // this is not working; it is performed before the fileDownloadService registers it as 'in progress'\r
+ // update ui \r
+ boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;\r
+ getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);\r
+ setButtonsForTransferring(); // disable button immediately, although the synchronization does not result in a file transference\r
+ \r
+ }\r
break;\r
}\r
case R.id.fdKeepInSync: {\r
CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);\r
mFile.setKeepInSync(cb.isChecked());\r
- FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());\r
- fdsm.saveFile(mFile);\r
+ mStorageManager.saveFile(mFile);\r
+ \r
+ /// register the OCFile instance in the observer service to monitor local updates;\r
+ /// if necessary, the file is download \r
+ Intent intent = new Intent(getActivity().getApplicationContext(),\r
+ FileObserverService.class);\r
+ intent.putExtra(FileObserverService.KEY_FILE_CMD,\r
+ (cb.isChecked()?\r
+ FileObserverService.CMD_ADD_OBSERVED_FILE:\r
+ FileObserverService.CMD_DEL_OBSERVED_FILE));\r
+ intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, mFile);\r
+ intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount);\r
+ Log.e(TAG, "starting observer service");\r
+ getActivity().startService(intent);\r
+ \r
if (mFile.keepInSync()) {\r
- onClick(getView().findViewById(R.id.fdDownloadBtn));\r
- } else { \r
- mContainerActivity.onFileStateChanged(); // put inside 'else' to not call it twice (here, and in the virtual click on fdDownloadBtn)\r
+ onClick(getView().findViewById(R.id.fdDownloadBtn)); // force an immediate synchronization\r
}\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
@Override\r
public void onConfirmation(String callerTag) {\r
if (callerTag.equals(FTAG_CONFIRMATION)) {\r
- FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver());\r
- if (fdsm.getFileById(mFile.getFileId()) != null) {\r
- new Thread(new RemoveRunnable(mFile, mAccount, new Handler())).start();\r
+ if (mStorageManager.getFileById(mFile.getFileId()) != null) {\r
+ mLastRemoteOperation = new RemoveFileOperation( mFile, \r
+ true, \r
+ mStorageManager);\r
+ WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());\r
+ mLastRemoteOperation.execute(wc, this, mHandler);\r
+ \r
boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;\r
getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);\r
}\r
\r
@Override\r
public void onNeutral(String callerTag) {\r
- FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver());\r
File f = null;\r
if (mFile.isDown() && (f = new File(mFile.getStoragePath())).exists()) {\r
f.delete();\r
mFile.setStoragePath(null);\r
- fdsm.saveFile(mFile);\r
+ mStorageManager.saveFile(mFile);\r
updateFileDetails(mFile, mAccount);\r
}\r
}\r
*/\r
public void updateFileDetails(OCFile file, Account ocAccount) {\r
mFile = file;\r
+ if (ocAccount != null && ( \r
+ mStorageManager == null || \r
+ (mAccount != null && !mAccount.equals(ocAccount))\r
+ )) {\r
+ mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());\r
+ }\r
mAccount = ocAccount;\r
updateFileDetails();\r
}\r
cb.setChecked(mFile.keepInSync());\r
\r
// configure UI for depending upon local state of the file\r
- if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) {\r
+ //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) {\r
+ FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();\r
+ FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();\r
+ if ((downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) {\r
setButtonsForTransferring();\r
\r
} else if (mFile.isDown()) {\r
private void setButtonsForTransferring() {\r
if (!isEmpty()) {\r
Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
- //downloadButton.setText(R.string.filedetails_download_in_progress); // ugly\r
- downloadButton.setEnabled(false); // TODO replace it with a 'cancel download' button\r
+ downloadButton.setText(R.string.common_cancel);\r
+ //downloadButton.setEnabled(false);\r
\r
// let's protect the user from himself ;)\r
((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false);\r
((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(false);\r
((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(false);\r
+ getView().findViewById(R.id.fdKeepInSync).setEnabled(false);\r
}\r
}\r
\r
private void setButtonsForDown() {\r
if (!isEmpty()) {\r
Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
- //downloadButton.setText(R.string.filedetails_redownload); // ugly\r
- downloadButton.setEnabled(true);\r
+ downloadButton.setText(R.string.filedetails_sync_file);\r
+ //downloadButton.setEnabled(true);\r
\r
((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(true);\r
((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true);\r
((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true);\r
+ getView().findViewById(R.id.fdKeepInSync).setEnabled(true);\r
}\r
}\r
\r
private void setButtonsForRemote() {\r
if (!isEmpty()) {\r
Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
- //downloadButton.setText(R.string.filedetails_download); // unnecessary\r
- downloadButton.setEnabled(true);\r
+ downloadButton.setText(R.string.filedetails_download);\r
\r
((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false);\r
((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true);\r
((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true);\r
+ getView().findViewById(R.id.fdKeepInSync).setEnabled(true);\r
}\r
}\r
\r
* \r
* @author David A. Velasco\r
*/\r
- public interface ContainerActivity {\r
+ public interface ContainerActivity extends TransferServiceGetter {\r
\r
/**\r
* Callback method invoked when the detail fragment wants to notice its container \r
String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);\r
if (mFile.getRemotePath().equals(downloadedRemotePath)) {\r
if (downloadWasFine) {\r
- mFile.setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); // updates the local object without accessing the database again\r
+ mFile = mStorageManager.getFileByPath(downloadedRemotePath);\r
}\r
updateFileDetails(); // it updates the buttons; must be called although !downloadWasFine\r
}\r
\r
\r
// this is a temporary class for sharing purposes, it need to be replaced in transfer service\r
+ @SuppressWarnings("unused")\r
private class ShareRunnable implements Runnable {\r
private String mPath;\r
\r
String uri = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + SHARED_PATH + token; \r
Log.d("Actions:shareFile ok", "url: " + uri); \r
\r
- } catch (HttpException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (IOException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (JSONException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
} catch (Exception e) {\r
- // TODO Auto-generated catch block\r
e.printStackTrace();\r
}\r
\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);\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
- private class RemoveRunnable implements Runnable {\r
- \r
- Account mAccount;\r
- OCFile mFileToRemove;\r
- Handler mHandler;\r
- \r
- public RemoveRunnable(OCFile fileToRemove, Account account, Handler handler) {\r
- mFileToRemove = fileToRemove;\r
- mAccount = account;\r
- mHandler = handler;\r
- }\r
- \r
- public void run() {\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(mFileToRemove.getRemotePath()));\r
-\r
- DeleteMethod delete = new DeleteMethod(baseUrl + webdav_path + WebdavUtils.encodePath(mFileToRemove.getRemotePath()));\r
- \r
- boolean success = false;\r
- int status = -1;\r
- try {\r
- status = wc.executeMethod(delete);\r
- success = (delete.succeeded());\r
- delete.getResponseBodyAsString(); // exhaust the response, although not interesting\r
- Log.d(TAG, "Delete: returned status " + status);\r
- \r
- } catch (HttpException e) {\r
- Log.e(TAG, "HTTP Exception removing file " + mFileToRemove.getRemotePath(), e);\r
- \r
- } catch (IOException e) {\r
- Log.e(TAG, "I/O Exception removing file " + mFileToRemove.getRemotePath(), e);\r
- \r
- } catch (Exception e) {\r
- Log.e(TAG, "Unexpected exception removing file " + mFileToRemove.getRemotePath(), e);\r
- \r
- } finally {\r
- delete.releaseConnection();\r
- }\r
- \r
- if (success) {\r
- FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver());\r
- fdsm.removeFile(mFileToRemove);\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
- try {\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
- \r
- } else {\r
- getActivity().finish();\r
- }\r
- \r
- } catch (NotFoundException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- });\r
- \r
- } else {\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
- try {\r
- Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); \r
- msg.show();\r
- \r
- } catch (NotFoundException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- });\r
- }\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
}\r
\r
}\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {\r
+ if (operation.equals(mLastRemoteOperation)) {\r
+ if (operation instanceof RemoveFileOperation) {\r
+ onRemoveFileOperationFinish((RemoveFileOperation)operation, result);\r
+ \r
+ } else if (operation instanceof RenameFileOperation) {\r
+ onRenameFileOperationFinish((RenameFileOperation)operation, result);\r
+ \r
+ } else if (operation instanceof SynchronizeFileOperation) {\r
+ onSynchronizeFileOperationFinish((SynchronizeFileOperation)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
+ }\r
+ \r
+ private void onSynchronizeFileOperationFinish(SynchronizeFileOperation 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
+ if (result.getCode() == ResultCode.SYNC_CONFLICT) {\r
+ Intent i = new Intent(getActivity(), ConflictsResolveActivity.class);\r
+ //i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);\r
+ i.putExtra("remotepath", mFile.getRemotePath());\r
+ i.putExtra("localpath", mFile.getStoragePath());\r
+ i.putExtra("account", mAccount);\r
+ startActivity(i);\r
+ \r
+ } else {\r
+ Toast msg = Toast.makeText(getActivity(), R.string.sync_file_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ }\r
+ \r
+ } else {\r
+ if (operation.transferWasRequested()) {\r
+ mContainerActivity.onFileStateChanged(); // this is not working; FileDownloader won't do NOTHING at all until this method finishes, so \r
+ // checking the service to see if the file is downloading results in FALSE\r
+ } else {\r
+ Toast msg = Toast.makeText(getActivity(), R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ if (mFile.isDown()) {\r
+ setButtonsForDown();\r
+ \r
+ } else {\r
+ setButtonsForRemote();\r
+ }\r
+ }\r
+ }\r
+ }\r
\r
}\r