Skip to content

Commit

Permalink
修复移除可能导致图片磁盘缓存初始化失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wyouflf committed Oct 19, 2014
1 parent a9b71b7 commit 9929936
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
10 changes: 5 additions & 5 deletions library/src/com/lidroid/xutils/BitmapUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ public <T extends View> void display(T container, String uri, BitmapDisplayConfi
return;
}

if (TextUtils.isEmpty(uri)) {
callBack.onLoadFailed(container, uri, displayConfig.getLoadFailedDrawable());
return;
}

container.clearAnimation();

if (callBack == null) {
Expand All @@ -234,11 +239,6 @@ public <T extends View> void display(T container, String uri, BitmapDisplayConfi

callBack.onPreLoad(container, uri, displayConfig);

if (TextUtils.isEmpty(uri)) {
callBack.onLoadFailed(container, uri, displayConfig.getLoadFailedDrawable());
return;
}

// find bitmap from mem cache.
Bitmap bitmap = globalConfig.getBitmapCache().getBitmapFromMemCache(uri, displayConfig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private BitmapGlobalConfig(Context context, String diskCachePath) {
initBitmapCache();
}

public static BitmapGlobalConfig getInstance(Context context, String diskCachePath) {
public synchronized static BitmapGlobalConfig getInstance(Context context, String diskCachePath) {

if (TextUtils.isEmpty(diskCachePath)) {
diskCachePath = OtherUtils.getDiskCacheDir(context, "xBitmapCache");
Expand Down
13 changes: 4 additions & 9 deletions library/src/com/lidroid/xutils/bitmap/core/BitmapCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,11 @@ public Bitmap downloadBitmap(String uri, BitmapDisplayConfig config, final Bitma

try {
Bitmap bitmap = null;

// try download to disk
if (globalConfig.isDiskCacheEnabled()) {
synchronized (mDiskCacheLock) {
// Wait for disk cache to initialize
while (!isDiskCacheReady) {
try {
mDiskCacheLock.wait();
} catch (Throwable e) {
break;
}
}
if (mDiskLruCache == null) {
initDiskCache();
}

if (mDiskLruCache != null) {
Expand Down Expand Up @@ -319,6 +313,7 @@ public void clearDiskCache() {
if (mDiskLruCache != null && !mDiskLruCache.isClosed()) {
try {
mDiskLruCache.delete();
mDiskLruCache.close();
} catch (Throwable e) {
LogUtils.e(e.getMessage(), e);
}
Expand Down

0 comments on commit 9929936

Please sign in to comment.