Removed useless swipe detection from details view
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / preview / PreviewImageActivity.java
index 1e9d108..0bc7e6b 100644 (file)
@@ -58,6 +58,7 @@ public class PreviewImageActivity extends SherlockFragmentActivity implements Fi
     public static final String TAG = PreviewImageActivity.class.getSimpleName();
     
     public static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
     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 OCFile mFile;
     private OCFile mParentFolder;  
@@ -71,6 +72,8 @@ public class PreviewImageActivity extends SherlockFragmentActivity implements Fi
     private ServiceConnection mDownloadConnection, mUploadConnection = null;
     private FileUploaderBinder mUploaderBinder = null;
     private OCFile mWaitingToPreview = null;
     private ServiceConnection mDownloadConnection, mUploadConnection = null;
     private FileUploaderBinder mUploaderBinder = null;
     private OCFile mWaitingToPreview = null;
+
+    private boolean mRequestWaitingForBinder;
     
 
     @Override
     
 
     @Override
@@ -102,14 +105,16 @@ public class PreviewImageActivity extends SherlockFragmentActivity implements Fi
             mParentFolder = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
         }
 
             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);
             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();
         mDownloadConnection = new PreviewImageServiceConnection();
         bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE);
         mUploadConnection = new PreviewImageServiceConnection();
@@ -120,8 +125,11 @@ public class PreviewImageActivity extends SherlockFragmentActivity implements Fi
     private void createViewPager() {
         mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(), mParentFolder, mAccount, mStorageManager);
         mViewPager = (ViewPager) findViewById(R.id.fragmentPager);
     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.setAdapter(mPreviewImagePagerAdapter);        
         mViewPager.setOnPageChangeListener(this);
+        mViewPager.setCurrentItem((position >= 0) ? position : 0);
     }
     
 
     }
     
 
@@ -129,6 +137,7 @@ public class PreviewImageActivity extends SherlockFragmentActivity implements Fi
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         outState.putParcelable(KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         outState.putParcelable(KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
+        outState.putBoolean(KEY_WAITING_FOR_BINDER, mRequestWaitingForBinder);    
     }
 
 
     }
 
 
@@ -141,6 +150,12 @@ public class PreviewImageActivity extends SherlockFragmentActivity implements Fi
             if (component.equals(new ComponentName(PreviewImageActivity.this, FileDownloader.class))) {
                 Log.d(TAG, "Download service connected");
                 mDownloaderBinder = (FileDownloaderBinder) service;
             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");
                     
             } else if (component.equals(new ComponentName(PreviewImageActivity.this, FileUploader.class))) {
                 Log.d(TAG, "Upload service connected");
@@ -269,12 +284,16 @@ public class PreviewImageActivity extends SherlockFragmentActivity implements Fi
     
     private void requestForDownload() {
         Log.e(TAG, "REQUEST FOR DOWNLOAD : " + mWaitingToPreview.getFileName());
     
     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);
         }
             Intent i = new Intent(this, FileDownloader.class);
             i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
             i.putExtra(FileDownloader.EXTRA_FILE, mWaitingToPreview);
             startService(i);
         }
+        mViewPager.invalidate();
     }
 
     @Override
     }
 
     @Override
@@ -287,9 +306,6 @@ public class PreviewImageActivity extends SherlockFragmentActivity implements Fi
                 Log.e(TAG, "BEFORE NOTIFY DATA SET CHANGED");
                 mPreviewImagePagerAdapter.notifyDataSetChanged();
                 Log.e(TAG, "AFTER NOTIFY DATA SET CHANGED");
                 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");
             }
         }
     }
             }
         }
     }
@@ -302,6 +318,7 @@ public class PreviewImageActivity extends SherlockFragmentActivity implements Fi
      */
     @Override
     public void onPageSelected(int position) {
      */
     @Override
     public void onPageSelected(int position) {
+        Log.e(TAG, "onPageSelected " + position);
         OCFile currentFile = mPreviewImagePagerAdapter.getFileAt(position); 
         getSupportActionBar().setTitle(currentFile.getFileName());
         if (currentFile.isDown()) {
         OCFile currentFile = mPreviewImagePagerAdapter.getFileAt(position); 
         getSupportActionBar().setTitle(currentFile.getFileName());
         if (currentFile.isDown()) {
@@ -309,7 +326,6 @@ public class PreviewImageActivity extends SherlockFragmentActivity implements Fi
         } else {
             mWaitingToPreview = currentFile;
             requestForDownload();
         } else {
             mWaitingToPreview = currentFile;
             requestForDownload();
-            mViewPager.invalidate();
         }
     }
     
         }
     }