X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/8eae3a2be5b08e2a5a0d271dbcfba91682bec368..5fc7cd13e7e561ef528e12d2fa088b58e35e00d0:/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 4772ddf4..10b44add 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; @@ -79,11 +78,13 @@ 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.ui.activity.FileDetailActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; +import com.owncloud.android.ui.activity.TransferServiceGetter; import com.owncloud.android.utils.OwnCloudVersion; import com.owncloud.android.R; @@ -138,7 +139,7 @@ public class FileDetailFragment extends SherlockFragment implements * @param fileToDetail An {@link OCFile} to show in the fragment * @param ocAccount An ownCloud account; needed to start downloads */ - public FileDetailFragment(OCFile fileToDetail, Account ocAccount){ + public FileDetailFragment(OCFile fileToDetail, Account ocAccount) { mFile = fileToDetail; mAccount = ocAccount; mLayout = R.layout.file_details_empty; @@ -149,20 +150,6 @@ public class FileDetailFragment extends SherlockFragment implements } - /** - * {@inheritDoc} - */ - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - try { - mContainerActivity = (ContainerActivity) activity; - } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() + " must implement FileListFragment.ContainerActivity"); - } - } - - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -192,6 +179,20 @@ public class FileDetailFragment extends SherlockFragment implements } + /** + * {@inheritDoc} + */ + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + try { + mContainerActivity = (ContainerActivity) activity; + } catch (ClassCastException e) { + throw new ClassCastException(activity.toString() + " must implement " + FileDetailFragment.ContainerActivity.class.getCanonicalName()); + } + } + + @Override public void onSaveInstanceState(Bundle outState) { Log.i(getClass().toString(), "onSaveInstanceState() start"); @@ -244,17 +245,30 @@ 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())) { + FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); + if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) { + downloaderBinder.cancel(mAccount, mFile); + if (mFile.isDown()) { + setButtonsForDown(); + } else { + setButtonsForRemote(); + } + + } else { + Intent i = new Intent(getActivity(), FileDownloader.class); + i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount); + i.putExtra(FileDownloader.EXTRA_FILE, mFile); + /*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: { @@ -430,7 +444,10 @@ public class FileDetailFragment extends SherlockFragment implements cb.setChecked(mFile.keepInSync()); // configure UI for depending upon local state of the file - if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) { + //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) { + FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); + FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); + if ((downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) { setButtonsForTransferring(); } else if (mFile.isDown()) { @@ -510,8 +527,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); @@ -526,8 +543,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); @@ -541,8 +558,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); @@ -576,7 +592,7 @@ public class FileDetailFragment extends SherlockFragment implements * * @author David A. Velasco */ - public interface ContainerActivity { + public interface ContainerActivity extends TransferServiceGetter { /** * Callback method invoked when the detail fragment wants to notice its container @@ -649,6 +665,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; @@ -741,17 +758,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(); }