am ea8c4b44: Continuously attempt to load thumbnail if it fails the first time. This behavior is the same as loading the full image.

* commit 'ea8c4b44178e7593870472743bde05d0d079b9ee':
  Continuously attempt to load thumbnail if it fails the first time. This behavior is the same as loading the full image.
diff --git a/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java b/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java
index 56df485..c5183ed 100644
--- a/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java
+++ b/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java
@@ -88,4 +88,8 @@
     public String getPhotoUri(Cursor cursor) {
         return cursor.getString(mContentUriIndex);
     }
+
+    public String getThumbnailUri(Cursor cursor) {
+        return cursor.getString(mThumbnailUriIndex);
+    }
 }
diff --git a/src/com/android/ex/photo/fragments/PhotoViewFragment.java b/src/com/android/ex/photo/fragments/PhotoViewFragment.java
index afd40ba..e4807b6 100644
--- a/src/com/android/ex/photo/fragments/PhotoViewFragment.java
+++ b/src/com/android/ex/photo/fragments/PhotoViewFragment.java
@@ -118,6 +118,7 @@
     protected boolean mProgressBarNeeded = true;
 
     protected View mPhotoPreviewAndProgress;
+    protected boolean mThumbnailShown;
 
     /** Public no-arg constructor for allowing the framework to handle orientation changes */
     public PhotoViewFragment() {
@@ -129,7 +130,6 @@
      * @param intent
      * @param position
      * @param onlyShowSpinner
-     * @return
      */
     public static final PhotoViewFragment newInstance(
             Intent intent, int position, boolean onlyShowSpinner) {
@@ -227,6 +227,7 @@
 
         mPhotoPreviewAndProgress = view.findViewById(R.id.photo_preview);
         mPhotoPreviewImage = (ImageView) view.findViewById(R.id.photo_preview_image);
+        mThumbnailShown = false;
         final ProgressBar indeterminate =
                 (ProgressBar) view.findViewById(R.id.indeterminate_progress);
         final ProgressBar determinate =
@@ -316,9 +317,11 @@
                 if (data == null) {
                     // no preview, show default
                     mPhotoPreviewImage.setImageResource(R.drawable.default_image);
+                    mThumbnailShown = false;
                 } else {
                     // show preview
                     mPhotoPreviewImage.setImageBitmap(data);
+                    mThumbnailShown = true;
                 }
                 mPhotoPreviewImage.setVisibility(View.VISIBLE);
                 mPhotoPreviewImage.setScaleType(ImageView.ScaleType.CENTER);
@@ -465,16 +468,23 @@
             mCallback.onCursorChanged(this, cursor);
 
             final LoaderManager manager = getLoaderManager();
-            final Loader<Bitmap> fakeLoader = manager.getLoader(LOADER_ID_PHOTO);
-            if (fakeLoader == null) {
-                return;
+            final Loader<Bitmap> fakePhotoLoader = manager.getLoader(LOADER_ID_PHOTO);
+            if (fakePhotoLoader != null) {
+                final PhotoBitmapLoader loader = (PhotoBitmapLoader) fakePhotoLoader;
+                mResolvedPhotoUri = mAdapter.getPhotoUri(cursor);
+                loader.setPhotoUri(mResolvedPhotoUri);
+                loader.forceLoad();
             }
 
-            final PhotoBitmapLoader loader =
-                    (PhotoBitmapLoader) fakeLoader;
-            mResolvedPhotoUri = mAdapter.getPhotoUri(cursor);
-            loader.setPhotoUri(mResolvedPhotoUri);
-            loader.forceLoad();
+            if (!mThumbnailShown) {
+                final Loader<Bitmap> fakeThumbnailLoader = manager.getLoader(LOADER_ID_THUMBNAIL);
+                if (fakeThumbnailLoader != null) {
+                    final PhotoBitmapLoader loader = (PhotoBitmapLoader) fakeThumbnailLoader;
+                    mThumbnailUri = mAdapter.getThumbnailUri(cursor);
+                    loader.setPhotoUri(mThumbnailUri);
+                    loader.forceLoad();
+                }
+            }
         }
     }