Fix overlays on new MapStyle
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,3 +9,4 @@ DS_Store
|
|||||||
.cxx
|
.cxx
|
||||||
local.properties
|
local.properties
|
||||||
/legacy_code/
|
/legacy_code/
|
||||||
|
*osma.style.json
|
||||||
|
|||||||
@@ -25,4 +25,4 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ import org.maplibre.geojson.Feature;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
//FIXME: Move Item functions into specific classes for specific types - e.g. StyleItem
|
|
||||||
public final class AlertDialogFactory {
|
public final class AlertDialogFactory {
|
||||||
|
private AlertDialogFactory() {} // prevent instantiation
|
||||||
|
|
||||||
public static AlertDialog pointSelector(AppController app, List<Feature> features, Consumer<Feature> callback) {
|
public static AlertDialog pointSelector(AppController app, List<Feature> features, Consumer<Feature> callback) {
|
||||||
LinearLayout layout = new LinearLayout(app.getActivity());
|
LinearLayout layout = new LinearLayout(app.getActivity());
|
||||||
layout.setOrientation(LinearLayout.VERTICAL);
|
layout.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ import java.util.List;
|
|||||||
|
|
||||||
import eu.konggdev.strikemaps.app.AppController;
|
import eu.konggdev.strikemaps.app.AppController;
|
||||||
|
|
||||||
//FIXME: Ugly
|
//FIXME: Spaghetti code
|
||||||
public final class FileHelper {
|
public final class FileHelper {
|
||||||
|
private FileHelper() {} // prevent instantiation
|
||||||
|
|
||||||
public static String loadStringFromAssetFile(String filePath, AppController app) {
|
public static String loadStringFromAssetFile(String filePath, AppController app) {
|
||||||
try (InputStream is = app.getActivity().getAssets().open(filePath)) {
|
try (InputStream is = app.getActivity().getAssets().open(filePath)) {
|
||||||
int size = is.available();
|
int size = is.available();
|
||||||
@@ -106,4 +108,4 @@ public final class FileHelper {
|
|||||||
|
|
||||||
return fileList.toArray(new String[0]);
|
return fileList.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import eu.konggdev.strikemaps.Component;
|
|||||||
import eu.konggdev.strikemaps.factory.AlertDialogFactory;
|
import eu.konggdev.strikemaps.factory.AlertDialogFactory;
|
||||||
import eu.konggdev.strikemaps.helper.UserPrefsHelper;
|
import eu.konggdev.strikemaps.helper.UserPrefsHelper;
|
||||||
import eu.konggdev.strikemaps.map.renderer.implementation.VtmRenderer;
|
import eu.konggdev.strikemaps.map.renderer.implementation.VtmRenderer;
|
||||||
|
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||||
import org.maplibre.android.geometry.LatLng;
|
import org.maplibre.android.geometry.LatLng;
|
||||||
import org.maplibre.geojson.Feature;
|
import org.maplibre.geojson.Feature;
|
||||||
|
|
||||||
@@ -17,9 +18,9 @@ import eu.konggdev.strikemaps.ui.fragment.layout.content.main.FragmentLayoutCont
|
|||||||
public class MapComponent implements Component {
|
public class MapComponent implements Component {
|
||||||
MapRenderer mapRenderer;
|
MapRenderer mapRenderer;
|
||||||
AppController app;
|
AppController app;
|
||||||
|
private MapStyle currentStyle;
|
||||||
public String style;
|
|
||||||
public Map<Class<? extends MapOverlay>, MapOverlay> overlays = new HashMap<>();
|
public Map<Class<? extends MapOverlay>, MapOverlay> overlays = new HashMap<>();
|
||||||
|
|
||||||
public MapComponent(AppController ref) {
|
public MapComponent(AppController ref) {
|
||||||
this.app = ref;
|
this.app = ref;
|
||||||
switch(UserPrefsHelper.mapRenderer(app.getPrefs())) {
|
switch(UserPrefsHelper.mapRenderer(app.getPrefs())) {
|
||||||
@@ -37,9 +38,14 @@ public class MapComponent implements Component {
|
|||||||
return new FragmentLayoutContentMap(mapRenderer.getView());
|
return new FragmentLayoutContentMap(mapRenderer.getView());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStyle(String style) {
|
public void setStyle(MapStyle style) {
|
||||||
this.style = style;
|
if(style != null)
|
||||||
mapRenderer.reload();
|
this.currentStyle = style;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapStyle getStyle() {
|
||||||
|
return currentStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void switchOverlay(MapOverlay overlay) {
|
public void switchOverlay(MapOverlay overlay) {
|
||||||
@@ -65,7 +71,7 @@ public class MapComponent implements Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
if(mapRenderer != null && style != null) mapRenderer.reload();
|
if(mapRenderer != null && currentStyle != null) mapRenderer.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onMapClick(LatLng point) {
|
public boolean onMapClick(LatLng point) {
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package eu.konggdev.strikemaps.map.layer;
|
||||||
|
|
||||||
|
import org.maplibre.android.style.layers.Layer;
|
||||||
|
import org.maplibre.android.style.sources.GeoJsonSource;
|
||||||
|
|
||||||
|
//FIXME: Stop being MapLibre reliant
|
||||||
|
public class MapLayer {
|
||||||
|
public GeoJsonSource source;
|
||||||
|
public Layer layer;
|
||||||
|
public MapLayer(GeoJsonSource source, Layer layer) {
|
||||||
|
this.source = source;
|
||||||
|
this.layer = layer;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package eu.konggdev.strikemaps.map.overlay;
|
package eu.konggdev.strikemaps.map.overlay;
|
||||||
|
|
||||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
/* More or less a data-driven layer factory */
|
/* More or less a data-driven layer factory */
|
||||||
public interface MapOverlay {
|
public interface MapOverlay {
|
||||||
|
|||||||
@@ -9,8 +9,12 @@ import eu.konggdev.strikemaps.map.MapComponent;
|
|||||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
||||||
|
|
||||||
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
||||||
|
import eu.konggdev.strikemaps.map.source.MapSource;
|
||||||
import eu.konggdev.strikemaps.provider.LocationDataProvider;
|
import eu.konggdev.strikemaps.provider.LocationDataProvider;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.maplibre.android.style.layers.CircleLayer;
|
import org.maplibre.android.style.layers.CircleLayer;
|
||||||
|
import org.maplibre.android.style.layers.Layer;
|
||||||
import org.maplibre.android.style.layers.Property;
|
import org.maplibre.android.style.layers.Property;
|
||||||
import org.maplibre.android.style.sources.GeoJsonSource;
|
import org.maplibre.android.style.sources.GeoJsonSource;
|
||||||
import org.maplibre.geojson.Feature;
|
import org.maplibre.geojson.Feature;
|
||||||
|
|||||||
@@ -4,17 +4,22 @@ import android.view.View;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
import eu.konggdev.strikemaps.helper.FileHelper;
|
||||||
import eu.konggdev.strikemaps.helper.UserPrefsHelper;
|
import eu.konggdev.strikemaps.helper.UserPrefsHelper;
|
||||||
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
||||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
||||||
import eu.konggdev.strikemaps.map.renderer.MapRenderer;
|
import eu.konggdev.strikemaps.map.renderer.MapRenderer;
|
||||||
|
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.maplibre.android.MapLibre;
|
import org.maplibre.android.MapLibre;
|
||||||
import org.maplibre.android.geometry.LatLng;
|
import org.maplibre.android.geometry.LatLng;
|
||||||
import org.maplibre.android.maps.MapLibreMap;
|
import org.maplibre.android.maps.MapLibreMap;
|
||||||
import org.maplibre.android.maps.MapView;
|
import org.maplibre.android.maps.MapView;
|
||||||
import org.maplibre.android.maps.OnMapReadyCallback;
|
import org.maplibre.android.maps.OnMapReadyCallback;
|
||||||
import org.maplibre.android.maps.Style;
|
import org.maplibre.android.maps.Style;
|
||||||
|
import org.maplibre.android.style.layers.Layer;
|
||||||
import org.maplibre.geojson.Feature;
|
import org.maplibre.geojson.Feature;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -44,11 +49,21 @@ public class MapLibreNativeRenderer implements MapRenderer, OnMapReadyCallback {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void reload() {
|
||||||
map.setStyle(new Style.Builder().fromJson(controller.style), style -> {
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
for(MapOverlay overlay : controller.overlays.values()) {
|
try {
|
||||||
passLayer(overlay.makeLayer());
|
MapStyle style = controller.getStyle();
|
||||||
}
|
ObjectNode root = style.metadata.deepCopy();
|
||||||
});
|
root.set("sources", mapper.valueToTree(style.sources));
|
||||||
|
root.set("layers", style.layerDefinitions);
|
||||||
|
map.setStyle(new Style.Builder().fromJson(mapper.writeValueAsString(root)), intStyle -> {
|
||||||
|
for(MapOverlay overlay : controller.overlays.values()) {
|
||||||
|
passLayer(overlay.makeLayer());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch ( Exception e ) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,7 +80,7 @@ public class MapLibreNativeRenderer implements MapRenderer, OnMapReadyCallback {
|
|||||||
public void onMapReady(@NonNull MapLibreMap maplibreMap) {
|
public void onMapReady(@NonNull MapLibreMap maplibreMap) {
|
||||||
this.map = maplibreMap;
|
this.map = maplibreMap;
|
||||||
|
|
||||||
controller.style = FileHelper.loadStringFromAssetFile(UserPrefsHelper.startupMapStyle(app.getPrefs()), app);
|
controller.setStyle(MapStyle.fromMapLibreJsonFile(UserPrefsHelper.startupMapStyle(app.getPrefs()), app));
|
||||||
|
|
||||||
//I have my own implementation of attribution that credits MapLibre among others, it's not as bad as it looks :)
|
//I have my own implementation of attribution that credits MapLibre among others, it's not as bad as it looks :)
|
||||||
map.getUiSettings().setLogoEnabled(false);
|
map.getUiSettings().setLogoEnabled(false);
|
||||||
@@ -73,6 +88,6 @@ public class MapLibreNativeRenderer implements MapRenderer, OnMapReadyCallback {
|
|||||||
|
|
||||||
map.addOnMapClickListener(point -> controller.onMapClick(point));
|
map.addOnMapClickListener(point -> controller.onMapClick(point));
|
||||||
map.addOnMapLongClickListener(point -> controller.onMapLongClick(point));
|
map.addOnMapLongClickListener(point -> controller.onMapLongClick(point));
|
||||||
this.reload();
|
//this.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
package eu.konggdev.strikemaps.map.source;
|
package eu.konggdev.strikemaps.map.source;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class MapSource {
|
public class MapSource {
|
||||||
public final String url;
|
public String type;
|
||||||
public final String type;
|
public String url;
|
||||||
public final String schema;
|
public String schema;
|
||||||
public MapSource(String url, String type, String schema) {
|
|
||||||
this.url = url;
|
@JsonIgnore
|
||||||
this.type = type;
|
public JsonNode raw;
|
||||||
this.schema = schema;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,28 @@
|
|||||||
package eu.konggdev.strikemaps.map.style;
|
package eu.konggdev.strikemaps.map.style;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import eu.konggdev.strikemaps.app.AppController;
|
import eu.konggdev.strikemaps.app.AppController;
|
||||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
import eu.konggdev.strikemaps.helper.FileHelper;
|
||||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
||||||
import eu.konggdev.strikemaps.map.source.MapSource;
|
import eu.konggdev.strikemaps.map.source.MapSource;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
public class MapStyle {
|
public class MapStyle {
|
||||||
public int version;
|
//Only local data
|
||||||
public String name;
|
public String name;
|
||||||
public String icon;
|
public Bitmap icon;
|
||||||
public String description;
|
|
||||||
|
|
||||||
|
public JsonNode metadata; // everything except layers + sources
|
||||||
public Map<String, MapSource> sources;
|
public Map<String, MapSource> sources;
|
||||||
public List<MapLayer> layers;
|
public JsonNode layerDefinitions; // the "layers" array
|
||||||
|
|
||||||
public JsonNode raw;
|
|
||||||
|
|
||||||
//FIXME
|
//FIXME
|
||||||
public static MapStyle fromMapLibreJsonFile(String filename, AppController app) {
|
public static MapStyle fromMapLibreJsonFile(String filename, AppController app) {
|
||||||
@@ -30,34 +33,38 @@ public class MapStyle {
|
|||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
try {
|
try {
|
||||||
JsonNode root = mapper.readTree(styleContents);
|
JsonNode root = mapper.readTree(styleContents);
|
||||||
MapStyle style = new MapStyle();
|
|
||||||
|
|
||||||
style.version = root.path("version").asInt();
|
MapStyle style = new MapStyle();
|
||||||
style.name = root.path("name").asText();
|
style.name = root.path("name").asText();
|
||||||
style.icon = root.path("icon").asText();
|
style.icon = getIcon(root.path("icon").asText(), app);
|
||||||
style.description = root.path("description").asText();
|
|
||||||
|
|
||||||
style.sources = mapper.convertValue(
|
style.sources = mapper.convertValue(
|
||||||
root.path("sources"),
|
root.path("sources"),
|
||||||
new TypeReference<Map<String, MapSource>>() {}
|
new TypeReference<Map<String, MapSource>>() {}
|
||||||
);
|
);
|
||||||
|
|
||||||
style.layers = new ArrayList<>();
|
style.layerDefinitions = root.path("layers");
|
||||||
for (JsonNode layerNode : root.path("layers")) {
|
|
||||||
|
|
||||||
MapLayer layer = mapper.treeToValue(layerNode, MapLayer.class);
|
ObjectNode metadata = root.deepCopy();
|
||||||
|
metadata.remove("layers");
|
||||||
layer.raw = layerNode; // IMPORTANT
|
metadata.remove("sources");
|
||||||
|
style.metadata = metadata;
|
||||||
style.layers.add(layer);
|
|
||||||
}
|
|
||||||
|
|
||||||
style.raw = root; // full backup
|
|
||||||
|
|
||||||
return style;
|
return style;
|
||||||
} catch ( Exception e ) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Bitmap getIcon(String iconLocator, AppController app) {
|
||||||
|
switch(iconLocator.split("//")[0]) {
|
||||||
|
//TODO: https
|
||||||
|
case "assets:":
|
||||||
|
return BitmapFactory.decodeStream(FileHelper.openAssetStream("bundled/icon/" + iconLocator.split("//")[1], app));
|
||||||
|
default:
|
||||||
|
app.logcat("Unimplemented icon locator space: " + iconLocator);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,22 @@
|
|||||||
package eu.konggdev.strikemaps.ui.element.item;
|
package eu.konggdev.strikemaps.ui.element.item;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import eu.konggdev.strikemaps.R;
|
import eu.konggdev.strikemaps.R;
|
||||||
import eu.konggdev.strikemaps.app.AppController;
|
|
||||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
|
||||||
import eu.konggdev.strikemaps.map.MapComponent;
|
import eu.konggdev.strikemaps.map.MapComponent;
|
||||||
|
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||||
import eu.konggdev.strikemaps.ui.UIComponent;
|
import eu.konggdev.strikemaps.ui.UIComponent;
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public class GenericItem implements UIItem {
|
public class GenericItem implements UIItem {
|
||||||
@NonNull public String name;
|
@NonNull public String name;
|
||||||
public Bitmap image;
|
public Bitmap image;
|
||||||
public Runnable onClick;
|
public Runnable onClick;
|
||||||
boolean hasImage;
|
boolean hasImage;
|
||||||
|
|
||||||
public GenericItem(String refName) {
|
public GenericItem(String refName) {
|
||||||
this.name = refName;
|
this.name = refName;
|
||||||
hasImage = false;
|
hasImage = false;
|
||||||
@@ -41,29 +37,10 @@ public class GenericItem implements UIItem {
|
|||||||
this.onClick = onClick;
|
this.onClick = onClick;
|
||||||
hasImage = true;
|
hasImage = true;
|
||||||
}
|
}
|
||||||
|
public final static GenericItem fromStyle(MapStyle style, MapComponent map) {
|
||||||
//FIXME: Ugly glue static constructor
|
//if(style.icon != null)
|
||||||
public final static GenericItem fromStyle(String style, AppController app, MapComponent map) {
|
//return new GenericItem(style.name, () -> map.setStyle(style));
|
||||||
try {
|
return new GenericItem(style.name, () -> map.setStyle(style));
|
||||||
JSONObject styleJson = new JSONObject(style);
|
|
||||||
String name = "Unknown"; //Fallback name
|
|
||||||
if (styleJson.has("name")) name = styleJson.getString("name");
|
|
||||||
if (styleJson.has("icon")) {
|
|
||||||
switch(styleJson.getString("icon").split("//")[0]) {
|
|
||||||
//TODO: https
|
|
||||||
case "assets:":
|
|
||||||
Bitmap icon = BitmapFactory.decodeStream(FileHelper.openAssetStream("bundled/icon/" + styleJson.getString("icon").split("//")[1], app));
|
|
||||||
return new GenericItem(name, icon, () -> map.setStyle(style));
|
|
||||||
default:
|
|
||||||
app.logcat("Unimplemented icon source requested in style: " + name);
|
|
||||||
return new GenericItem(name, () -> map.setStyle(style));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new GenericItem(name, () -> map.setStyle(style));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return new GenericItem("Exception!", () -> map.setStyle(style));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public View makeView(UIComponent spawner) {
|
public View makeView(UIComponent spawner) {
|
||||||
View v = spawner.inflateUi(R.layout.item_generic);
|
View v = spawner.inflateUi(R.layout.item_generic);
|
||||||
|
|||||||
@@ -7,18 +7,24 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import eu.konggdev.strikemaps.R;
|
import eu.konggdev.strikemaps.R;
|
||||||
import eu.konggdev.strikemaps.app.AppController;
|
import eu.konggdev.strikemaps.app.AppController;
|
||||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
import eu.konggdev.strikemaps.helper.FileHelper;
|
||||||
import eu.konggdev.strikemaps.factory.AlertDialogFactory;
|
import eu.konggdev.strikemaps.factory.AlertDialogFactory;
|
||||||
import eu.konggdev.strikemaps.map.MapComponent;
|
import eu.konggdev.strikemaps.map.MapComponent;
|
||||||
|
|
||||||
|
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||||
import eu.konggdev.strikemaps.ui.UIComponent;
|
import eu.konggdev.strikemaps.ui.UIComponent;
|
||||||
import eu.konggdev.strikemaps.ui.element.item.GenericItem;
|
import eu.konggdev.strikemaps.ui.element.item.GenericItem;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
public class FragmentMapChangePopup extends Fragment implements Popup {
|
public class FragmentMapChangePopup extends Fragment implements Popup {
|
||||||
@@ -35,6 +41,7 @@ public class FragmentMapChangePopup extends Fragment implements Popup {
|
|||||||
this.ui = app.getUi();
|
this.ui = app.getUi();
|
||||||
this.region = region;
|
this.region = region;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getRegion() {
|
public Integer getRegion() {
|
||||||
return region;
|
return region;
|
||||||
@@ -50,12 +57,10 @@ public class FragmentMapChangePopup extends Fragment implements Popup {
|
|||||||
//FIXME
|
//FIXME
|
||||||
setupButton(view, R.id.closeButton, click(() -> ui.getCurrentScreen().closePopup()));
|
setupButton(view, R.id.closeButton, click(() -> ui.getCurrentScreen().closePopup()));
|
||||||
setupDragHandle(view, view, () -> ui.getCurrentScreen().closePopup());
|
setupDragHandle(view, view, () -> ui.getCurrentScreen().closePopup());
|
||||||
String[] stylePaths = ArrayUtils.addAll(FileHelper.getAssetFiles("bundled/style", ".style.json", app), FileHelper.getUserFiles("style", ".style.json", app));
|
List<String> stylePaths = Stream.concat(
|
||||||
List<View> views = new ArrayList<>();
|
Arrays.stream(FileHelper.getAssetFiles("bundled/style", ".style.json", app)),
|
||||||
LinearLayout stylesLayout = view.findViewById(R.id.stylesLayout);
|
Arrays.stream(FileHelper.getUserFiles("style", ".style.json", app))
|
||||||
for(String i : stylePaths) {
|
).collect(Collectors.toList()); LinearLayout stylesLayout = view.findViewById(R.id.stylesLayout);
|
||||||
if(i.startsWith("/storage")) stylesLayout.addView(GenericItem.fromStyle(FileHelper.loadStringFromUserFile(i), app, map).makeView(ui));
|
stylePaths.forEach(style -> stylesLayout.addView(GenericItem.fromStyle(MapStyle.fromMapLibreJsonFile(style, app), map).makeView(ui)));
|
||||||
else stylesLayout.addView(GenericItem.fromStyle(FileHelper.loadStringFromAssetFile(i, app), app, map).makeView(ui));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user