X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/a3aca94694441e12e449a127903310148fdf60f0..a0e4e7ea97d5686b29a4e778fcab688f8c4f1bc8:/src/com/owncloud/android/ui/preview/FileDownloadFragment.java diff --git a/src/com/owncloud/android/ui/preview/FileDownloadFragment.java b/src/com/owncloud/android/ui/preview/FileDownloadFragment.java index 5331d5bf..493e65bc 100644 --- a/src/com/owncloud/android/ui/preview/FileDownloadFragment.java +++ b/src/com/owncloud/android/ui/preview/FileDownloadFragment.java @@ -22,11 +22,8 @@ import java.lang.ref.WeakReference; import android.accounts.Account; import android.app.Activity; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; import android.os.Bundle; +import android.support.v4.app.FragmentStatePagerAdapter; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -39,10 +36,8 @@ import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragment; 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.FileDownloader.FileDownloaderBinder; import com.owncloud.android.ui.fragment.FileFragment; -import com.owncloud.android.ui.fragment.FileFragment.ContainerActivity; import com.owncloud.android.R; @@ -53,7 +48,7 @@ import eu.alefzero.webdav.OnDatatransferProgressListener; * * @author David A. Velasco */ -public class FileDownloadFragment extends SherlockFragment implements OnClickListener,FileFragment { +public class FileDownloadFragment extends SherlockFragment implements OnClickListener, FileFragment { public static final String EXTRA_FILE = "FILE"; public static final String EXTRA_ACCOUNT = "ACCOUNT"; @@ -65,13 +60,14 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis private Account mAccount; private FileDataStorageManager mStorageManager; - private DownloadFinishReceiver mDownloadFinishReceiver; public ProgressListener mProgressListener; private boolean mListening; private static final String TAG = FileDownloadFragment.class.getSimpleName(); + private boolean mIgnoreFirstSavedState; + /** * Creates an empty details fragment. * @@ -83,6 +79,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis mStorageManager = null; mProgressListener = null; mListening = false; + mIgnoreFirstSavedState = false; } @@ -93,13 +90,15 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis * * @param fileToDetail An {@link OCFile} to show in the fragment * @param ocAccount An ownCloud account; needed to start downloads + * @param ignoreFirstSavedState Flag to work around an unexpected behaviour of {@link FragmentStatePagerAdapter}; TODO better solution */ - public FileDownloadFragment(OCFile fileToDetail, Account ocAccount) { + public FileDownloadFragment(OCFile fileToDetail, Account ocAccount, boolean ignoreFirstSavedState) { mFile = fileToDetail; 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; + mIgnoreFirstSavedState = ignoreFirstSavedState; } @@ -116,12 +115,12 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis super.onCreateView(inflater, container, savedInstanceState); if (savedInstanceState != null) { - mFile = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_FILE); - mAccount = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_ACCOUNT); - } - - if(mFile != null && mAccount != null) { - //mLayout = R.layout.file_details_fragment; + if (!mIgnoreFirstSavedState) { + mFile = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_FILE); + mAccount = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_ACCOUNT); + } else { + mIgnoreFirstSavedState = false; + } } View view = null; @@ -131,6 +130,8 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis ProgressBar progressBar = (ProgressBar)mView.findViewById(R.id.progressBar); mProgressListener = new ProgressListener(progressBar); + ((Button)mView.findViewById(R.id.cancelBtn)).setOnClickListener(this); + return view; } @@ -182,11 +183,6 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis public void onResume() { Log.e(TAG, "PREVIEW_DOWNLOAD_FRAGMENT ONRESUME " + mFile.getFileName()); super.onResume(); - - mDownloadFinishReceiver = new DownloadFinishReceiver(); - IntentFilter filter = new IntentFilter( - FileDownloader.DOWNLOAD_FINISH_MESSAGE); - getActivity().registerReceiver(mDownloadFinishReceiver, filter); } @@ -194,9 +190,6 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis public void onPause() { super.onPause(); Log.e(TAG, "PREVIEW_DOWNLOAD_FRAGMENT ONPAUSE " + mFile.getFileName()); - - getActivity().unregisterReceiver(mDownloadFinishReceiver); - mDownloadFinishReceiver = null; } @@ -230,11 +223,15 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) { downloaderBinder.cancel(mAccount, mFile); + getActivity().finish(); // :) + /* + leaveTransferProgress(); if (mFile.isDown()) { setButtonsForDown(); } else { setButtonsForRemote(); } + */ } break; } @@ -325,29 +322,6 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis } - /** - * Once the file download has finished -> update view - */ - private class DownloadFinishReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME); - if (accountName.equals(mAccount.name)) { - boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false); - String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); - if (mFile.getRemotePath().equals(downloadedRemotePath)) { - if (downloadWasFine) { - mFile = mStorageManager.getFileByPath(downloadedRemotePath); - } - updateView(false); - getActivity().removeStickyBroadcast(intent); - mContainerActivity.notifySuccessfulDownload(mFile, intent, downloadWasFine); - } - } - } - } - - public void listenForTransferProgress() { if (mProgressListener != null && !mListening) { if (mContainerActivity.getFileDownloaderBinder() != null) { @@ -363,6 +337,7 @@ public class FileDownloadFragment extends SherlockFragment implements OnClickLis if (mProgressListener != null) { if (mContainerActivity.getFileDownloaderBinder() != null) { mContainerActivity.getFileDownloaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, mFile); + mListening = false; } } }