Fixed some l8n around weather conditions
We were fetching description from the server as a string instead of using the weather ID and an internal string that can be translated.
This commit is contained in:
@@ -193,8 +193,8 @@ public class DetailFragment extends Fragment implements LoaderManager.LoaderCall
|
|||||||
mFriendlyDateView.setText(friendlyDateText);
|
mFriendlyDateView.setText(friendlyDateText);
|
||||||
mDateView.setText(dateText);
|
mDateView.setText(dateText);
|
||||||
|
|
||||||
// Read description from cursor and update view
|
// Get description from weather condition ID
|
||||||
String description = data.getString(COL_WEATHER_DESC);
|
String description = Utility.getStringForWeatherCondition(getActivity(), weatherId);
|
||||||
mDescriptionView.setText(description);
|
mDescriptionView.setText(description);
|
||||||
|
|
||||||
// For accessibility, add a content description to the icon field
|
// For accessibility, add a content description to the icon field
|
||||||
|
|||||||
@@ -90,17 +90,18 @@ public class ForecastAdapter extends CursorAdapter {
|
|||||||
ViewHolder viewHolder = (ViewHolder) view.getTag();
|
ViewHolder viewHolder = (ViewHolder) view.getTag();
|
||||||
|
|
||||||
int viewType = getItemViewType(cursor.getPosition());
|
int viewType = getItemViewType(cursor.getPosition());
|
||||||
|
int weatherId = cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID);
|
||||||
switch (viewType) {
|
switch (viewType) {
|
||||||
case VIEW_TYPE_TODAY: {
|
case VIEW_TYPE_TODAY: {
|
||||||
// Get weather icon
|
// Get weather icon
|
||||||
viewHolder.iconView.setImageResource(Utility.getArtResourceForWeatherCondition(
|
viewHolder.iconView.setImageResource(Utility.getArtResourceForWeatherCondition(
|
||||||
cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID)));
|
weatherId));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case VIEW_TYPE_FUTURE_DAY: {
|
case VIEW_TYPE_FUTURE_DAY: {
|
||||||
// Get weather icon
|
// Get weather icon
|
||||||
viewHolder.iconView.setImageResource(Utility.getIconResourceForWeatherCondition(
|
viewHolder.iconView.setImageResource(Utility.getIconResourceForWeatherCondition(
|
||||||
cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID)));
|
weatherId));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,8 +111,8 @@ public class ForecastAdapter extends CursorAdapter {
|
|||||||
// Find TextView and set formatted date on it
|
// Find TextView and set formatted date on it
|
||||||
viewHolder.dateView.setText(Utility.getFriendlyDayString(context, dateInMillis));
|
viewHolder.dateView.setText(Utility.getFriendlyDayString(context, dateInMillis));
|
||||||
|
|
||||||
// Read weather forecast from cursor
|
// Get description from weather condition ID
|
||||||
String description = cursor.getString(ForecastFragment.COL_WEATHER_DESC);
|
String description = Utility.getStringForWeatherCondition(context, weatherId);
|
||||||
// Find TextView and set weather forecast on it
|
// Find TextView and set weather forecast on it
|
||||||
viewHolder.descriptionView.setText(description);
|
viewHolder.descriptionView.setText(description);
|
||||||
|
|
||||||
|
|||||||
@@ -251,6 +251,184 @@ public class Utility {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to provide the string according to the weather
|
||||||
|
* condition id returned by the OpenWeatherMap call.
|
||||||
|
* @param context Android context
|
||||||
|
* @param weatherId from OpenWeatherMap API response
|
||||||
|
* @return string for the weather condition. null if no relation is found.
|
||||||
|
*/
|
||||||
|
public static String getStringForWeatherCondition(Context context, int weatherId) {
|
||||||
|
// Based on weather code data found at:
|
||||||
|
// http://bugs.openweathermap.org/projects/api/wiki/Weather_Condition_Codes
|
||||||
|
int stringId;
|
||||||
|
if (weatherId >= 200 && weatherId <= 232) {
|
||||||
|
stringId = R.string.condition_2xx;
|
||||||
|
} else if (weatherId >= 300 && weatherId <= 321) {
|
||||||
|
stringId = R.string.condition_3xx;
|
||||||
|
} else switch(weatherId) {
|
||||||
|
case 500:
|
||||||
|
stringId = R.string.condition_500;
|
||||||
|
break;
|
||||||
|
case 501:
|
||||||
|
stringId = R.string.condition_501;
|
||||||
|
break;
|
||||||
|
case 502:
|
||||||
|
stringId = R.string.condition_502;
|
||||||
|
break;
|
||||||
|
case 503:
|
||||||
|
stringId = R.string.condition_503;
|
||||||
|
break;
|
||||||
|
case 504:
|
||||||
|
stringId = R.string.condition_504;
|
||||||
|
break;
|
||||||
|
case 511:
|
||||||
|
stringId = R.string.condition_511;
|
||||||
|
break;
|
||||||
|
case 520:
|
||||||
|
stringId = R.string.condition_520;
|
||||||
|
break;
|
||||||
|
case 531:
|
||||||
|
stringId = R.string.condition_531;
|
||||||
|
break;
|
||||||
|
case 600:
|
||||||
|
stringId = R.string.condition_600;
|
||||||
|
break;
|
||||||
|
case 601:
|
||||||
|
stringId = R.string.condition_601;
|
||||||
|
break;
|
||||||
|
case 602:
|
||||||
|
stringId = R.string.condition_602;
|
||||||
|
break;
|
||||||
|
case 611:
|
||||||
|
stringId = R.string.condition_611;
|
||||||
|
break;
|
||||||
|
case 612:
|
||||||
|
stringId = R.string.condition_612;
|
||||||
|
break;
|
||||||
|
case 615:
|
||||||
|
stringId = R.string.condition_615;
|
||||||
|
break;
|
||||||
|
case 616:
|
||||||
|
stringId = R.string.condition_616;
|
||||||
|
break;
|
||||||
|
case 620:
|
||||||
|
stringId = R.string.condition_620;
|
||||||
|
break;
|
||||||
|
case 621:
|
||||||
|
stringId = R.string.condition_621;
|
||||||
|
break;
|
||||||
|
case 622:
|
||||||
|
stringId = R.string.condition_622;
|
||||||
|
break;
|
||||||
|
case 701:
|
||||||
|
stringId = R.string.condition_701;
|
||||||
|
break;
|
||||||
|
case 711:
|
||||||
|
stringId = R.string.condition_711;
|
||||||
|
break;
|
||||||
|
case 721:
|
||||||
|
stringId = R.string.condition_721;
|
||||||
|
break;
|
||||||
|
case 731:
|
||||||
|
stringId = R.string.condition_731;
|
||||||
|
break;
|
||||||
|
case 741:
|
||||||
|
stringId = R.string.condition_741;
|
||||||
|
break;
|
||||||
|
case 751:
|
||||||
|
stringId = R.string.condition_751;
|
||||||
|
break;
|
||||||
|
case 761:
|
||||||
|
stringId = R.string.condition_761;
|
||||||
|
break;
|
||||||
|
case 762:
|
||||||
|
stringId = R.string.condition_762;
|
||||||
|
break;
|
||||||
|
case 771:
|
||||||
|
stringId = R.string.condition_771;
|
||||||
|
break;
|
||||||
|
case 781:
|
||||||
|
stringId = R.string.condition_781;
|
||||||
|
break;
|
||||||
|
case 800:
|
||||||
|
stringId = R.string.condition_800;
|
||||||
|
break;
|
||||||
|
case 801:
|
||||||
|
stringId = R.string.condition_801;
|
||||||
|
break;
|
||||||
|
case 802:
|
||||||
|
stringId = R.string.condition_802;
|
||||||
|
break;
|
||||||
|
case 803:
|
||||||
|
stringId = R.string.condition_803;
|
||||||
|
break;
|
||||||
|
case 804:
|
||||||
|
stringId = R.string.condition_804;
|
||||||
|
break;
|
||||||
|
case 900:
|
||||||
|
stringId = R.string.condition_900;
|
||||||
|
break;
|
||||||
|
case 901:
|
||||||
|
stringId = R.string.condition_901;
|
||||||
|
break;
|
||||||
|
case 902:
|
||||||
|
stringId = R.string.condition_902;
|
||||||
|
break;
|
||||||
|
case 903:
|
||||||
|
stringId = R.string.condition_903;
|
||||||
|
break;
|
||||||
|
case 904:
|
||||||
|
stringId = R.string.condition_904;
|
||||||
|
break;
|
||||||
|
case 905:
|
||||||
|
stringId = R.string.condition_905;
|
||||||
|
break;
|
||||||
|
case 906:
|
||||||
|
stringId = R.string.condition_906;
|
||||||
|
break;
|
||||||
|
case 951:
|
||||||
|
stringId = R.string.condition_951;
|
||||||
|
break;
|
||||||
|
case 952:
|
||||||
|
stringId = R.string.condition_952;
|
||||||
|
break;
|
||||||
|
case 953:
|
||||||
|
stringId = R.string.condition_953;
|
||||||
|
break;
|
||||||
|
case 954:
|
||||||
|
stringId = R.string.condition_954;
|
||||||
|
break;
|
||||||
|
case 955:
|
||||||
|
stringId = R.string.condition_955;
|
||||||
|
break;
|
||||||
|
case 956:
|
||||||
|
stringId = R.string.condition_956;
|
||||||
|
break;
|
||||||
|
case 957:
|
||||||
|
stringId = R.string.condition_957;
|
||||||
|
break;
|
||||||
|
case 958:
|
||||||
|
stringId = R.string.condition_958;
|
||||||
|
break;
|
||||||
|
case 959:
|
||||||
|
stringId = R.string.condition_959;
|
||||||
|
break;
|
||||||
|
case 960:
|
||||||
|
stringId = R.string.condition_960;
|
||||||
|
break;
|
||||||
|
case 961:
|
||||||
|
stringId = R.string.condition_961;
|
||||||
|
break;
|
||||||
|
case 962:
|
||||||
|
stringId = R.string.condition_962;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return context.getString(R.string.condition_unknown, weatherId);
|
||||||
|
}
|
||||||
|
return context.getString(stringId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the network is available or about to become available.
|
* Returns true if the network is available or about to become available.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -123,4 +123,63 @@
|
|||||||
<string name="empty_forecast_list_server_error">No weather information available. The server is not returning valid data. Please check for an updated version of Sunshine.</string>
|
<string name="empty_forecast_list_server_error">No weather information available. The server is not returning valid data. Please check for an updated version of Sunshine.</string>
|
||||||
<string name="empty_forecast_list_invalid_location">No weather information available. The location in settings is not recognized by the weather server.</string>
|
<string name="empty_forecast_list_invalid_location">No weather information available. The location in settings is not recognized by the weather server.</string>
|
||||||
|
|
||||||
|
<!-- Weather Conditions -->
|
||||||
|
<string name="condition_2xx">Storm</string>
|
||||||
|
<string name="condition_3xx">Drizzle</string>
|
||||||
|
<string name="condition_500">Light Rain</string>
|
||||||
|
<string name="condition_501">Moderate Rain</string>
|
||||||
|
<string name="condition_502">Heavy Rain</string>
|
||||||
|
<string name="condition_503">Intense Rain</string>
|
||||||
|
<string name="condition_504">Extreme Rain</string>
|
||||||
|
<string name="condition_511">Freezing Rain</string>
|
||||||
|
<string name="condition_520">Light Shower</string>
|
||||||
|
<string name="condition_521">Shower</string>
|
||||||
|
<string name="condition_522">Heavy Shower</string>
|
||||||
|
<string name="condition_531">Ragged Shower</string>
|
||||||
|
<string name="condition_600">Light Snow</string>
|
||||||
|
<string name="condition_601">Snow</string>
|
||||||
|
<string name="condition_602">Heavy Snow</string>
|
||||||
|
<string name="condition_611">Sleet</string>
|
||||||
|
<string name="condition_612">Shower Sleet</string>
|
||||||
|
<string name="condition_615">Rain and Snow</string> <!-- light rain and snow -->
|
||||||
|
<string name="condition_616">Rain and Snow</string>
|
||||||
|
<string name="condition_620">Shower Snow</string> <!-- light shower snow -->
|
||||||
|
<string name="condition_621">Shower Snow</string>
|
||||||
|
<string name="condition_622">Shower Snow</string> <!-- heavy shower snow -->
|
||||||
|
<string name="condition_701">Mist</string>
|
||||||
|
<string name="condition_711">Smoke</string>
|
||||||
|
<string name="condition_721">Haze</string>
|
||||||
|
<string name="condition_731">Sand, Dust</string>
|
||||||
|
<string name="condition_741">Fog</string>
|
||||||
|
<string name="condition_751">Sand</string>
|
||||||
|
<string name="condition_761">Dust</string>
|
||||||
|
<string name="condition_762">Volcanic Ash</string>
|
||||||
|
<string name="condition_771">Squalls</string>
|
||||||
|
<string name="condition_781">Tornado</string>
|
||||||
|
<string name="condition_800">Clear</string>
|
||||||
|
<string name="condition_801">Mostly Clear</string>
|
||||||
|
<string name="condition_802">Scattered Clouds</string>
|
||||||
|
<string name="condition_803">Broken Clouds</string>
|
||||||
|
<string name="condition_804">Overcast Clouds</string>
|
||||||
|
<string name="condition_900">Tornado</string>
|
||||||
|
<string name="condition_901">Tropical Storm</string>
|
||||||
|
<string name="condition_902">Hurricane</string>
|
||||||
|
<string name="condition_903">Cold</string>
|
||||||
|
<string name="condition_904">Hot</string>
|
||||||
|
<string name="condition_905">Windy</string>
|
||||||
|
<string name="condition_906">Hail</string>
|
||||||
|
<string name="condition_951">Calm</string>
|
||||||
|
<string name="condition_952">Light Breeze</string>
|
||||||
|
<string name="condition_953">Gentle Breeze</string>
|
||||||
|
<string name="condition_954">Breeze</string> <!-- moderate breeze -->
|
||||||
|
<string name="condition_955">Fresh Breeze</string>
|
||||||
|
<string name="condition_956">Strong Breeze</string>
|
||||||
|
<string name="condition_957">High Wind</string>
|
||||||
|
<string name="condition_958">Gale</string>
|
||||||
|
<string name="condition_959">Severe Gale</string>
|
||||||
|
<string name="condition_960">Storm</string>
|
||||||
|
<string name="condition_961">Violent Storm</string>
|
||||||
|
<string name="condition_962">Hurricane</string>
|
||||||
|
|
||||||
|
<string name="condition_unknown">Unknown (<xliff:g id="low">%1$s</xliff:g>)</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user