public static final String TAG = PreviewImageActivity.class.getSimpleName();
public static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
+ private static final String KEY_WAITING_FOR_BINDER = "WAITING_FOR_BINDER";
private OCFile mFile;
private OCFile mParentFolder;
private ServiceConnection mDownloadConnection, mUploadConnection = null;
private FileUploaderBinder mUploaderBinder = null;
private OCFile mWaitingToPreview = null;
+
+ private boolean mRequestWaitingForBinder;
@Override
mParentFolder = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
}
- createViewPager();
-
- if (savedInstanceState == null) {
- mWaitingToPreview = (mFile.isDown())?null:mFile;
- } else {
+ if (savedInstanceState != null) {
mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(KEY_WAITING_TO_PREVIEW);
+ mRequestWaitingForBinder = savedInstanceState.getBoolean(KEY_WAITING_FOR_BINDER);
+ } else {
+ mWaitingToPreview = null;
+ mRequestWaitingForBinder = false;
}
+ createViewPager();
+
mDownloadConnection = new PreviewImageServiceConnection();
bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE);
mUploadConnection = new PreviewImageServiceConnection();
private void createViewPager() {
mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(), mParentFolder, mAccount, mStorageManager);
mViewPager = (ViewPager) findViewById(R.id.fragmentPager);
+ int position = mPreviewImagePagerAdapter.getFilePosition(mFile);
+ Log.e(TAG, "Setting initial position " + position);
mViewPager.setAdapter(mPreviewImagePagerAdapter);
mViewPager.setOnPageChangeListener(this);
+ mViewPager.setCurrentItem((position >= 0) ? position : 0);
}
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
+ outState.putBoolean(KEY_WAITING_FOR_BINDER, mRequestWaitingForBinder);
}
if (component.equals(new ComponentName(PreviewImageActivity.this, FileDownloader.class))) {
Log.d(TAG, "Download service connected");
mDownloaderBinder = (FileDownloaderBinder) service;
+ if (mRequestWaitingForBinder) {
+ if (mWaitingToPreview != null) {
+ requestForDownload();
+ }
+ mRequestWaitingForBinder = false;
+ }
} else if (component.equals(new ComponentName(PreviewImageActivity.this, FileUploader.class))) {
Log.d(TAG, "Upload service connected");
private void requestForDownload() {
Log.e(TAG, "REQUEST FOR DOWNLOAD : " + mWaitingToPreview.getFileName());
- if (!mDownloaderBinder.isDownloading(mAccount, mWaitingToPreview)) {
+ if (mDownloaderBinder == null) {
+ mRequestWaitingForBinder = true;
+
+ } else if (!mDownloaderBinder.isDownloading(mAccount, mWaitingToPreview)) {
Intent i = new Intent(this, FileDownloader.class);
i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
i.putExtra(FileDownloader.EXTRA_FILE, mWaitingToPreview);
startService(i);
}
+ mViewPager.invalidate();
}
@Override
Log.e(TAG, "BEFORE NOTIFY DATA SET CHANGED");
mPreviewImagePagerAdapter.notifyDataSetChanged();
Log.e(TAG, "AFTER NOTIFY DATA SET CHANGED");
- //Log.e(TAG, "BEFORE INVALIDATE");
- //mViewPager.postInvalidate();
- //Log.e(TAG, "AFTER INVALIDATE");
}
}
}
*/
@Override
public void onPageSelected(int position) {
+ Log.e(TAG, "onPageSelected " + position);
OCFile currentFile = mPreviewImagePagerAdapter.getFileAt(position);
getSupportActionBar().setTitle(currentFile.getFileName());
if (currentFile.isDown()) {
} else {
mWaitingToPreview = currentFile;
requestForDownload();
- mViewPager.invalidate();
}
}