Store the layers that have been downloaded into the MapWithAI

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2020-06-30 11:37:05 -06:00
rodzic 81950d379e
commit f4ad6b7421
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
4 zmienionych plików z 46 dodań i 8 usunięć

Wyświetl plik

@ -90,7 +90,7 @@ public class AddMapWithAILayerAction extends JosmAction implements AdaptableActi
} }
})); }));
} }
MapWithAIDataUtils.getLayer(false).addDownloadedInfo(info);
} }
@Override @Override
@ -100,7 +100,8 @@ public class AddMapWithAILayerAction extends JosmAction implements AdaptableActi
@Override @Override
protected void updateEnabledState() { protected void updateEnabledState() {
setEnabled(!info.isBlacklisted()); setEnabled(!info.isBlacklisted() && (MapWithAIDataUtils.getLayer(false) == null
|| !MapWithAIDataUtils.getLayer(false).hasDownloaded(info)));
} }
@Override @Override

Wyświetl plik

@ -199,7 +199,7 @@ public final class MapWithAIDataUtils {
final List<Bounds> realBounds = realBBoxes.stream() final List<Bounds> realBounds = realBBoxes.stream()
.flatMap(tBBox -> MapWithAIDataUtils.reduceBBoxSize(tBBox, maximumDimensions).stream()) .flatMap(tBBox -> MapWithAIDataUtils.reduceBBoxSize(tBBox, maximumDimensions).stream())
.map(MapWithAIDataUtils::bboxToBounds).collect(Collectors.toList()); .map(MapWithAIDataUtils::bboxToBounds).collect(Collectors.toList());
if (!MapWithAILayerInfo.getInstance().getLayers().isEmpty()) { if (!MapWithAIPreferenceHelper.getMapWithAIUrl().isEmpty()) {
if ((realBBoxes.size() < TOO_MANY_BBOXES) || confirmBigDownload(realBBoxes)) { if ((realBBoxes.size() < TOO_MANY_BBOXES) || confirmBigDownload(realBBoxes)) {
final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(); final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor();
monitor.beginTask(tr("Downloading {0} Data", MapWithAIPlugin.NAME), realBounds.size()); monitor.beginTask(tr("Downloading {0} Data", MapWithAIPlugin.NAME), realBounds.size());

Wyświetl plik

@ -9,7 +9,9 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -58,6 +60,7 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
private Boolean switchLayers; private Boolean switchLayers;
private boolean continuousDownload = true; private boolean continuousDownload = true;
private final Lock lock; private final Lock lock;
private final HashSet<MapWithAIInfo> downloadedInfo = new HashSet<>();
/** /**
* Create a new MapWithAI layer * Create a new MapWithAI layer
@ -318,4 +321,32 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
} }
} }
/**
* Check if the layer has downloaded a specific data type
*
* @param info The info to check
* @return {@code true} if the info has been added to the layer
*/
public boolean hasDownloaded(MapWithAIInfo info) {
return downloadedInfo.contains(info);
}
/**
* Indicate an info has been downloaded in this layer
*
* @param info The info that has been downloaded
*/
public void addDownloadedInfo(MapWithAIInfo info) {
downloadedInfo.add(info);
}
/**
* Get the info that has been downloaded into this layer
*
* @return An unmodifiable collection of the downloaded info
*/
public Collection<MapWithAIInfo> getDownloadedInfo() {
return Collections.unmodifiableCollection(downloadedInfo);
}
} }

Wyświetl plik

@ -2,6 +2,7 @@
package org.openstreetmap.josm.plugins.mapwithai.backend; package org.openstreetmap.josm.plugins.mapwithai.backend;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -38,11 +39,16 @@ public final class MapWithAIPreferenceHelper {
* @return A list of enabled MapWithAI urls (maps have source, parameters, * @return A list of enabled MapWithAI urls (maps have source, parameters,
* enabled, and the url) * enabled, and the url)
*/ */
public static List<MapWithAIInfo> getMapWithAIUrl() { public static Collection<MapWithAIInfo> getMapWithAIUrl() {
return MapWithAIDataUtils.getLayer(false) == null MapWithAILayer layer = MapWithAIDataUtils.getLayer(false);
|| MapWithAIDataUtils.getLayer(false).getMapWithAIUrl() == null if (layer != null) {
? MapWithAILayerInfo.getInstance().getLayers() if (!layer.getDownloadedInfo().isEmpty()) {
: Collections.singletonList(MapWithAIDataUtils.getLayer(false).getMapWithAIUrl()); return layer.getDownloadedInfo();
} else if (layer.getMapWithAIUrl() != null) {
return Collections.singleton(layer.getMapWithAIUrl());
}
}
return MapWithAILayerInfo.getInstance().getLayers();
} }
/** /**