X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/99d52af203f63a5dd3d43626f569ac88c5ac9b14..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 a77d9ad6..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,9 +79,9 @@ 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.OwnCloudClientUtils; import com.owncloud.android.utils.OwnCloudVersion; import com.owncloud.android.R; @@ -243,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: { @@ -263,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: { @@ -499,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); @@ -515,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); @@ -530,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); @@ -638,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; @@ -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(); } @@ -842,7 +853,7 @@ public class FileDetailFragment extends SherlockFragment implements 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() { @@ -1008,7 +1019,7 @@ public class FileDetailFragment extends SherlockFragment implements if (success) { FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); - fdsm.removeFile(mFileToRemove); + fdsm.removeFile(mFileToRemove, true); mHandler.post(new Runnable() { @Override public void run() {