From d71210f1f408c757d4fe3da07829bbc3362a7e93 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 15 Jul 2016 15:33:08 +0500 Subject: Move code related to devices to DeviceManager --- src/org/traccar/events/MotionEventHandler.java | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/org/traccar/events/MotionEventHandler.java') diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java index d10513d26..4a3d2f0f0 100644 --- a/src/org/traccar/events/MotionEventHandler.java +++ b/src/org/traccar/events/MotionEventHandler.java @@ -38,7 +38,7 @@ public class MotionEventHandler extends BaseEventHandler { @Override protected Collection analyzePosition(Position position) { - Device device = Context.getDataManager().getDeviceById(position.getDeviceId()); + Device device = Context.getIdentityManager().getDeviceById(position.getDeviceId()); if (device == null) { return null; } @@ -53,16 +53,19 @@ public class MotionEventHandler extends BaseEventHandler { if (motion == null) { motion = Device.STATUS_STOPPED; } - if (valid && speed > SPEED_THRESHOLD && !motion.equals(Device.STATUS_MOVING)) { - Context.getConnectionManager().updateDevice(position.getDeviceId(), Device.STATUS_MOVING, null); - result = new ArrayList<>(); - result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId())); - } else if (valid && speed < SPEED_THRESHOLD && motion.equals(Device.STATUS_MOVING)) { - Context.getConnectionManager().updateDevice(position.getDeviceId(), Device.STATUS_STOPPED, null); - result = new ArrayList<>(); - result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId())); - } try { + if (valid && speed > SPEED_THRESHOLD && !motion.equals(Device.STATUS_MOVING)) { + device.setMotion(Device.STATUS_MOVING); + Context.getDeviceManager().updateDeviceStatus(device); + result = new ArrayList<>(); + result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId())); + } else if (valid && speed < SPEED_THRESHOLD && motion.equals(Device.STATUS_MOVING)) { + device.setMotion(Device.STATUS_STOPPED); + Context.getDeviceManager().updateDeviceStatus(device); + result = new ArrayList<>(); + result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId())); + } + if (result != null && !result.isEmpty()) { for (Event event : result) { if (!Context.getDataManager().getLastEvents(position.getDeviceId(), -- cgit v1.2.3