glide image loading timeout increase

后端 未结 5 1059
半阙折子戏
半阙折子戏 2020-12-15 08:03

I am using glide to load images from URL. While I am fetching the images I am showing a loader in the image view. Some of the images being fetched are larger and therefore

5条回答
  •  無奈伤痛
    2020-12-15 08:43

    If you would like to use OkHttp, please import glide:okhttp-integration according to this, and then implement your own OkHttpGlideModule:

    @GlideModule
    public class CustomGlideModule extends OkHttpGlideModule {
        @Override
        public void applyOptions(Context context, GlideBuilder builder) {
            // stub
        }
    
        @Override
        public void registerComponents(Context context, Glide glide) {
            final OkHttpClient.Builder builder = new OkHttpClient.Builder();
    
            // set your timeout here
            builder.readTimeout(30, TimeUnit.SECONDS);
            builder.writeTimeout(30, TimeUnit.SECONDS);
            builder.connectTimeout(30, TimeUnit.SECONDS);
    
            glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(builder.build()));
        }
    }
    

提交回复
热议问题