Merge pull request #7462 from osmandapp/NotificationFailsFix

Fix ErrorNotification appearance
This commit is contained in:
max-klaus 2019-08-23 16:24:28 +03:00 committed by GitHub
commit ed44959ede
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View file

@ -191,9 +191,16 @@ public class NavigationService extends Service implements LocationListener {
// registering icon at top level
// Leave icon visible even for navigation for proper display
Notification notification = app.getNotificationHelper().buildTopNotification();
startForeground(OsmandNotification.TOP_NOTIFICATION_SERVICE_ID, notification);
app.getNotificationHelper().refreshNotifications();
return START_REDELIVER_INTENT;
if (notification != null) {
startForeground(OsmandNotification.TOP_NOTIFICATION_SERVICE_ID, notification);
app.getNotificationHelper().refreshNotifications();
return START_REDELIVER_INTENT;
} else {
notification = app.getNotificationHelper().buildErrorNotification();
startForeground(OsmandNotification.TOP_NOTIFICATION_SERVICE_ID, notification);
stopSelf();
return START_NOT_STICKY;
}
}

View file

@ -46,7 +46,6 @@ public class NotificationHelper {
all.add(downloadNotification);
}
@NonNull
public Notification buildTopNotification() {
OsmandNotification notification = acquireTopNotification();
if (notification != null) {
@ -56,10 +55,10 @@ public class NotificationHelper {
if (notificationBuilder != null) {
return notificationBuilder.build();
} else {
return buildErrorNotification();
return null;
}
} else {
return buildErrorNotification();
return null;
}
}
@ -68,7 +67,7 @@ public class NotificationHelper {
return downloadNotification.buildNotification(false).build();
}
private Notification buildErrorNotification() {
public Notification buildErrorNotification() {
removeNotification(errorNotification.getType());
setTopNotification(errorNotification);
return errorNotification.buildNotification(false).build();