Merge pull request #10428 from osmandapp/minor_fixes

Fix possible npe
This commit is contained in:
vshcherb 2020-12-17 16:53:02 +01:00 committed by GitHub
commit e6a0238597
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -134,7 +134,6 @@ public class NavigationNotification extends OsmandNotification {
turnBitmap = null; turnBitmap = null;
ongoing = true; ongoing = true;
RoutingHelper routingHelper = app.getRoutingHelper(); RoutingHelper routingHelper = app.getRoutingHelper();
Location location = getLastKnownLocation();
if (service != null && (service.getUsedBy() & USED_BY_NAVIGATION) != 0) { if (service != null && (service.getUsedBy() & USED_BY_NAVIGATION) != 0) {
color = app.getResources().getColor(R.color.osmand_orange); color = app.getResources().getColor(R.color.osmand_orange);
@ -142,7 +141,11 @@ public class NavigationNotification extends OsmandNotification {
String timeStr = OsmAndFormatter.getFormattedDuration(routingHelper.getLeftTime(), app); String timeStr = OsmAndFormatter.getFormattedDuration(routingHelper.getLeftTime(), app);
String etaStr = SimpleDateFormat.getTimeInstance(DateFormat.SHORT) String etaStr = SimpleDateFormat.getTimeInstance(DateFormat.SHORT)
.format(new Date(System.currentTimeMillis() + routingHelper.getLeftTime() * 1000)); .format(new Date(System.currentTimeMillis() + routingHelper.getLeftTime() * 1000));
String speedStr = OsmAndFormatter.getFormattedSpeed(location.getSpeed(), app); String speedStr = null;
Location location = getLastKnownLocation();
if (location != null && location.hasSpeed()) {
speedStr = OsmAndFormatter.getFormattedSpeed(location.getSpeed(), app);
}
TurnType turnType = null; TurnType turnType = null;
boolean deviatedFromRoute; boolean deviatedFromRoute;
@ -202,12 +205,12 @@ public class NavigationNotification extends OsmandNotification {
notificationText.append("\n"); notificationText.append("\n");
} }
} }
notificationText.append(distanceStr) notificationText.append(distanceStr)
.append("").append(timeStr) .append("").append(timeStr)
.append("").append(etaStr) .append("").append(etaStr);
.append("").append(speedStr); if (speedStr != null) {
notificationText.append("").append(speedStr);
}
} else { } else {
notificationTitle = app.getString(R.string.shared_string_navigation); notificationTitle = app.getString(R.string.shared_string_navigation);
String error = routingHelper.getLastRouteCalcErrorShort(); String error = routingHelper.getLastRouteCalcErrorShort();
@ -217,7 +220,6 @@ public class NavigationNotification extends OsmandNotification {
notificationText.append(error); notificationText.append(error);
} }
} }
} else if (routingHelper.isRoutePlanningMode() && routingHelper.isPauseNavigation()) { } else if (routingHelper.isRoutePlanningMode() && routingHelper.isPauseNavigation()) {
ongoing = false; ongoing = false;
notificationTitle = app.getString(R.string.shared_string_navigation); notificationTitle = app.getString(R.string.shared_string_navigation);