Prevent NPE in transport type

This commit is contained in:
PavelRatushny 2017-12-21 15:13:45 +02:00
parent 95499c39eb
commit 8551969bc9
3 changed files with 54 additions and 50 deletions

View file

@ -778,7 +778,7 @@ public class MenuBuilder {
TextView typeTextView = new TextView(view.getContext()); TextView typeTextView = new TextView(view.getContext());
LinearLayout.LayoutParams typeTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams typeTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
typeTextView.setLayoutParams(typeTextParams); typeTextView.setLayoutParams(typeTextParams);
typeTextView.setText(route.type.getTypeStrRes()); typeTextView.setText(route.getTypeStrRes());
typeView.addView(typeTextView); typeView.addView(typeTextView);
baseView.setOnClickListener(listener); baseView.setOnClickListener(listener);

View file

@ -55,16 +55,63 @@ public class TransportStopRoute {
if (cachedColor == 0 || cachedNight != nightMode) { if (cachedColor == 0 || cachedNight != nightMode) {
cachedColor = ctx.getResources().getColor(R.color.transport_route_line); cachedColor = ctx.getResources().getColor(R.color.transport_route_line);
cachedNight = nightMode; cachedNight = nightMode;
RenderingRulesStorage rrs = ctx.getRendererRegistry().getCurrentSelectedRenderer(); if (type != null) {
RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs); RenderingRulesStorage rrs = ctx.getRendererRegistry().getCurrentSelectedRenderer();
req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode); RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
String typeStr = type.getRendeAttr(); req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode);
if (req.searchRenderingAttribute(typeStr)) { String typeStr = type.getRendeAttr();
cachedColor = req.getIntPropertyValue(rrs.PROPS.R_ATTR_COLOR_VALUE); if (req.searchRenderingAttribute(typeStr)) {
cachedColor = req.getIntPropertyValue(rrs.PROPS.R_ATTR_COLOR_VALUE);
}
} }
} }
return cachedColor; return cachedColor;
} }
public int getTypeStrRes() {
int typeResId = R.string.poi_filter_public_transport;
if (type != null) {
switch (type) {
case BUS:
typeResId = R.string.poi_route_bus_ref;
break;
case TRAM:
typeResId = R.string.poi_route_tram_ref;
break;
case FERRY:
typeResId = R.string.poi_route_ferry_ref;
break;
case TRAIN:
typeResId = R.string.poi_route_train_ref;
break;
case SHARE_TAXI:
typeResId = R.string.poi_route_share_taxi_ref;
break;
case FUNICULAR:
typeResId = R.string.poi_route_funicular_ref;
break;
case LIGHT_RAIL:
typeResId = R.string.poi_route_light_rail_ref;
break;
case MONORAIL:
typeResId = R.string.poi_route_monorail_ref;
break;
case TROLLEYBUS:
typeResId = R.string.poi_route_trolleybus_ref;
break;
case RAILWAY:
typeResId = R.string.poi_route_railway_ref;
break;
case SUBWAY:
typeResId = R.string.poi_route_subway_ref;
break;
default:
typeResId = R.string.poi_filter_public_transport;
break;
}
}
return typeResId;
}
} }

View file

@ -51,47 +51,4 @@ public enum TransportStopType {
return null; return null;
} }
public int getTypeStrRes() {
int typeResId;
switch (this) {
case BUS:
typeResId = R.string.poi_route_bus_ref;
break;
case TRAM:
typeResId = R.string.poi_route_tram_ref;
break;
case FERRY:
typeResId = R.string.poi_route_ferry_ref;
break;
case TRAIN:
typeResId = R.string.poi_route_train_ref;
break;
case SHARE_TAXI:
typeResId = R.string.poi_route_share_taxi_ref;
break;
case FUNICULAR:
typeResId = R.string.poi_route_funicular_ref;
break;
case LIGHT_RAIL:
typeResId = R.string.poi_route_light_rail_ref;
break;
case MONORAIL:
typeResId = R.string.poi_route_monorail_ref;
break;
case TROLLEYBUS:
typeResId = R.string.poi_route_trolleybus_ref;
break;
case RAILWAY:
typeResId = R.string.poi_route_railway_ref;
break;
case SUBWAY:
typeResId = R.string.poi_route_subway_ref;
break;
default:
typeResId = R.string.poi_filter_public_transport;
break;
}
return typeResId;
}
} }