From 347d9358b295ed2ed37f1b14c5ceb7404b3e088b Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Fri, 19 Apr 2019 13:28:27 +0300 Subject: [PATCH] fixed older code. --- .../osmand/plus/routing/RoutingHelper.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 86ceb4f8e6..bae4c245fb 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -261,10 +261,6 @@ public class RoutingHelper { return lastProjection; } - public void addListener(IRouteInformationListener l){ - listeners.add(new WeakReference<>(l)); - transportRoutingHelper.addListener(l); - } public void addRouteDataListener(IRoutingDataUpdateListener listener) { updateListeners = updateListenersList(new ArrayList<>(updateListeners), listener, true); @@ -281,7 +277,7 @@ public class RoutingHelper { while (it.hasNext()) { WeakReference ref = it.next(); IRoutingDataUpdateListener l = ref.get(); - if (l == null || (l == listener)) { + if (l == null || l == listener) { it.remove(); } } @@ -291,20 +287,34 @@ public class RoutingHelper { return copyList; } - public boolean removeListener(IRouteInformationListener lt){ - Iterator> it = listeners.iterator(); - while(it.hasNext()) { + public void addListener(IRouteInformationListener l){ + listeners = updateInformationListeners(new ArrayList<>(listeners), l, true); + transportRoutingHelper.addListener(l); + } + + public void removeListener(IRouteInformationListener lt){ + listeners = updateInformationListeners(new ArrayList<>(listeners), lt, false); + } + + private List> updateInformationListeners( + List> copyList, + IRouteInformationListener listener, boolean isNewListener) { + Iterator> it = copyList.iterator(); + while (it.hasNext()) { WeakReference ref = it.next(); IRouteInformationListener l = ref.get(); - if(l == null || lt == l) { + if (l == null || l == listener) { it.remove(); - return true; } } - transportRoutingHelper.removeListener(lt); - return false; + + if (isNewListener) { + copyList.add(new WeakReference<>(listener)); + } + return copyList; } + public void updateLocation(Location currentLocation) { if (settings.getPointToStart() == null && settings.getMyLocationToStart() == null && currentLocation != null) { app.getTargetPointsHelper().setMyLocationPoint(