Fixed bug caused by batching responses in the ImageLoader

If the first call to batchResponse passes a VolleyError,
then all responses from that batch would show an error even
if some of them succeeded. This fixes the bug by setting the
error per BatchedImageRequest rather than for the batch.

Change-Id: I2543d2d6f4154c33ba072d7f97aee9dc67f3300e
Signed-off-by: Cameron Ketcham <cketcham@gmail.com>
diff --git a/src/com/android/volley/toolbox/ImageLoader.java b/src/com/android/volley/toolbox/ImageLoader.java
index 0e72928..b6af8f1 100755
--- a/src/com/android/volley/toolbox/ImageLoader.java
+++ b/src/com/android/volley/toolbox/ImageLoader.java
@@ -248,7 +248,7 @@
             request.mResponseBitmap = response;
 
             // Send the batched response
-            batchResponse(cacheKey, request, null);
+            batchResponse(cacheKey, request);
         }
     }
 
@@ -261,9 +261,12 @@
         // Remove this request from the list of in-flight requests.
         BatchedImageRequest request = mInFlightRequests.remove(cacheKey);
 
+        // Set the error for this request
+        request.setError(error);
+
         if (request != null) {
             // Send the batched response
-            batchResponse(cacheKey, request, error);
+            batchResponse(cacheKey, request);
         }
     }
 
@@ -351,6 +354,9 @@
         /** The result of the request being tracked by this item */
         private Bitmap mResponseBitmap;
 
+        /** Error if one occurred for this response */
+        private VolleyError mError;
+
         /** List of all of the active ImageContainers that are interested in the request */
         private final LinkedList<ImageContainer> mContainers = new LinkedList<ImageContainer>();
 
@@ -365,6 +371,20 @@
         }
 
         /**
+         * Set the error for this response
+         */
+        public void setError(VolleyError error) {
+            mError = error;
+        }
+
+        /**
+         * Get the error for this response
+         */
+        public VolleyError getError() {
+            return mError;
+        }
+
+        /**
          * Adds another ImageContainer to the list of those interested in the results of
          * the request.
          */
@@ -394,8 +414,7 @@
      * @param request The BatchedImageRequest to be delivered.
      * @param error The volley error associated with the request (if applicable).
      */
-    private void batchResponse(String cacheKey, BatchedImageRequest request,
-            final VolleyError error) {
+    private void batchResponse(String cacheKey, BatchedImageRequest request) {
         mBatchedResponses.put(cacheKey, request);
         // If we don't already have a batch delivery runnable in flight, make a new one.
         // Note that this will be used to deliver responses to all callers in mBatchedResponses.
@@ -411,11 +430,11 @@
                             if (container.mListener == null) {
                                 continue;
                             }
-                            if (error == null) {
+                            if (bir.getError() == null) {
                                 container.mBitmap = bir.mResponseBitmap;
                                 container.mListener.onResponse(container, false);
                             } else {
-                                container.mListener.onErrorResponse(error);
+                                container.mListener.onErrorResponse(bir.getError());
                             }
                         }
                     }