Disable Geocoder for Alarms

JMVSL4 years ago

I have opencage geocoder set with geocoder.onRequest set to true, however it is constantly being called for alarm events, regardless of if a notification is sent or not.

Is there a way to not geocode for alarm events if no notification is sent?

Anton Tananaev4 years ago
JMVSL4 years ago

Thanks, so would need a code change to change that?

Anton Tananaev4 years ago

Correct.

JMVSL4 years ago

Great, so having looked at that, I should just be able to remove that if statement and proceeding code block?

 if (position != null && geocodeOnRequest && Context.getGeocoder() != null && position.getAddress() == null) {
           position.setAddress(Context.getGeocoder()
                  .getAddress(position.getLatitude(), position.getLongitude(), null));
      }
Anton Tananaev4 years ago

I think so.

JMVSL4 years ago

I've moved it into here, which seems to have done the trick - it now only does a lookup if the event is one that is sent as a notification:

 for (long userId : users) {
            if ((event.getGeofenceId() == 0
                    || Context.getGeofenceManager().checkItemPermission(userId, event.getGeofenceId()))
                    && (event.getMaintenanceId() == 0
                    || Context.getMaintenancesManager().checkItemPermission(userId, event.getMaintenanceId()))) {
                if (usersToForward != null) {
                    usersToForward.add(userId);
                }
                final Set<String> notificators = new HashSet<>();
                for (long notificationId : getEffectiveNotifications(userId, deviceId, event.getServerTime())) {
                    Notification notification = getById(notificationId);
                    if (getById(notificationId).getType().equals(event.getType())) {

-->                        if (position != null && geocodeOnRequest && Context.getGeocoder() != null && position.getAddress() == null) {
-->                           position.setAddress(Context.getGeocoder()
-->                                    .getAddress(position.getLatitude(), position.getLongitude(), null));
-->                        }

                        boolean filter = false;
                        if (event.getType().equals(Event.TYPE_ALARM)) {
                            String alarmsAttribute = notification.getString("alarms");
                            if (alarmsAttribute == null) {
                                filter = true;
                            } else {
                                List<String> alarms = Arrays.asList(alarmsAttribute.split(","));
                                filter = !alarms.contains(event.getString(Position.KEY_ALARM));
                            }
Anton Tananaev4 years ago

Feel free to send a PR.