diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index e0fa8c3bc7..d3bcfb205e 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -212,13 +212,13 @@ public abstract class OsmandPlugin { return Collections.emptyList(); } - protected List getImageCards(@NonNull Map params, + protected List getContextMenuImageCards(@NonNull Map params, @Nullable Map additionalParams, @Nullable GetImageCardsListener listener) { return Collections.emptyList(); } - protected ImageCard createImageCard(@NonNull JSONObject imageObject) { + protected ImageCard createContextMenuImageCard(@NonNull JSONObject imageObject) { return null; } @@ -882,16 +882,16 @@ public abstract class OsmandPlugin { return collection; } - public static void populateImageCards(@NonNull List imageCards, @NonNull Map params, + public static void populateContextMenuImageCards(@NonNull List imageCards, @NonNull Map params, @Nullable Map additionalParams, @Nullable GetImageCardsListener listener) { for (OsmandPlugin plugin : getEnabledPlugins()) { - imageCards.addAll(plugin.getImageCards(params, additionalParams, listener)); + imageCards.addAll(plugin.getContextMenuImageCards(params, additionalParams, listener)); } } public static ImageCard createImageCardForJson(@NonNull JSONObject imageObject) { for (OsmandPlugin plugin : getEnabledPlugins()) { - ImageCard imageCard = plugin.createImageCard(imageObject); + ImageCard imageCard = plugin.createContextMenuImageCard(imageObject); if (imageCard != null) { return imageCard; } diff --git a/OsmAnd/src/net/osmand/plus/importfiles/GpxOrFavouritesImportTask.java b/OsmAnd/src/net/osmand/plus/importfiles/GpxOrFavouritesImportTask.java index 9ae0e9b59b..7286c7ee19 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/GpxOrFavouritesImportTask.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/GpxOrFavouritesImportTask.java @@ -63,7 +63,7 @@ class GpxOrFavouritesImportTask extends BaseLoadAsyncTask { ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { if (entry.getName().endsWith(ImportHelper.KML_SUFFIX)) { - InputStream gpxStream = convertKmlToGpxStream(is); + InputStream gpxStream = convertKmlToGpxStream(zis); if (gpxStream != null) { fileSize = gpxStream.available(); return GPXUtilities.loadGPXFile(gpxStream); diff --git a/OsmAnd/src/net/osmand/plus/importfiles/KmzImportTask.java b/OsmAnd/src/net/osmand/plus/importfiles/KmzImportTask.java index 6a145a04f7..2ed67cc0e4 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/KmzImportTask.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/KmzImportTask.java @@ -49,7 +49,7 @@ class KmzImportTask extends BaseLoadAsyncTask { ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { if (entry.getName().endsWith(KML_SUFFIX)) { - InputStream gpxStream = convertKmlToGpxStream(is); + InputStream gpxStream = convertKmlToGpxStream(zis); if (gpxStream != null) { fileSize = gpxStream.available(); return GPXUtilities.loadGPXFile(gpxStream); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index ca11b8a456..78d2b67fa7 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -63,6 +63,7 @@ import net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController; import net.osmand.plus.mapcontextmenu.controllers.TransportStopController; import net.osmand.plus.openplacereviews.AddPhotosBottomSheetDialogFragment; import net.osmand.plus.openplacereviews.OPRConstants; +import net.osmand.plus.openplacereviews.OpenPlaceReviewsPlugin; import net.osmand.plus.openplacereviews.OprStartFragment; import net.osmand.plus.osmedit.opr.OpenDBAPI; import net.osmand.plus.poi.PoiFiltersHelper; @@ -91,7 +92,7 @@ import java.util.Set; import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener; -public class MenuBuilder implements UploadPhotosListener { +public class MenuBuilder { private static final Log LOG = PlatformUtil.getLog(MenuBuilder.class); private static final int PICK_IMAGE = 1231; @@ -173,25 +174,6 @@ public class MenuBuilder implements UploadPhotosListener { } } - @Override - public void uploadPhotosSuccess(final String response) { - app.runInUIThread(new Runnable() { - @Override - public void run() { - if (AndroidUtils.isActivityNotDestroyed(mapActivity)) { - try { - ImageCard imageCard = ImageCard.createCardOpr(mapActivity, new JSONObject(response)); - if (imageCard != null) { - addImageCard(imageCard); - } - } catch (JSONException e) { - LOG.error(e); - } - } - } - }); - } - public interface CollapseExpandListener { void onCollapseExpand(boolean collapsed); } @@ -512,7 +494,27 @@ public class MenuBuilder implements UploadPhotosListener { } } } - execute(new UploadPhotosAsyncTask(mapActivity, imagesUri, placeId, MenuBuilder.this)); + UploadPhotosListener listener = new UploadPhotosListener() { + @Override + public void uploadPhotosSuccess(final String response) { + app.runInUIThread(new Runnable() { + @Override + public void run() { + if (AndroidUtils.isActivityNotDestroyed(mapActivity)) { + try { + ImageCard imageCard = OpenPlaceReviewsPlugin.createCardOpr(mapActivity, new JSONObject(response)); + if (imageCard != null) { + addImageCard(imageCard); + } + } catch (JSONException e) { + LOG.error(e); + } + } + } + }); + } + }; + execute(new UploadPhotosAsyncTask(mapActivity, imagesUri, placeId, listener)); } } })); 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 3e1f20ccfb..b72fb9d56a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -189,14 +189,6 @@ public abstract class ImageCard extends AbstractCard { return imageCard; } - public static ImageCard createCardOpr(MapActivity mapActivity, JSONObject imageObject) { - ImageCard imageCard = null; - if (imageObject.has("cid")) { - imageCard = new IPFSImageCard(mapActivity, imageObject); - } - return imageCard; - } - public double getCa() { return ca; } @@ -432,6 +424,7 @@ public abstract class ImageCard extends AbstractCard { protected List doInBackground(Void... voids) { TrafficStats.setThreadStatsTag(GET_IMAGE_CARD_THREAD_ID); List result = new ArrayList<>(); + OsmandPlugin.populateContextMenuImageCards(result, listener); try { final Map pms = new LinkedHashMap<>(); pms.put("lat", "" + (float) latLon.getLatitude()); @@ -448,7 +441,7 @@ public abstract class ImageCard extends AbstractCard { if (!Algorithms.isEmpty(preferredLang)) { pms.put("lang", preferredLang); } - OsmandPlugin.populateImageCards(result, pms, params, listener); + OsmandPlugin.populateContextMenuImageCards(result, pms, params, listener); String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms, "Requesting location images...", false, false); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java b/OsmAnd/src/net/osmand/plus/openplacereviews/IPFSImageCard.java similarity index 93% rename from OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java rename to OsmAnd/src/net/osmand/plus/openplacereviews/IPFSImageCard.java index 64bf146d56..ccf52f7de9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/IPFSImageCard.java +++ b/OsmAnd/src/net/osmand/plus/openplacereviews/IPFSImageCard.java @@ -1,4 +1,4 @@ -package net.osmand.plus.mapcontextmenu.builders.cards; +package net.osmand.plus.openplacereviews; import android.view.View; @@ -8,7 +8,7 @@ import androidx.core.content.ContextCompat; import net.osmand.PlatformUtil; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.openplacereviews.OPRConstants; +import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; diff --git a/OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java b/OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java index d099be448b..3df34da0fd 100644 --- a/OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java @@ -87,7 +87,7 @@ public class OpenPlaceReviewsPlugin extends OsmandPlugin { } @Override - protected List getImageCards(@NonNull Map params, + protected List getContextMenuImageCards(@NonNull Map params, @Nullable Map additionalParams, @Nullable GetImageCardsListener listener) { List imageCards = new ArrayList<>(); @@ -124,7 +124,7 @@ public class OpenPlaceReviewsPlugin extends OsmandPlugin { try { JSONObject imageObject = (JSONObject) images.get(i); if (imageObject != JSONObject.NULL) { - ImageCard imageCard = ImageCard.createCardOpr(mapActivity, imageObject); + ImageCard imageCard = createCardOpr(mapActivity, imageObject); if (imageCard != null) { result.add(imageCard); } @@ -141,6 +141,14 @@ public class OpenPlaceReviewsPlugin extends OsmandPlugin { } } + public static ImageCard createCardOpr(MapActivity mapActivity, JSONObject imageObject) { + ImageCard imageCard = null; + if (imageObject.has("cid")) { + imageCard = new IPFSImageCard(mapActivity, imageObject); + } + return imageCard; + } + private static String[] getIdFromResponse(String response) { try { JSONArray obj = new JSONObject(response).getJSONArray("objects");