import com.owncloud.android.datamodel.OCFile;\r
import com.owncloud.android.files.services.FileDownloader;\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.ui.activity.FileDetailActivity;\r
import com.owncloud.android.ui.activity.FileDisplayActivity;\r
+import com.owncloud.android.ui.activity.TransferServiceGetter;\r
import com.owncloud.android.utils.OwnCloudVersion;\r
\r
import com.owncloud.android.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
mLayout = R.layout.file_details_empty;\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 FileListFragment.ContainerActivity");\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.getCanonicalName());\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
- if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath())) {\r
- \r
- // TODO cancelar descarga\r
- \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
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, mFile);\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
+ i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength());*/\r
\r
// update ui \r
setButtonsForTransferring();\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
((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
((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
((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