X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/a4ba6170ea7696e085b07adfef73eeb8b77cb8e2..76ba00b2b23f5c2079a6635dc5e661850c3c5dfb:/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 ae38a0a0..5b76c018 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -35,7 +35,6 @@ 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.JSONException; import org.json.JSONObject; import android.accounts.Account; @@ -80,6 +79,7 @@ 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.FileUploader; +import com.owncloud.android.network.OwnCloudClientUtils; import com.owncloud.android.ui.activity.FileDetailActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.utils.OwnCloudVersion; @@ -242,17 +242,29 @@ public class FileDetailFragment extends SherlockFragment implements public void onClick(View v) { switch (v.getId()) { case R.id.fdDownloadBtn: { - Intent i = new Intent(getActivity(), FileDownloader.class); - i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount); - i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath()); - i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath()); - i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength()); + if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath())) { + + // TODO cancelar descarga + + if (mFile.isDown()) { + setButtonsForDown(); + } else { + setButtonsForRemote(); + } + + } else { + Intent i = new Intent(getActivity(), FileDownloader.class); + i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount); + i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath()); + i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath()); + i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength()); - // update ui - setButtonsForTransferring(); + // update ui + setButtonsForTransferring(); - getActivity().startService(i); - mContainerActivity.onFileStateChanged(); // this is not working; it is performed before the fileDownloadService registers it as 'in progress' + getActivity().startService(i); + mContainerActivity.onFileStateChanged(); // this is not working; it is performed before the fileDownloadService registers it as 'in progress' + } break; } case R.id.fdKeepInSync: { @@ -262,9 +274,19 @@ public class FileDetailFragment extends SherlockFragment implements fdsm.saveFile(mFile); if (mFile.keepInSync()) { onClick(getView().findViewById(R.id.fdDownloadBtn)); - } else { + } 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, + (cb.isChecked()? + FileObserverService.CMD_ADD_OBSERVED_FILE: + FileObserverService.CMD_DEL_OBSERVED_FILE)); + intent.putExtra(FileObserverService.KEY_CMD_ARG, mFile.getStoragePath()); + getActivity().startService(intent); + */ break; } case R.id.fdRenameBtn: { @@ -498,8 +520,8 @@ public class FileDetailFragment extends SherlockFragment implements private void setButtonsForTransferring() { if (!isEmpty()) { Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); - //downloadButton.setText(R.string.filedetails_download_in_progress); // ugly - downloadButton.setEnabled(false); // TODO replace it with a 'cancel download' button + downloadButton.setText(R.string.common_cancel); + //downloadButton.setEnabled(false); // let's protect the user from himself ;) ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false); @@ -514,8 +536,8 @@ public class FileDetailFragment extends SherlockFragment implements private void setButtonsForDown() { if (!isEmpty()) { Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); - //downloadButton.setText(R.string.filedetails_redownload); // ugly - downloadButton.setEnabled(true); + downloadButton.setText(R.string.filedetails_redownload); + //downloadButton.setEnabled(true); ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(true); ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true); @@ -529,8 +551,7 @@ public class FileDetailFragment extends SherlockFragment implements private void setButtonsForRemote() { if (!isEmpty()) { Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); - //downloadButton.setText(R.string.filedetails_download); // unnecessary - downloadButton.setEnabled(true); + downloadButton.setText(R.string.filedetails_download); ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false); ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true); @@ -637,6 +658,7 @@ public class FileDetailFragment extends SherlockFragment implements // this is a temporary class for sharing purposes, it need to be replaced in transfer service + @SuppressWarnings("unused") private class ShareRunnable implements Runnable { private String mPath; @@ -661,7 +683,7 @@ public class FileDetailFragment extends SherlockFragment implements final String WEBDAV_SCRIPT = "webdav.php"; final String WEBDAV_FILES_LOCATION = "/files/"; - WebdavClient wc = new WebdavClient(); + WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(account, getActivity().getApplicationContext()); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setMaxConnectionsPerHost(wc.getHostConfiguration(), 5); @@ -684,7 +706,6 @@ public class FileDetailFragment extends SherlockFragment implements PropFindMethod find = new PropFindMethod(url+"/"); find.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL)); Log.d("sharer", ""+ url+"/"); - wc.setCredentials(account.name.substring(0, account.name.lastIndexOf('@')), am.getPassword(account)); for (org.apache.commons.httpclient.Header a : find.getRequestHeaders()) { Log.d("sharer-h", a.getName() + ":"+a.getValue()); @@ -730,17 +751,7 @@ public class FileDetailFragment extends SherlockFragment implements String uri = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + SHARED_PATH + token; Log.d("Actions:shareFile ok", "url: " + uri); - } catch (HttpException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (JSONException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); } @@ -809,8 +820,7 @@ public class FileDetailFragment extends SherlockFragment implements } public void run() { - WebdavClient wc = new WebdavClient(mAccount, getSherlockActivity().getApplicationContext()); - wc.allowSelfsignedCertificates(); + 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)); @@ -825,6 +835,7 @@ public class FileDetailFragment extends SherlockFragment implements 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) { @@ -835,11 +846,14 @@ public class FileDetailFragment extends SherlockFragment implements } 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); + fdsm.removeFile(mOld, false); fdsm.saveFile(mNew); mFile = mNew; mHandler.post(new Runnable() { @@ -973,8 +987,7 @@ public class FileDetailFragment extends SherlockFragment implements } public void run() { - WebdavClient wc = new WebdavClient(mAccount, getSherlockActivity().getApplicationContext()); - wc.allowSelfsignedCertificates(); + 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)); @@ -988,6 +1001,7 @@ public class FileDetailFragment extends SherlockFragment implements 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) { @@ -998,11 +1012,14 @@ public class FileDetailFragment extends SherlockFragment implements } 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); + fdsm.removeFile(mFileToRemove, true); mHandler.post(new Runnable() { @Override public void run() {