Skip to content

Commit

Permalink
For #238 - always draw marker position of selected device at last so …
Browse files Browse the repository at this point in the history
…it will be at front
  • Loading branch information
vitalidze committed Sep 8, 2015
1 parent 31c90cc commit 154d9fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public void onSuccess(List<Position> positions) {

private Map<Long, Position> timestampMap = new HashMap<Long, Position>();

private Device selectedDevice;

private int updateFailureCount = 0;

private final Messages i18n = GWT.create(Messages.class);
Expand All @@ -117,8 +119,14 @@ public void onSuccess(List<Position> result) {
*/
List<Position> alerts = null;
long currentTime = System.currentTimeMillis();
for (Position position : result) {
int selectedIndex = -1;
for (int i = 0; i < result.size(); i++) {
Position position = result.get(i);
Device device = position.getDevice();
if (device.equals(selectedDevice)) {
selectedIndex = i;
}

// update status and icon
boolean isOffline = currentTime - position.getTime().getTime() > position.getDevice().getTimeout() * 1000;
position.setStatus(isOffline ? Position.Status.OFFLINE : Position.Status.LATEST);
Expand All @@ -145,6 +153,12 @@ public void onSuccess(List<Position> result) {
}
}
}
/**
* Put position of selected device to the end of list so it will be drawn after all other positions
*/
if (selectedIndex >= 0) {
result.add(result.remove(selectedIndex));
}
/**
* Draw positions
*/
Expand Down Expand Up @@ -229,6 +243,7 @@ public void selectGeoFence(GeoFence geoFence) {

public void selectDevice(Device device) {
mapView.selectDevice(device);
this.selectedDevice = device;
}

public void showArchivePositions(Track track) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ public List<Position> getPositions(Device device, Date from, Date to, boolean fi
@Transactional
@Override
public List<Position> getLatestPositions() {
List<Position> positions = new LinkedList<Position>();
List<Position> positions = new ArrayList<Position>();
List<Device> devices = getDevices(false);
List<GeoFence> geoFences = getGeoFences(false);
GeoFenceCalculator geoFenceCalculator = new GeoFenceCalculator(getGeoFences());
Expand Down

0 comments on commit 154d9fc

Please sign in to comment.