Hippy icon indicating copy to clipboard operation
Hippy copied to clipboard

3.0Android图片三级缓存如何实现

Open Ghoulers opened this issue 7 months ago • 2 comments

3.0Android图片三级缓存如何实现

Ghoulers avatar May 14 '25 07:05 Ghoulers

引擎初始化的时候,可以自定义processor实现

Processor customProcessor = new CustomProcessor()
List<Processor> processors = new ArrayList<>();
processors.add(customProcessor);
initParams.processors = processors;

// 使用glide图片缓存库
public class CustomProcessor extends Processor {
      @override
       public void handleRequestAsync(ResourceHolder holder, VfsManager.ProcessorCallback callback) {
             if (holder.requestParams != null && holder.requestParams.get(ImageLoader.REQUEST_CONTENT_TYPE) != null && holder.requestParams.get(ImageLoader.REQUEST_CONTENT_TYPE)
                        .equals(ImageLoader.REQUEST_CONTENT_TYPE_IMAGE)) {
                           int width = Integer.valueOf(holder.requestParams.get("width"));
                           int height = Integer.valueOf(holder.requestParams.get("height"));
                           if (width == 0) {
                                   width = Target.SIZE_ORIGINAL;
                           }

                          if (height == 0) {
                                   height = Target.SIZE_ORIGINAL;
                           }
                          
                          Bitmap bitmap = Glide.with(context)
                                   .asBitmap()
                                   .load(holder.uri)
                                   .submit(width, height)
                                  .get()
                           holder.bitmap = bitmap;
                           holder.resultCode = HippyResourceLoader.FetchResultCode.OK.oridinal();
                           callback.onHandleCompleted();
                           return;
                 }
                  
                callback.goNext();
        }

}

mason-Wang avatar May 20 '25 08:05 mason-Wang

Bitmap bitmap = Glide.with(context) .asBitmap() .load(holder.uri) .submit(width, height) .get() glide 这种同步执行在主线程会报错。使用异步操作,onResourceReady 后执行callback.onHandleCompleted(); 会导致图片错乱显示。

HeWenhui avatar Jun 10 '25 07:06 HeWenhui

Pay attention 🛎️ !! There has been no activity on this issue for 2 months, so I will label it stalled. It will be automatically closed in 60 days if no more activity. Feel free to leave a comment if you have any questions.

hippy-service[bot] avatar Aug 09 '25 19:08 hippy-service[bot]

Sorry, closing this issue because it has stalled for over 3 months. Feel free to reopen if this issue is still relevant, or to ping the collaborator if you have any questions.

hippy-service[bot] avatar Sep 08 '25 19:09 hippy-service[bot]