Skip to content

Commit

Permalink
Fix threading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
marczych committed Jul 5, 2012
1 parent eda865d commit fc62282
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions library/src/com/ifixit/android/imagemanager/ImageManager.java
Expand Up @@ -254,22 +254,24 @@ private void writeFile(Bitmap bitmap, String url) {
}

private void storeImage(String url, Bitmap bitmap) {
StoredBitmap storedBitmap = new StoredBitmap(null, url);
int index = mRecentImages.indexOf(storedBitmap);
synchronized (mRecentImages) {
StoredBitmap storedBitmap = new StoredBitmap(null, url);
int index = mRecentImages.indexOf(storedBitmap);

// Already in list, lets move it to the front
if (index != -1) {
storedBitmap = mRecentImages.get(index);
mRecentImages.remove(index);
} else {
storedBitmap.mBitmap = bitmap;
}
// Already in list, lets move it to the front
if (index != -1) {
storedBitmap = mRecentImages.get(index);
mRecentImages.remove(index);
} else {
storedBitmap.mBitmap = bitmap;
}

while (mRecentImages.size() >= mMaxStoredImages) {
mRecentImages.removeLast();
}
while (mRecentImages.size() >= mMaxStoredImages) {
mRecentImages.removeLast();
}

mRecentImages.addFirst(new StoredBitmap(bitmap, url));
mRecentImages.addFirst(new StoredBitmap(bitmap, url));
}
}

private class StoredBitmap {
Expand Down

0 comments on commit fc62282

Please sign in to comment.