Skip to content

Commit 63c966d

Browse files
committed
Update OkHttpImageDownloader.java
Support contentLength for OkHttp, so ImageLoadingProgressListener's onProgressUpdate will report correct values
1 parent 3acca4a commit 63c966d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sample/src/main/java/com/nostra13/universalimageloader/sample/ext/OkHttpImageDownloader.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* Implementation of ImageDownloader which uses {@link com.squareup.okhttp.OkHttpClient} for image stream retrieving.
2828
*
2929
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
30+
* @author Leo Link (mr[dot]leolink[at]gmail[dot]com)
3031
*/
3132
public class OkHttpImageDownloader extends BaseImageDownloader {
3233

@@ -40,6 +41,9 @@ public OkHttpImageDownloader(Context context, OkHttpClient client) {
4041
@Override
4142
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
4243
Request request = new Request.Builder().url(imageUri).build();
43-
return client.newCall(request).execute().body().byteStream();
44+
ResponseBody responseBody = client.newCall(request).execute().body();
45+
InputStream inputStream = responseBody.byteStream();
46+
int contentLength = (int) responseBody.contentLength();
47+
return new ContentLengthInputStream(inputStream, contentLength);
4448
}
4549
}

0 commit comments

Comments
 (0)