Search in sources :

Example 1 with ProgressListener

use of me.zhanghai.android.douya.glide.progress.ProgressListener in project Douya by DreaminginCodeZH.

the class GalleryAdapter method loadImageForPosition.

private void loadImageForPosition(int position, ViewHolder holder) {
    ViewUtils.fadeIn(holder.progress);
    GlideApp.with(holder.progress.getContext()).downloadOnlyDefaultPriority().load(mImageList.get(position)).progressListener(new ProgressListener() {

        @Override
        public void onProgress(long bytesRead, long contentLength, boolean done) {
            int progress = Math.round((float) bytesRead / contentLength * holder.progress.getMax());
            ProgressBarCompat.setProgress(holder.progress, progress, true);
        }
    }).listener(new RequestListener<File>() {

        @Override
        public boolean onResourceReady(File resource, Object model, Target<File> target, DataSource dataSource, boolean isFirstResource) {
            return false;
        }

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<File> target, boolean isFirstResource) {
            showError(e, R.string.gallery_network_error, holder);
            return false;
        }
    }).into(new SimpleTarget<File>() {

        @Override
        public void onResourceReady(File file, Transition<? super File> transition) {
            mFileMap.put(position, file);
            if (mListener != null) {
                mListener.onFileDownloaded(position);
            }
            holder.progress.setIndeterminate(true);
            loadImageFromFile(file, holder);
        }
    });
}
Also used : RequestListener(com.bumptech.glide.request.RequestListener) DataSource(com.bumptech.glide.load.DataSource) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Target(com.bumptech.glide.request.target.Target) ProgressListener(me.zhanghai.android.douya.glide.progress.ProgressListener) File(java.io.File) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(androidx.annotation.Nullable)

Example 2 with ProgressListener

use of me.zhanghai.android.douya.glide.progress.ProgressListener in project Douya by DreaminginCodeZH.

the class OkHttpProgressInterceptor method intercept.

@Override
public Response intercept(@NonNull Chain chain) throws IOException {
    Request request = chain.request();
    Response response = chain.proceed(chain.request());
    Object requestTag = request.tag();
    if (!(requestTag instanceof ProgressListener)) {
        return response;
    }
    ProgressListener progressListener = (ProgressListener) requestTag;
    return response.newBuilder().body(new ProgressResponseBody(response.body(), progressListener)).build();
}
Also used : Response(okhttp3.Response) ProgressListener(me.zhanghai.android.douya.glide.progress.ProgressListener) Request(okhttp3.Request)

Aggregations

ProgressListener (me.zhanghai.android.douya.glide.progress.ProgressListener)2 Nullable (androidx.annotation.Nullable)1 DataSource (com.bumptech.glide.load.DataSource)1 GlideException (com.bumptech.glide.load.engine.GlideException)1 RequestListener (com.bumptech.glide.request.RequestListener)1 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)1 Target (com.bumptech.glide.request.target.Target)1 File (java.io.File)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1