Add check for npe and NotFoundException

This commit is contained in:
Chumva 2018-09-25 15:53:26 +03:00
parent 4a6c5c28c2
commit f8be196656

View file

@ -1287,12 +1287,18 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
private void createTransportBadges() { private void createTransportBadges() {
if (!transportBadgesCreated) { if (!transportBadgesCreated) {
List<TransportStopRoute> localTransportStopRoutes = filterTransportRoutes(menu.getLocalTransportStopRoutes()); List<TransportStopRoute> localTransportStopRoutes = menu.getLocalTransportStopRoutes();
List<TransportStopRoute> nearbyTransportStopRoutes = filterTransportRoutes(menu.getNearbyTransportStopRoutes()); List<TransportStopRoute> nearbyTransportStopRoutes = menu.getNearbyTransportStopRoutes();
int localColumnsPerRow = getRoutesBadgesColumnsPerRow(null); int localColumnsPerRow = getRoutesBadgesColumnsPerRow(null);
int maxLocalRows = (int) Math.round(Math.ceil((double) localTransportStopRoutes.size() / localColumnsPerRow)); int maxLocalRows = 0;
updateLocalRoutesBadges(localTransportStopRoutes, localColumnsPerRow); if (localTransportStopRoutes != null) {
updateNearbyRoutesBadges(maxLocalRows, nearbyTransportStopRoutes); List<TransportStopRoute> localFilteredTransportStopRoutes = filterTransportRoutes(localTransportStopRoutes);
maxLocalRows = (int) Math.round(Math.ceil((double) localFilteredTransportStopRoutes.size() / localColumnsPerRow));
updateLocalRoutesBadges(localFilteredTransportStopRoutes, localColumnsPerRow);
}
if (nearbyTransportStopRoutes != null) {
updateNearbyRoutesBadges(maxLocalRows, filterTransportRoutes(nearbyTransportStopRoutes));
}
transportBadgesCreated = true; transportBadgesCreated = true;
} }
} }
@ -1341,18 +1347,22 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
} }
private int getRoutesBadgesColumnsPerRow(@Nullable String nearInDistance) { private int getRoutesBadgesColumnsPerRow(@Nullable String nearInDistance) {
double badgeWidth = getResources().getDimension(R.dimen.context_menu_transport_grid_item_width); try {
double gridSpacing = getResources().getDimension(R.dimen.context_menu_transport_grid_spacing); double badgeWidth = getResources().getDimension(R.dimen.context_menu_transport_grid_item_width);
double gridPadding = getResources().getDimension(R.dimen.context_menu_padding_margin_default); double gridSpacing = getResources().getDimension(R.dimen.context_menu_transport_grid_spacing);
int availableSpace; double gridPadding = getResources().getDimension(R.dimen.context_menu_padding_margin_default);
if (nearInDistance == null) { int availableSpace;
availableSpace = (int) (routesBadgesContainer.getWidth() - gridPadding * 2); if (nearInDistance == null) {
} else { availableSpace = (int) (routesBadgesContainer.getWidth() - gridPadding * 2);
int textWidth = AndroidUtils.getTextWidth(getResources().getDimensionPixelSize(R.dimen.default_sub_text_size), nearInDistance); } else {
double paddingTv = getResources().getDimension(R.dimen.context_menu_padding_margin_small); int textWidth = AndroidUtils.getTextWidth(getResources().getDimensionPixelSize(R.dimen.default_sub_text_size), nearInDistance);
availableSpace = (int) (routesBadgesContainer.getWidth() - gridPadding * 2 - paddingTv - textWidth); double paddingTv = getResources().getDimension(R.dimen.context_menu_padding_margin_small);
availableSpace = (int) (routesBadgesContainer.getWidth() - gridPadding * 2 - paddingTv - textWidth);
}
return (int) ((availableSpace + gridSpacing) / (badgeWidth + gridSpacing));
} catch (Resources.NotFoundException e) {
return -1;
} }
return (int) ((availableSpace + gridSpacing) / (badgeWidth + gridSpacing));
} }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @TargetApi(Build.VERSION_CODES.JELLY_BEAN)