Skip to content
Permalink
Browse files

[Mobile,Widget] Status message and Alerts button no longer turn red w…

…hen a service outage is due to a lift not working.

[Widget] Changed to use status API. Remove unnecessary createStopForecast() method.
  • Loading branch information...
thecosmicfrog committed Jul 2, 2019
1 parent 82d8b3e commit 5a766c3c571c4dad12868a39439b7d2c3c5db91f
@@ -8,8 +8,8 @@ android {
applicationId "org.thecosmicfrog.luasataglance"
minSdkVersion 21
targetSdkVersion 28
versionCode 136
versionName "0.136"
versionCode 138
versionName "0.138"
}
buildTypes {
release {
@@ -976,7 +976,8 @@ private void updateStopForecast(StopForecast stopForecast) {
status = stopForecast.getMessage();
}

if (operatingNormally) {
/* A lot of Luas status messages relate to lifts being out of service. Ignore these. */
if (operatingNormally || status.toLowerCase().contains("lift")) {
/*
* No error message on server. Change the message title TextView to
* green and set a default success message.
@@ -45,9 +45,9 @@
import org.thecosmicfrog.luasataglance.object.EnglishGaeilgeMap;
import org.thecosmicfrog.luasataglance.object.StopForecast;
import org.thecosmicfrog.luasataglance.object.StopNameIdMap;
import org.thecosmicfrog.luasataglance.object.Tram;
import org.thecosmicfrog.luasataglance.util.Analytics;
import org.thecosmicfrog.luasataglance.util.Constant;
import org.thecosmicfrog.luasataglance.util.StopForecastUtil;

import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
@@ -207,7 +207,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";
final String API_VER = "3";

/* Instantiate a new EnglishGaeilgeMap. */
mapEnglishGaeilge = new EnglishGaeilgeMap();
@@ -252,7 +252,7 @@ public void success(ApiTimes apiTimes, Response response) {
/* If the server returned times. */
if (apiTimes != null) {
/* Then create a stop forecast with this data. */
StopForecast stopForecast = createStopForecast(apiTimes);
StopForecast stopForecast = StopForecastUtil.createStopForecast(apiTimes);

/* Update the stop forecast. */
updateStopForecast(context, views, stopForecast);
@@ -343,39 +343,6 @@ public void failure(RetrofitError retrofitError) {
stopForeground(true);
}

/**
* Create a usable stop forecast with the data returned from the server.
* @param apiTimes ApiTimes object created by Retrofit, containing raw stop forecast data.
* @return Usable stop forecast.
*/
private StopForecast createStopForecast(ApiTimes apiTimes) {
StopForecast stopForecast = new StopForecast();

if (apiTimes.getTrams() != null) {
for (Tram tram : apiTimes.getTrams()) {
switch (tram.getDirection()) {
case "Inbound":
stopForecast.addInboundTram(tram);

break;

case "Outbound":
stopForecast.addOutboundTram(tram);

break;

default:
/* If for some reason the direction doesn't make sense. */
Log.e(LOG_TAG, "Invalid direction: " + tram.getDirection());
}
}
}

stopForecast.setMessage(apiTimes.getMessage());

return stopForecast;
}

/**
* Make progress bar appear or disappear.
* @param loading Whether or not progress bar should animate.
@@ -465,39 +432,43 @@ private boolean saveSelectedStopName(Context context, String selectedStopName) {
private void updateStopForecast(Context context, RemoteViews views, StopForecast stopForecast) {
final String GAEILGE = "ga";

String message;

/* If a valid stop forecast exists... */
if (stopForecast != null) {
String status;
boolean operatingNormally = false;

if (stopForecast.getStopForecastStatusDirectionInbound().getOperatingNormally()
&& stopForecast.getStopForecastStatusDirectionOutbound().getOperatingNormally()) {
operatingNormally = true;
}

if (localeDefault.startsWith(GAEILGE)) {
message = getString(R.string.message_success);
status = getString(R.string.message_success);
} else {
message = stopForecast.getMessage();
status = stopForecast.getMessage();
}

mapEnglishGaeilge = new EnglishGaeilgeMap();

if (stopForecast.getMessage() != null) {
if (message.contains(getString(R.string.message_success))) {
/*
* No error message on server. Change the stop name TextView to green.
*/
views.setInt(
R.id.linearlayout_stop_name,
"setBackgroundResource",
R.color.message_success
);
} else {
Log.w(LOG_TAG, "Server has returned a service disruption or error.");
/* A lot of Luas status messages relate to lifts being out of service. Ignore these. */
if (operatingNormally || status.toLowerCase().contains("lift")) {
/*
* No error message on server. Change the stop name TextView to green.
*/
views.setInt(
R.id.linearlayout_stop_name,
"setBackgroundResource",
R.color.message_success
);
} else {
Log.w(LOG_TAG, "Server has returned a service disruption or error.");

views.setInt(
R.id.linearlayout_stop_name,
"setBackgroundResource",
R.color.message_error
);
}
views.setInt(
R.id.linearlayout_stop_name,
"setBackgroundResource",
R.color.message_error
);
}


/*
* Pull in all trams from the StopForecast, but only display up to two inbound
* and outbound trams.
@@ -24,7 +24,7 @@
<color name="luas_purple">#ff4d3475</color>
<color name="luas_purple_statusbar">#ff3f2a5f</color>
<color name="message_success">#ff006600</color>
<color name="message_not_running">#fff1A82e</color>
<color name="message_warning">#fff1A82e</color>
<color name="message_error">#ffe00000</color>
<color name="off_white">#fffafafa</color>
<color name="stop_forecast_border_grey">#fff5f5f5</color>
@@ -23,8 +23,8 @@
App
-->
<string name="app_name">Luas at a Glance</string>
<string name="version_code" translatable="false">136</string>
<string name="version_name" translatable="false">0.136</string>
<string name="version_code" translatable="false">138</string>
<string name="version_name" translatable="false">0.138</string>

<!--
Activities
@@ -167,19 +167,18 @@
<!--
What's New
-->
<string name="whatsnew_title_current" translatable="false">Version 0.136 (4th June 2019)
<string name="whatsnew_title_current" translatable="false">Version 0.138 (13th June 2019)
</string>
<string name="whatsnew_content_current" translatable="false">\u2022 [FIXED] Fixed issue where
a widget notification occasionally got stuck for some users. Thanks to everyone who reported
this!
<string name="whatsnew_content_current" translatable="false">\u2022 <b>Status</b> bar and
<b>Alerts</b> button no longer turn red when a lift is out of order. The associated message
will still be displayed.\n\u2022 Made widget status bar colour more reliable during Luas
service outages.
</string>
<string name="whatsnew_title_previous" translatable="false">Version 0.133 (17th May 2019)
<string name="whatsnew_title_previous" translatable="false">Version 0.136 (4th June 2019)
</string>
<string name="whatsnew_content_previous" translatable="false">\u2022 [NEW] You can now see your
Luas times without having to open the app! The homescreen widget is now considered stable,
with major crashes and bugs now fixed. To try it out, tap and hold on your device\'s
wallpaper and add the <b>Luas at a Glance</b> widget.\nPlease report any and all issues and
I\'ll be happy to fix them.
<string name="whatsnew_content_previous" translatable="false">\u2022 [FIXED] Fixed issue where
a widget notification occasionally got stuck for some users. Thanks to everyone who reported
this!
</string>

<!--
@@ -10,8 +10,8 @@ android {
applicationId "org.thecosmicfrog.luasataglance"
minSdkVersion 21
targetSdkVersion 28
versionCode 13600
versionName "0.136"
versionCode 13800
versionName "0.138"
}
buildTypes {
release {
@@ -23,7 +23,7 @@ android {
productFlavors {
wear2 {
minSdkVersion 25
versionCode 13601
versionCode 13801
}
}
}
@@ -23,8 +23,8 @@
App
-->
<string name="app_name">Luas at a Glance</string>
<string name="version_code" translatable="false">136</string>
<string name="version_name" translatable="false">0.136</string>
<string name="version_code" translatable="false">138</string>
<string name="version_name" translatable="false">0.138</string>

<!--
Activities

0 comments on commit 5a766c3

Please sign in to comment.
You can’t perform that action at this time.