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);
}
});
}
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();
}
Aggregations