private DownloadFinishReceiver mDownloadFinishReceiver;
public ProgressListener mProgressListener;
+ private boolean mListening;
private static final String TAG = FileDownloadFragment.class.getSimpleName();
mAccount = null;
mStorageManager = null;
mProgressListener = null;
+ mListening = false;
}
mAccount = ocAccount;
mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment
mProgressListener = null;
+ mListening = false;
}
view = inflater.inflate(R.layout.file_download_fragment, container, false);
mView = view;
- ProgressBar progressBar = (ProgressBar)mView.findViewById(R.id.fdProgressBar);
+ ProgressBar progressBar = (ProgressBar)mView.findViewById(R.id.progressBar);
mProgressListener = new ProgressListener(progressBar);
return view;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
+ Log.e(TAG, "PREVIEW_DOWNLOAD_FRAGMENT ONATTACH " + ((mFile == null)?" (NULL)":mFile.getFileName()));
try {
mContainerActivity = (ContainerActivity) activity;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
+ Log.e(TAG, "PREVIEW_DOWNLOAD_FRAGMENT ONACTIVITYCREATED " + ((mFile == null)?" (NULL)":mFile.getFileName()));
if (mAccount != null) {
mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());;
}
@Override
public View getView() {
+ if (!mListening) {
+ listenForTransferProgress();
+ }
return super.getView() == null ? mView : super.getView();
}
/**
* Updates the view depending upon the state of the downloading file.
+ *
+ * @param transferring When true, the view must be updated assuming that the holded file is
+ * downloading, no matter what the downloaderBinder says.
*/
- public void updateView() {
+ public void updateView(boolean transferring) {
// configure UI for depending upon local state of the file
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
- if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
+ if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile))) {
setButtonsForTransferring();
} else if (mFile.isDown()) {
downloadButton.setText(R.string.common_cancel);
// show the progress bar for the transfer
- ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.fdProgressBar);
+ ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
- TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText);
+ TextView progressText = (TextView)getView().findViewById(R.id.progressText);
progressText.setText(R.string.downloader_download_in_progress_ticker);
}
downloadButton.setVisibility(View.GONE);
// hides the progress bar
- ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.fdProgressBar);
+ ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.progressBar);
progressBar.setVisibility(View.GONE);
// updates the text message
- TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText);
+ TextView progressText = (TextView)getView().findViewById(R.id.progressText);
progressText.setText(R.string.common_loading);
}
//downloadButton.setText(R.string.filedetails_download);
// hides the progress bar
- ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.fdProgressBar);
+ ProgressBar progressBar = (ProgressBar)getView().findViewById(R.id.progressBar);
progressBar.setVisibility(View.GONE);
// updates the text message
- TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText);
+ TextView progressText = (TextView)getView().findViewById(R.id.progressText);
progressText.setText(R.string.downloader_not_downloaded_yet);
}
if (downloadWasFine) {
mFile = mStorageManager.getFileByPath(downloadedRemotePath);
}
- mContainerActivity.notifySuccessfulDownload(mFile, intent, downloadWasFine);
+ updateView(false);
getActivity().removeStickyBroadcast(intent);
- updateView();
+ mContainerActivity.notifySuccessfulDownload(mFile, intent, downloadWasFine);
}
}
}
public void listenForTransferProgress() {
- if (mProgressListener != null) {
+ if (mProgressListener != null && !mListening) {
if (mContainerActivity.getFileDownloaderBinder() != null) {
mContainerActivity.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, mFile);
- }
- if (mContainerActivity.getFileUploaderBinder() != null) {
- mContainerActivity.getFileUploaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, mFile);
+ mListening = true;
+ setButtonsForTransferring();
}
}
}
if (mContainerActivity.getFileDownloaderBinder() != null) {
mContainerActivity.getFileDownloaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, mFile);
}
- if (mContainerActivity.getFileUploaderBinder() != null) {
- mContainerActivity.getFileUploaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, mFile);
- }
}
}