diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 3783c501ad..e0fa8c3bc7 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -218,6 +218,10 @@ public abstract class OsmandPlugin { return Collections.emptyList(); } + protected ImageCard createImageCard(@NonNull JSONObject imageObject) { + return null; + } + /** * Plugin was installed */ @@ -880,11 +884,21 @@ public abstract class OsmandPlugin { public static void populateImageCards(@NonNull List imageCards, @NonNull Map params, @Nullable Map additionalParams, @Nullable GetImageCardsListener listener) { - for (OsmandPlugin p : getEnabledPlugins()) { - imageCards.addAll(p.getImageCards(params, additionalParams, listener)); + for (OsmandPlugin plugin : getEnabledPlugins()) { + imageCards.addAll(plugin.getImageCards(params, additionalParams, listener)); } } + public static ImageCard createImageCardForJson(@NonNull JSONObject imageObject) { + for (OsmandPlugin plugin : getEnabledPlugins()) { + ImageCard imageCard = plugin.createImageCard(imageObject); + if (imageCard != null) { + return imageCard; + } + } + return null; + } + public static boolean isPackageInstalled(String packageInfo, Context ctx) { if (packageInfo == null) { return false; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java index e25c043b62..3e1f20ccfb 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -26,8 +26,6 @@ import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MenuBuilder; -import net.osmand.plus.mapillary.MapillaryContributeCard; -import net.osmand.plus.mapillary.MapillaryImageCard; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -45,10 +43,11 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import static net.osmand.plus.mapillary.MapillaryPlugin.TYPE_MAPILLARY_CONTRIBUTE; +import static net.osmand.plus.mapillary.MapillaryPlugin.TYPE_MAPILLARY_PHOTO; + public abstract class ImageCard extends AbstractCard { - public static String TYPE_MAPILLARY_PHOTO = "mapillary-photo"; - public static String TYPE_MAPILLARY_CONTRIBUTE = "mapillary-contribute"; private static final Log LOG = PlatformUtil.getLog(ImageCard.class); protected String type; @@ -180,11 +179,7 @@ public abstract class ImageCard extends AbstractCard { try { if (imageObject.has("type")) { String type = imageObject.getString("type"); - if (TYPE_MAPILLARY_PHOTO.equals(type)) { - imageCard = new MapillaryImageCard(mapActivity, imageObject); - } else if (TYPE_MAPILLARY_CONTRIBUTE.equals(type)) { - imageCard = new MapillaryContributeCard(mapActivity, imageObject); - } else { + if (!TYPE_MAPILLARY_CONTRIBUTE.equals(type) && !TYPE_MAPILLARY_PHOTO.equals(type)) { imageCard = new UrlImageCard(mapActivity, imageObject); } } @@ -466,7 +461,10 @@ public abstract class ImageCard extends AbstractCard { try { JSONObject imageObject = (JSONObject) images.get(i); if (imageObject != JSONObject.NULL) { - ImageCard imageCard = ImageCard.createCard(mapActivity, imageObject); + ImageCard imageCard = OsmandPlugin.createImageCardForJson(imageObject); + if (imageCard == null) { + imageCard = ImageCard.createCard(mapActivity, imageObject); + } if (imageCard != null) { result.add(imageCard); } diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java index 98e9624a5f..05fb1ecffa 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java @@ -17,27 +17,34 @@ import androidx.appcompat.widget.SwitchCompat; import androidx.fragment.app.FragmentActivity; import net.osmand.AndroidUtils; +import net.osmand.PlatformUtil; import net.osmand.map.ITileSource; import net.osmand.map.TileSourceManager; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.dashboard.DashboardOnMap; -import net.osmand.plus.views.layers.MapInfoLayer; +import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; +import net.osmand.plus.openplacereviews.OpenPlaceReviewsPlugin; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.views.MapTileLayer; import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.plus.views.layers.MapInfoLayer; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget; import net.osmand.util.Algorithms; +import org.apache.commons.logging.Log; +import org.json.JSONException; +import org.json.JSONObject; + import java.text.MessageFormat; import java.util.List; @@ -47,11 +54,18 @@ import static net.osmand.plus.ContextMenuAdapter.makeDeleteAction; public class MapillaryPlugin extends OsmandPlugin { + public static String TYPE_MAPILLARY_PHOTO = "mapillary-photo"; + public static String TYPE_MAPILLARY_CONTRIBUTE = "mapillary-contribute"; + public static final String ID = "osmand.mapillary"; private static final String MAPILLARY_PACKAGE_ID = "app.mapillary"; + private static final Log LOG = PlatformUtil.getLog(OpenPlaceReviewsPlugin.class); + private OsmandSettings settings; + private MapActivity mapActivity; + private MapillaryRasterLayer rasterLayer; private MapillaryVectorLayer vectorLayer; private TextInfoWidget mapillaryControl; @@ -223,6 +237,41 @@ public class MapillaryPlugin extends OsmandPlugin { } } + @Override + protected ImageCard createImageCard(@NonNull JSONObject imageObject) { + ImageCard imageCard = null; + if (mapActivity != null) { + try { + if (imageObject.has("type")) { + String type = imageObject.getString("type"); + if (TYPE_MAPILLARY_PHOTO.equals(type)) { + imageCard = new MapillaryImageCard(mapActivity, imageObject); + } else if (TYPE_MAPILLARY_CONTRIBUTE.equals(type)) { + imageCard = new MapillaryContributeCard(mapActivity, imageObject); + } + } + } catch (JSONException e) { + LOG.error(e); + } + } + return imageCard; + } + + @Override + public void mapActivityResume(MapActivity activity) { + this.mapActivity = activity; + } + + @Override + public void mapActivityResumeOnTop(MapActivity activity) { + this.mapActivity = activity; + } + + @Override + public void mapActivityPause(MapActivity activity) { + this.mapActivity = null; + } + public static boolean openMapillary(FragmentActivity activity, String imageKey) { boolean success = false; OsmandApplication app = (OsmandApplication) activity.getApplication();