Add check for npe and NotFoundException
This commit is contained in:
parent
4a6c5c28c2
commit
f8be196656
1 changed files with 26 additions and 16 deletions
|
@ -1287,12 +1287,18 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
|
||||
private void createTransportBadges() {
|
||||
if (!transportBadgesCreated) {
|
||||
List<TransportStopRoute> localTransportStopRoutes = filterTransportRoutes(menu.getLocalTransportStopRoutes());
|
||||
List<TransportStopRoute> nearbyTransportStopRoutes = filterTransportRoutes(menu.getNearbyTransportStopRoutes());
|
||||
List<TransportStopRoute> localTransportStopRoutes = menu.getLocalTransportStopRoutes();
|
||||
List<TransportStopRoute> nearbyTransportStopRoutes = menu.getNearbyTransportStopRoutes();
|
||||
int localColumnsPerRow = getRoutesBadgesColumnsPerRow(null);
|
||||
int maxLocalRows = (int) Math.round(Math.ceil((double) localTransportStopRoutes.size() / localColumnsPerRow));
|
||||
updateLocalRoutesBadges(localTransportStopRoutes, localColumnsPerRow);
|
||||
updateNearbyRoutesBadges(maxLocalRows, nearbyTransportStopRoutes);
|
||||
int maxLocalRows = 0;
|
||||
if (localTransportStopRoutes != null) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1341,6 +1347,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
|
||||
private int getRoutesBadgesColumnsPerRow(@Nullable String nearInDistance) {
|
||||
try {
|
||||
double badgeWidth = getResources().getDimension(R.dimen.context_menu_transport_grid_item_width);
|
||||
double gridSpacing = getResources().getDimension(R.dimen.context_menu_transport_grid_spacing);
|
||||
double gridPadding = getResources().getDimension(R.dimen.context_menu_padding_margin_default);
|
||||
|
@ -1353,6 +1360,9 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
availableSpace = (int) (routesBadgesContainer.getWidth() - gridPadding * 2 - paddingTv - textWidth);
|
||||
}
|
||||
return (int) ((availableSpace + gridSpacing) / (badgeWidth + gridSpacing));
|
||||
} catch (Resources.NotFoundException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
|
|
Loading…
Reference in a new issue