- 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, true);\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