Permalink
Browse files

[Mobile,Wear,Widget] Updated to v2 of Luas RTPI API. This is actually…

… broken, pending updates to the API backend, but committing here as the code is in production. A fix is currently in testing.
  • Loading branch information...
thecosmicfrog committed Dec 4, 2017
1 parent 23d8ef4 commit 563e889f451f9cf13442c8dd84c28906f5194ec4
@@ -785,6 +785,7 @@ public void run() {
private void loadStopForecast(String stopName) {
final String API_URL = "https://api.thecosmicfrog.org/cgi-bin";
final String API_ACTION = "times";
final String API_VER = "2";
setIsLoading(true);
@@ -876,6 +877,7 @@ public void failure(RetrofitError retrofitError) {
/* Call API and get stop forecast from server. */
methods.getStopForecast(
API_ACTION,
API_VER,
mapStopNameId.get(stopName),
callback
);
@@ -898,15 +900,15 @@ private void updateStopForecast(StopForecast stopForecast) {
/* If a valid stop forecast exists... */
if (stopForecast != null) {
String status;
boolean operatingNormally = stopForecast.getOperatingNormally();
if (localeDefault.startsWith(GAEILGE)) {
status = getString(R.string.message_success);
} else {
status = stopForecast.getMessage();
}
if (status.contains(
getString(R.string.message_success))) {
if (operatingNormally) {
/*
* No error message on server. Change the message title TextView to
* green and set a default success message.
@@ -40,6 +40,7 @@ void getFares(
@GET("/luas-api.php")
void getStopForecast(
@Query("action") String action,
@Query("ver") String ver,
@Query("station") String station,
Callback<ApiTimes> cb
);
@@ -28,12 +28,22 @@
public class ApiTimes {
private String message;
private boolean forecastsEnabled;
private boolean operatingNormally;
private List<Tram> trams;
public String getMessage() {
return message;
}
public boolean getForecastsEnabled() {
return forecastsEnabled;
}
public boolean getOperatingNormally() {
return operatingNormally;
}
public List<Tram> getTrams() {
return trams;
}
@@ -42,6 +52,14 @@ public void setMessage(String m) {
message = m;
}
public void setForecastsEnabled(boolean f) {
forecastsEnabled = f;
}
public void setOperatingNormally(boolean o) {
operatingNormally = o;
}
public void setTrams(List<Tram> t) {
trams = t;
}
@@ -32,6 +32,8 @@
private final String LOG_TAG = StopForecast.class.getSimpleName();
private String message;
private boolean forecastsEnabled;
private boolean operatingNormally;
private List<Tram> inboundTrams;
private List<Tram> outboundTrams;
@@ -56,6 +58,14 @@ public void setMessage(String m) {
message = m;
}
public void setForecastsEnabled(boolean f) {
forecastsEnabled = f;
}
public void setOperatingNormally(boolean o) {
operatingNormally = o;
}
public void setInboundTrams(List<Tram> i) {
inboundTrams = i;
}
@@ -68,6 +78,14 @@ public String getMessage() {
return message;
}
public boolean getForecastsEnabled() {
return forecastsEnabled;
}
public boolean getOperatingNormally() {
return operatingNormally;
}
public List<Tram> getInboundTrams() {
return inboundTrams;
}
@@ -126,6 +126,7 @@ public void onMessageReceived(MessageEvent messageEvent) {
private void fetchStopForecast(String stopName) {
final String API_URL = "https://api.thecosmicfrog.org/cgi-bin";
final String API_ACTION = "times";
final String API_VER = "2";
/*
* Prepare Retrofit API call.
@@ -210,6 +211,7 @@ public void failure(RetrofitError retrofitError) {
*/
methods.getStopForecast(
API_ACTION,
API_VER,
mapStopNameId.get(stopName),
callback
);
@@ -203,6 +203,7 @@ private void loadStopForecast(final Context context,final AppWidgetManager appWi
/* API constants. */
final String API_URL = "https://api.thecosmicfrog.org/cgi-bin";
final String API_ACTION = "times";
final String API_VER = "2";
/* Instantiate a new EnglishGaeilgeMap. */
mapEnglishGaeilge = new EnglishGaeilgeMap();
@@ -308,6 +309,7 @@ public void failure(RetrofitError retrofitError) {
*/
methods.getStopForecast(
API_ACTION,
API_VER,
mapStopNameId.get(stopName),
callback
);
@@ -160,6 +160,12 @@ public static void displayTutorial(View rootView, String line, String tutorial,
public static StopForecast createStopForecast(ApiTimes apiTimes) {
StopForecast stopForecast = new StopForecast();
if (apiTimes.getMessage() != null) {
stopForecast.setMessage(apiTimes.getMessage());
}
stopForecast.setOperatingNormally(apiTimes.getOperatingNormally());
if (apiTimes.getTrams() != null) {
for (Tram tram : apiTimes.getTrams()) {
switch (tram.getDirection()) {
@@ -180,8 +186,6 @@ public static StopForecast createStopForecast(ApiTimes apiTimes) {
}
}
stopForecast.setMessage(apiTimes.getMessage());
return stopForecast;
}
}

0 comments on commit 563e889

Please sign in to comment.