import android.accounts.Account;\r
import android.app.Dialog;\r
import android.app.ProgressDialog;\r
+import android.content.ComponentName;\r
+import android.content.Context;\r
import android.content.Intent;\r
+import android.content.ServiceConnection;\r
import android.content.res.Configuration;\r
import android.os.Bundle;\r
+import android.os.IBinder;\r
import android.support.v4.app.FragmentTransaction;\r
\r
import com.actionbarsherlock.app.ActionBar;\r
import com.actionbarsherlock.view.MenuItem;\r
import com.owncloud.android.datamodel.OCFile;\r
import com.owncloud.android.files.services.FileDownloader;\r
+import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;\r
import com.owncloud.android.ui.fragment.FileDetailFragment;\r
\r
import com.owncloud.android.R;\r
public static final int DIALOG_SHORT_WAIT = 0;\r
\r
private boolean mConfigurationChangedToLandscape = false;\r
+ private FileDownloaderBinder mDownloaderBinder = null;\r
\r
@Override\r
protected void onCreate(Bundle savedInstanceState) {\r
);\r
\r
if (!mConfigurationChangedToLandscape) {\r
+ bindService(new Intent(this, FileDownloader.class), mConnection, Context.BIND_AUTO_CREATE);\r
+ \r
setContentView(R.layout.file_activity_details);\r
\r
ActionBar actionBar = getSupportActionBar();\r
actionBar.setDisplayHomeAsUpEnabled(true);\r
- \r
+\r
OCFile file = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE);\r
Account account = getIntent().getParcelableExtra(FileDownloader.EXTRA_ACCOUNT);\r
FileDetailFragment mFileDetail = new FileDetailFragment(file, account);\r
\r
\r
}\r
+ \r
+ \r
+ /** Defines callbacks for service binding, passed to bindService() */\r
+ private ServiceConnection mConnection = new ServiceConnection() {\r
+\r
+ @Override\r
+ public void onServiceConnected(ComponentName className, IBinder service) {\r
+ mDownloaderBinder = (FileDownloaderBinder) service;\r
+ FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
+ if (fragment != null)\r
+ fragment.updateFileDetails(); // a new chance to get the mDownloadBinder through getDownloadBinder()\r
+ }\r
+\r
+ @Override\r
+ public void onServiceDisconnected(ComponentName arg0) {\r
+ mDownloaderBinder = null;\r
+ }\r
+ }; \r
+ \r
\r
@Override\r
+ public void onDestroy() {\r
+ super.onDestroy();\r
+ unbindService(mConnection);\r
+ }\r
+ \r
+ \r
+ @Override\r
public boolean onOptionsItemSelected(MenuItem item) {\r
boolean returnValue = false;\r
\r
// nothing to do here!\r
}\r
\r
+ \r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public FileDownloaderBinder getFileDownloaderBinder() {\r
+ return mDownloaderBinder;\r
+ }\r
+ \r
}\r