fixed older code.

This commit is contained in:
madwasp79 2019-04-19 13:28:27 +03:00
parent 055c403f14
commit 347d9358b2

View file

@ -261,10 +261,6 @@ public class RoutingHelper {
return lastProjection; return lastProjection;
} }
public void addListener(IRouteInformationListener l){
listeners.add(new WeakReference<>(l));
transportRoutingHelper.addListener(l);
}
public void addRouteDataListener(IRoutingDataUpdateListener listener) { public void addRouteDataListener(IRoutingDataUpdateListener listener) {
updateListeners = updateListenersList(new ArrayList<>(updateListeners), listener, true); updateListeners = updateListenersList(new ArrayList<>(updateListeners), listener, true);
@ -281,7 +277,7 @@ public class RoutingHelper {
while (it.hasNext()) { while (it.hasNext()) {
WeakReference<IRoutingDataUpdateListener> ref = it.next(); WeakReference<IRoutingDataUpdateListener> ref = it.next();
IRoutingDataUpdateListener l = ref.get(); IRoutingDataUpdateListener l = ref.get();
if (l == null || (l == listener)) { if (l == null || l == listener) {
it.remove(); it.remove();
} }
} }
@ -291,19 +287,33 @@ public class RoutingHelper {
return copyList; return copyList;
} }
public boolean removeListener(IRouteInformationListener lt){ public void addListener(IRouteInformationListener l){
Iterator<WeakReference<IRouteInformationListener>> it = listeners.iterator(); listeners = updateInformationListeners(new ArrayList<>(listeners), l, true);
transportRoutingHelper.addListener(l);
}
public void removeListener(IRouteInformationListener lt){
listeners = updateInformationListeners(new ArrayList<>(listeners), lt, false);
}
private List<WeakReference<IRouteInformationListener>> updateInformationListeners(
List<WeakReference<IRouteInformationListener>> copyList,
IRouteInformationListener listener, boolean isNewListener) {
Iterator<WeakReference<IRouteInformationListener>> it = copyList.iterator();
while (it.hasNext()) { while (it.hasNext()) {
WeakReference<IRouteInformationListener> ref = it.next(); WeakReference<IRouteInformationListener> ref = it.next();
IRouteInformationListener l = ref.get(); IRouteInformationListener l = ref.get();
if(l == null || lt == l) { if (l == null || l == listener) {
it.remove(); it.remove();
return true;
} }
} }
transportRoutingHelper.removeListener(lt);
return false; if (isNewListener) {
copyList.add(new WeakReference<>(listener));
} }
return copyList;
}
public void updateLocation(Location currentLocation) { public void updateLocation(Location currentLocation) {
if (settings.getPointToStart() == null && settings.getMyLocationToStart() == null && currentLocation != null) { if (settings.getPointToStart() == null && settings.getMyLocationToStart() == null && currentLocation != null) {