*/\r
package com.owncloud.android.ui.activity;\r
\r
-import java.lang.ref.WeakReference;\r
-\r
import android.accounts.Account;\r
import android.app.Dialog;\r
import android.app.ProgressDialog;\r
import android.support.v4.app.Fragment;\r
import android.support.v4.app.FragmentTransaction;\r
import android.util.Log;\r
-import android.widget.ProgressBar;\r
\r
import com.actionbarsherlock.app.ActionBar;\r
import com.actionbarsherlock.app.SherlockFragmentActivity;\r
\r
import com.owncloud.android.R;\r
\r
-import eu.alefzero.webdav.OnDatatransferProgressListener;\r
-\r
/**\r
* This activity displays the details of a file like its name, its size and so\r
* on.\r
private FileUploaderBinder mUploaderBinder = null;\r
private boolean mWaitingToPreview;\r
\r
+ private OCFile mFile;\r
+ private Account mAccount;\r
+ \r
\r
@Override\r
protected void onCreate(Bundle savedInstanceState) {\r
super.onCreate(savedInstanceState);\r
\r
+ mFile = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE);\r
+ mAccount = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT);\r
+ \r
// check if configuration changed to large-land ; for a tablet being changed from portrait to landscape when in FileDetailActivity \r
Configuration conf = getResources().getConfiguration();\r
mConfigurationChangedToLandscape = (conf.orientation == Configuration.ORIENTATION_LANDSCAPE && \r
);\r
\r
if (!mConfigurationChangedToLandscape) {\r
- mDownloadConnection = new DetailsServiceConnection();\r
- bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE);\r
- mUploadConnection = new DetailsServiceConnection();\r
- bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE);\r
- \r
setContentView(R.layout.file_activity_details);\r
\r
ActionBar actionBar = getSupportActionBar();\r
mWaitingToPreview = savedInstanceState.getBoolean(KEY_WAITING_TO_PREVIEW);\r
}\r
\r
+ mDownloadConnection = new DetailsServiceConnection();\r
+ bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE);\r
+ mUploadConnection = new DetailsServiceConnection();\r
+ bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE);\r
+ \r
+ \r
} else {\r
backToDisplayActivity(); // the 'back' won't be effective until this.onStart() and this.onResume() are completed;\r
}\r
* the requested {@link Intent}.\r
*/\r
private void createChildFragment() {\r
- OCFile file = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE);\r
- Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT);\r
int mode = getIntent().getIntExtra(EXTRA_MODE, MODE_PREVIEW); \r
\r
Fragment newFragment = null;\r
- if (FilePreviewFragment.canBePreviewed(file) && mode == MODE_PREVIEW) {\r
- if (file.isDown()) {\r
- newFragment = new FilePreviewFragment(file, account);\r
+ if (FilePreviewFragment.canBePreviewed(mFile) && mode == MODE_PREVIEW) {\r
+ if (mFile.isDown()) {\r
+ newFragment = new FilePreviewFragment(mFile, mAccount);\r
\r
} else {\r
- newFragment = new FileDetailFragment(file, account);\r
+ newFragment = new FileDetailFragment(mFile, mAccount);\r
mWaitingToPreview = true;\r
}\r
\r
} else {\r
- newFragment = new FileDetailFragment(file, account);\r
+ newFragment = new FileDetailFragment(mFile, mAccount);\r
}\r
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();\r
ft.replace(R.id.fragment, newFragment, FileDetailFragment.FTAG);\r
if (component.equals(new ComponentName(FileDetailActivity.this, FileDownloader.class))) {\r
Log.d(TAG, "Download service connected");\r
mDownloaderBinder = (FileDownloaderBinder) service;\r
+ if (mWaitingToPreview) {\r
+ requestForDownload();\r
+ }\r
+ \r
} else if (component.equals(new ComponentName(FileDetailActivity.this, FileUploader.class))) {\r
Log.d(TAG, "Upload service connected");\r
mUploaderBinder = (FileUploaderBinder) service;\r
FileDetailFragment detailsFragment = (fragment instanceof FileDetailFragment) ? (FileDetailFragment) fragment : null;\r
if (detailsFragment != null) {\r
detailsFragment.listenForTransferProgress();\r
- detailsFragment.updateFileDetails(false); // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais())\r
+ detailsFragment.updateFileDetails(mWaitingToPreview); // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais())\r
}\r
}\r
\r
private void backToDisplayActivity() {\r
Intent intent = new Intent(this, FileDisplayActivity.class);\r
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);\r
- intent.putExtra(FileDetailFragment.EXTRA_FILE, getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE));\r
- intent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT));\r
+ intent.putExtra(FileDetailFragment.EXTRA_FILE, mFile);\r
+ intent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, mAccount);\r
startActivity(intent);\r
finish();\r
}\r
@Override\r
public void showFragmentWithDetails(OCFile file) {\r
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\r
- transaction.replace(R.id.fragment, new FileDetailFragment(file, (Account) getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT)), FileDetailFragment.FTAG); \r
+ transaction.replace(R.id.fragment, new FileDetailFragment(file, mAccount), FileDetailFragment.FTAG); \r
transaction.commit();\r
}\r
+\r
+ \r
+ private void requestForDownload() {\r
+ if (!mDownloaderBinder.isDownloading(mAccount, mFile)) {\r
+ Intent i = new Intent(this, FileDownloader.class);\r
+ i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);\r
+ i.putExtra(FileDownloader.EXTRA_FILE, mFile);\r
+ startService(i);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void notifySuccessfulDownload(OCFile file) {\r
+ if (mWaitingToPreview) {\r
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\r
+ transaction.replace(R.id.fragment, new FilePreviewFragment(file, mAccount), FileDetailFragment.FTAG); \r
+ transaction.commit();\r
+ mWaitingToPreview = false;\r
+ }\r
+ }\r
\r
}\r