Fix notifications

This commit is contained in:
Alexey Kulish 2017-04-20 15:52:57 +03:00
parent 8490982312
commit fb6df5fc4e
3 changed files with 26 additions and 26 deletions

View file

@ -317,8 +317,8 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
SavingTrackHelper helper = app.getSavingTrackHelper();
helper.saveDataToGpx(app.getAppCustomization().getTracksDir());
helper.close();
} finally {
app.getNotificationHelper().showNotifications();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@ -326,6 +326,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
@Override
protected void onPostExecute(Void aVoid) {
isSaving = false;
app.getNotificationHelper().refreshNotifications();
updateControl();
}
}, (Void) null);

View file

@ -26,7 +26,8 @@ public class GpxNotification extends OsmandNotification {
public final static String OSMAND_STOP_GPX_SERVICE_ACTION = "OSMAND_STOP_GPX_SERVICE_ACTION";
public final static String GROUP_NAME = "GPX";
private boolean wasDismissed;
private boolean wasNoDataDismissed;
private boolean lastBuiltNoData;
public GpxNotification(OsmandApplication app) {
super(app, GROUP_NAME);
@ -98,7 +99,9 @@ public class GpxNotification extends OsmandNotification {
@Override
public void onNotificationDismissed() {
wasDismissed = true;
if (!wasNoDataDismissed) {
wasNoDataDismissed = lastBuiltNoData;
}
}
@Override
@ -113,6 +116,7 @@ public class GpxNotification extends OsmandNotification {
boolean isGpxRecording = app.getSavingTrackHelper().getIsRecording();
float recordedDistance = app.getSavingTrackHelper().getDistance();
ongoing = true;
lastBuiltNoData = false;
if (isGpxRecording) {
color = app.getResources().getColor(R.color.osmand_orange);
notificationTitle = app.getString(R.string.shared_string_trip) + ""
@ -129,10 +133,11 @@ public class GpxNotification extends OsmandNotification {
ongoing = false;
notificationTitle = app.getString(R.string.shared_string_trip_recording);
notificationText = app.getString(R.string.gpx_logging_no_data);
lastBuiltNoData = true;
}
}
if ((wasDismissed || !app.getSettings().SHOW_TRIP_REC_NOTIFICATION.get()) && !ongoing) {
if ((wasNoDataDismissed || !app.getSettings().SHOW_TRIP_REC_NOTIFICATION.get()) && !ongoing) {
return null;
}

View file

@ -68,10 +68,8 @@ public abstract class OsmandNotification {
.setPriority(top ? NotificationCompat.PRIORITY_HIGH : getPriority())
.setOngoing(ongoing && !wearable)
.setContentIntent(contentPendingIntent)
.setDeleteIntent(NotificationDismissReceiver.createIntent(app, getType()));
if (top) {
builder.setGroup(groupName).setGroupSummary(!wearable);
}
.setDeleteIntent(NotificationDismissReceiver.createIntent(app, getType()))
.setGroup(groupName).setGroupSummary(!wearable);
if (color != 0) {
builder.setColor(color);
@ -101,6 +99,14 @@ public abstract class OsmandNotification {
public void onNotificationDismissed() {
}
private void notifyWearable(NotificationManagerCompat notificationManager) {
Builder wearNotificationBuilder = buildNotification(true);
if (wearNotificationBuilder != null) {
Notification wearNotification = wearNotificationBuilder.build();
notificationManager.notify(getOsmandWearableNotificationId(), wearNotification);
}
}
public boolean showNotification() {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(app);
if (isEnabled()) {
@ -109,13 +115,7 @@ public abstract class OsmandNotification {
Notification notification = notificationBuilder.build();
setupNotification(notification);
notificationManager.notify(top ? TOP_NOTIFICATION_SERVICE_ID : getOsmandNotificationId(), notification);
if (top) {
Builder wearNotificationBuilder = buildNotification(true);
if (wearNotificationBuilder != null) {
Notification wearNotification = wearNotificationBuilder.build();
notificationManager.notify(getOsmandWearableNotificationId(), wearNotification);
}
}
notifyWearable(notificationManager);
return true;
}
}
@ -130,24 +130,18 @@ public abstract class OsmandNotification {
Notification notification = notificationBuilder.build();
setupNotification(notification);
if (top) {
removeNotification();
notificationManager.cancel(getOsmandNotificationId());
notificationManager.notify(TOP_NOTIFICATION_SERVICE_ID, notification);
Builder wearNotificationBuilder = buildNotification(true);
if (wearNotificationBuilder != null) {
Notification wearNotification = wearNotificationBuilder.build();
notificationManager.notify(getOsmandWearableNotificationId(), wearNotification);
}
} else {
notificationManager.notify(getOsmandNotificationId(), notification);
}
notifyWearable(notificationManager);
return true;
} else {
removeNotification();
notificationManager.cancel(getOsmandNotificationId());
}
} else {
removeNotification();
notificationManager.cancel(getOsmandNotificationId());
}
return false;
}