import android.app.AlertDialog.Builder;\r
import android.app.Dialog;\r
import android.content.BroadcastReceiver;\r
+import android.content.ComponentName;\r
import android.content.ContentResolver;\r
import android.content.Context;\r
import android.content.DialogInterface;\r
import android.content.DialogInterface.OnClickListener;\r
import android.content.Intent;\r
import android.content.IntentFilter;\r
+import android.content.ServiceConnection;\r
import android.content.SharedPreferences;\r
import android.content.pm.PackageInfo;\r
import android.content.pm.PackageManager.NameNotFoundException;\r
import android.net.Uri;\r
import android.os.Bundle;\r
import android.os.Handler;\r
+import android.os.IBinder;\r
import android.preference.PreferenceManager;\r
import android.provider.MediaStore;\r
import android.support.v4.app.FragmentTransaction;\r
import com.owncloud.android.datamodel.FileDataStorageManager;\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.files.services.FileUploader;\r
import com.owncloud.android.network.OwnCloudClientUtils;\r
import com.owncloud.android.syncadapter.FileSyncService;\r
private SyncBroadcastReceiver mSyncBroadcastReceiver;\r
private UploadFinishReceiver mUploadFinishReceiver;\r
private DownloadFinishReceiver mDownloadFinishReceiver;\r
+ private FileDownloaderBinder mDownloaderBinder = null;\r
\r
private OCFileListFragment mFileList;\r
\r
\r
} else { /// at least an account is available\r
\r
+ bindService(new Intent(this, FileDownloader.class), mConnection, Context.BIND_AUTO_CREATE);\r
initDataFromCurrentAccount();\r
\r
}\r
mCurrentDir = mStorageManager.getFileByPath("/"); // this will return NULL if the database has not ever synchronized\r
}\r
\r
+ \r
+ @Override\r
+ public void onDestroy() {\r
+ super.onDestroy();\r
+ unbindService(mConnection);\r
+ }\r
\r
+ \r
@Override\r
public boolean onCreateOptionsMenu(Menu menu) {\r
MenuInflater inflater = getSherlock().getMenuInflater();\r
registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);\r
\r
// List current directory\r
- //mFileList.listDirectory(mCurrentDir);\r
+ mFileList.listDirectory(mCurrentDir); // we should find the way to avoid the need of this\r
\r
} else {\r
\r
fileListFragment.listDirectory();\r
}\r
}\r
+\r
+ \r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public FileDownloaderBinder getFileDownloaderBinder() {\r
+ return mDownloaderBinder;\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
+ // a new chance to get the mDownloadBinder through getDownloadBinder() - THIS IS A MESS\r
+ mFileList.listDirectory();\r
+ if (mDualPane) {\r
+ FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
+ if (fragment != null)\r
+ fragment.updateFileDetails();\r
+ }\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void onServiceDisconnected(ComponentName arg0) {\r
+ mDownloaderBinder = null;\r
+ }\r
+ }; \r
+\r
+ \r
\r
/**\r
* Launch an intent to request the PIN code to the user before letting him use the app\r
}\r
}\r
\r
- \r
+\r
}\r