Browse Source

merge createRequest and getResponse

pull/54/head
Thodoris1999 6 years ago
parent
commit
f400960548
  1. 10
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/NetworkTask.java

10
app/src/main/java/gr/thmmy/mthmmy/utils/parsing/NetworkTask.java

@ -30,11 +30,13 @@ public abstract class NetworkTask<T> extends ExternalAsyncTask<String, Parcel<T>
@Override @Override
protected final Parcel<T> doInBackground(String... input) { protected final Parcel<T> doInBackground(String... input) {
Request request = createRequest(input); Response response = sendRequest(BaseApplication.getInstance().getClient(), input);
Response response = getResponse(request, BaseApplication.getInstance().getClient());
String responseBodyString; String responseBodyString;
try { try {
responseBodyString = response.body().string(); responseBodyString = response.body().string();
} catch (NullPointerException npe) {
Timber.e(npe, "Invalid response. Detatails: https://square.github.io/okhttp/3.x/okhttp/okhttp3/Response.html#body--");
return new Parcel<>(Parcel.ResultCode.NETWORK_ERROR, null);
} catch (IOException e) { } catch (IOException e) {
Timber.e(e); Timber.e(e);
return new Parcel<>(Parcel.ResultCode.NETWORK_ERROR, null); return new Parcel<>(Parcel.ResultCode.NETWORK_ERROR, null);
@ -60,9 +62,7 @@ public abstract class NetworkTask<T> extends ExternalAsyncTask<String, Parcel<T>
super.onPostExecute(tParcel); super.onPostExecute(tParcel);
} }
protected abstract Request createRequest(String... input); protected abstract Response sendRequest(OkHttpClient client, String... input);
protected abstract Response getResponse(Request request, OkHttpClient client);
protected abstract T performTask(Document document) throws ParseException; protected abstract T performTask(Document document) throws ParseException;

Loading…
Cancel
Save