Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split OkHttpNetworkFetcher's fetch method to make part of it reusable #1459

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,8 @@ public OkHttpNetworkFetchState createFetchState(
return new OkHttpNetworkFetchState(consumer, context);
}

@Override
public void fetch(final OkHttpNetworkFetchState fetchState, final Callback callback) {
fetchState.submitTime = SystemClock.elapsedRealtime();
final Uri uri = fetchState.getUri();
final Request request = new Request.Builder()
.cacheControl(new CacheControl.Builder().noStore().build())
.url(uri.toString())
.get()
.build();
protected void fetchWithRequest(final OkHttpNetworkFetchState fetchState, final Callback callback,
Copy link
Contributor

@lambdapioneer lambdapioneer Oct 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move this method below the other public methods and re-format:

protected void fetchWithRequest(
    final OkHttpNetworkFetchState fetchState,
    final Callback callback,
    final Request request) {

final Request request) {
final Call call = mOkHttpClient.newCall(request);

fetchState.getContext().addCallbacks(
Expand Down Expand Up @@ -109,9 +102,9 @@ public void onResponse(Call call, Response response) throws IOException {
try {
if (!response.isSuccessful()) {
handleException(
call,
new IOException("Unexpected HTTP code " + response),
callback);
call,
Copy link
Contributor

@lambdapioneer lambdapioneer Oct 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

new IOException("Unexpected HTTP code " + response),
callback);
return;
}

Expand All @@ -138,6 +131,18 @@ public void onFailure(Call call, IOException e) {
});
}

@Override
public void fetch(final OkHttpNetworkFetchState fetchState, final Callback callback) {
fetchState.submitTime = SystemClock.elapsedRealtime();
final Uri uri = fetchState.getUri();
final Request request = new Request.Builder()
.cacheControl(new CacheControl.Builder().noStore().build())
.url(uri.toString())
.get()
.build();
fetchWithRequest(fetchState, callback, request);
}

@Override
public void onFetchCompletion(OkHttpNetworkFetchState fetchState, int byteSize) {
fetchState.fetchCompleteTime = SystemClock.elapsedRealtime();
Expand Down