Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix threading issue

  • Loading branch information...
commit fc6228227e6f3c14754c1604ce80529497caec5b 1 parent eda865d
@marczych authored
Showing with 15 additions and 13 deletions.
  1. +15 −13 library/src/com/ifixit/android/imagemanager/ImageManager.java
View
28 library/src/com/ifixit/android/imagemanager/ImageManager.java
@@ -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 {
Please sign in to comment.
Something went wrong with that request. Please try again.