Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/backend/FiveTAPIVolleyRequest.java
Show All 31 Lines | |||||
/** | /** | ||||
* Class to handle request with the Volley Library | * Class to handle request with the Volley Library | ||||
*/ | */ | ||||
public class FiveTAPIVolleyRequest extends Request<Palina> { | public class FiveTAPIVolleyRequest extends Request<Palina> { | ||||
private static final String LOG_TAG = "BusTO-FiveTAPIVolleyReq"; | private static final String LOG_TAG = "BusTO-FiveTAPIVolleyReq"; | ||||
private ResponseListener listener; | private ResponseListener listener; | ||||
final private String url,stopID; | final private String url,stopID; | ||||
final private AtomicReference<Fetcher.result> resultRef; | final private AtomicReference<Fetcher.Result> resultRef; | ||||
final private FiveTAPIFetcher fetcher; | final private FiveTAPIFetcher fetcher; | ||||
final private FiveTAPIFetcher.QueryType type; | final private FiveTAPIFetcher.QueryType type; | ||||
private FiveTAPIVolleyRequest(int method, String url, String stopID, FiveTAPIFetcher.QueryType kind, | private FiveTAPIVolleyRequest(int method, String url, String stopID, FiveTAPIFetcher.QueryType kind, | ||||
ResponseListener listener, | ResponseListener listener, | ||||
@Nullable Response.ErrorListener errorListener) { | @Nullable Response.ErrorListener errorListener) { | ||||
Show All 34 Lines | protected Response<Palina> parseNetworkResponse(NetworkResponse response) { | ||||
case DETAILS: | case DETAILS: | ||||
routeList = fetcher.parseDirectionsFromResponse(stringResponse); | routeList = fetcher.parseDirectionsFromResponse(stringResponse); | ||||
break; | break; | ||||
default: | default: | ||||
//empty | //empty | ||||
return Response.error(new VolleyError("Invalid query type")); | return Response.error(new VolleyError("Invalid query type")); | ||||
} | } | ||||
} catch (JSONException e) { | } catch (JSONException e) { | ||||
resultRef.set(Fetcher.result.PARSER_ERROR); | resultRef.set(Fetcher.Result.PARSER_ERROR); | ||||
//e.printStackTrace(); | //e.printStackTrace(); | ||||
Log.w("FivetVolleyParser","JSON Exception in parsing response of: "+url); | Log.w("FivetVolleyParser","JSON Exception in parsing response of: "+url); | ||||
return Response.error(new ParseError(response)); | return Response.error(new ParseError(response)); | ||||
} | } | ||||
if(resultRef.get()== Fetcher.result.PARSER_ERROR){ | if(resultRef.get()== Fetcher.Result.PARSER_ERROR){ | ||||
return Response.error(new ParseError(response)); | return Response.error(new ParseError(response)); | ||||
} | } | ||||
final Palina p = new Palina(stopID); | final Palina p = new Palina(stopID); | ||||
p.setRoutes(routeList); | p.setRoutes(routeList); | ||||
p.sortRoutes(); | p.sortRoutes(); | ||||
return Response.success(p, HttpHeaderParser.parseCacheHeaders(response)); | return Response.success(p, HttpHeaderParser.parseCacheHeaders(response)); | ||||
} | } | ||||
Show All 26 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register