android: fix when in dev mode, asset resource cannot be downloaded

This commit is contained in:
pengfei.zhou 2022-08-02 14:17:19 +08:00 committed by osborn
parent 7f6710a7b5
commit ee9b8102f2

View File

@ -18,15 +18,19 @@ package pub.doric.resource;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder; import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.Key;
import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.signature.ObjectKey;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.security.MessageDigest;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import pub.doric.DoricContext; import pub.doric.DoricContext;
import pub.doric.async.AsyncResult; import pub.doric.async.AsyncResult;
@ -51,10 +55,15 @@ public class DoricRemoteResource extends DoricResource {
@Override @Override
public AsyncResult<byte[]> fetchRaw() { public AsyncResult<byte[]> fetchRaw() {
final AsyncResult<byte[]> result = new AsyncResult<>(); final AsyncResult<byte[]> result = new AsyncResult<>();
RequestBuilder<File> requestBuilder = Glide.with(doricContext.getContext()).download(identifier); RequestBuilder<File> requestBuilder = Glide.with(doricContext.getContext())
.download(identifier);
if (!this.needCache) { if (!this.needCache) {
requestBuilder = requestBuilder.diskCacheStrategy(DiskCacheStrategy.NONE) requestBuilder = requestBuilder.skipMemoryCache(true).signature(new Key() {
.skipMemoryCache(true); @Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update(toString().getBytes(CHARSET));
}
});
} }
requestBuilder requestBuilder
.listener(new RequestListener<File>() { .listener(new RequestListener<File>() {
@ -83,6 +92,9 @@ public class DoricRemoteResource extends DoricResource {
} }
} }
} }
if (!needCache) {
resource.delete();
}
return false; return false;
} }
}) })