From 457c90f945c5c867b160dade4e755b9834bfcacc Mon Sep 17 00:00:00 2001 From: max-klaus Date: Wed, 3 Feb 2021 16:10:46 +0300 Subject: [PATCH 1/3] Fix kmz reading --- .../net/osmand/plus/importfiles/GpxOrFavouritesImportTask.java | 2 +- OsmAnd/src/net/osmand/plus/importfiles/KmzImportTask.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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); From 2a4818f6300513bda871ad8e4f81f818482f93d9 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 3 Feb 2021 16:40:24 +0200 Subject: [PATCH 2/3] Move IPFSImageCard to plugin --- .../plus/mapcontextmenu/MenuBuilder.java | 44 ++++++++++--------- .../builders/cards/ImageCard.java | 8 ---- .../IPFSImageCard.java | 4 +- .../OpenPlaceReviewsPlugin.java | 10 ++++- 4 files changed, 34 insertions(+), 32 deletions(-) rename OsmAnd/src/net/osmand/plus/{mapcontextmenu/builders/cards => openplacereviews}/IPFSImageCard.java (93%) 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 1c2339648e..c754e6fc84 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -196,14 +196,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; } 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 abf4d23b0e..42a8399c34 100644 --- a/OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java @@ -120,7 +120,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); } @@ -137,6 +137,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"); From 0514a49ba130e7b6afab63b1ad2be54beec276a8 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 3 Feb 2021 16:47:31 +0200 Subject: [PATCH 3/3] Rename methods --- OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 6 +++--- .../plus/mapcontextmenu/builders/cards/ImageCard.java | 2 +- .../plus/openplacereviews/OpenPlaceReviewsPlugin.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index aadeed5671..62ba9b40f5 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -211,7 +211,7 @@ public abstract class OsmandPlugin { return Collections.emptyList(); } - protected List getImageCards(@Nullable GetImageCardsListener listener) { + protected List getContextMenuImageCards(@Nullable GetImageCardsListener listener) { return Collections.emptyList(); } @@ -875,9 +875,9 @@ public abstract class OsmandPlugin { return collection; } - public static void populateImageCards(@NonNull List imageCards, @Nullable GetImageCardsListener listener) { + public static void populateContextMenuImageCards(@NonNull List imageCards, @Nullable GetImageCardsListener listener) { for (OsmandPlugin p : getEnabledPlugins()) { - imageCards.addAll(p.getImageCards(listener)); + imageCards.addAll(p.getContextMenuImageCards(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 c754e6fc84..b4a473531a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -431,7 +431,7 @@ public abstract class ImageCard extends AbstractCard { protected List doInBackground(Void... params) { TrafficStats.setThreadStatsTag(GET_IMAGE_CARD_THREAD_ID); List result = new ArrayList<>(); - OsmandPlugin.populateImageCards(result, listener); + OsmandPlugin.populateContextMenuImageCards(result, listener); try { final Map pms = new LinkedHashMap<>(); pms.put("lat", "" + (float) latLon.getLatitude()); diff --git a/OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java b/OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java index 42a8399c34..48c506a2a5 100644 --- a/OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java @@ -85,7 +85,7 @@ public class OpenPlaceReviewsPlugin extends OsmandPlugin { } @Override - protected List getImageCards(@Nullable GetImageCardsListener listener) { + protected List getContextMenuImageCards(@Nullable GetImageCardsListener listener) { List imageCards = new ArrayList<>(); if (mapActivity != null) { Object object = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObject();