protocolClass; private final Gson gson = new Gson(); private OnResponseListener
onResponseListener; + private OnErrorListener onErrorListener; + private volatile String error; public GetJsonAsyncTask(Class
protocolClass) {
this.protocolClass = protocolClass;
@@ -270,7 +286,7 @@ public class ReportsFragment extends BaseOsmAndFragment implements SearchSelecti
@Override
protected P doInBackground(String... params) {
StringBuilder response = new StringBuilder();
- String error = NetworkUtils.sendGetRequest(params[0], null, response);
+ error = NetworkUtils.sendGetRequest(params[0], null, response);
if (error == null) {
return gson.fromJson(response.toString(), protocolClass);
}
@@ -280,8 +296,10 @@ public class ReportsFragment extends BaseOsmAndFragment implements SearchSelecti
@Override
protected void onPostExecute(P protocol) {
- if (onResponseListener != null) {
+ if (protocol != null) {
onResponseListener.onResponse(protocol);
+ } else {
+ onErrorListener.onError(error);
}
}
@@ -289,9 +307,17 @@ public class ReportsFragment extends BaseOsmAndFragment implements SearchSelecti
this.onResponseListener = onResponseListener;
}
+ public void setOnErrorListener(OnErrorListener onErrorListener) {
+ this.onErrorListener = onErrorListener;
+ }
+
public interface OnResponseListener