Merge branch 'r3.9' into mapillary_plugin

# Conflicts:
#	OsmAnd/src/net/osmand/plus/OsmandPlugin.java
#	OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java
#	OsmAnd/src/net/osmand/plus/openplacereviews/OpenPlaceReviewsPlugin.java
This commit is contained in:
Vitaliy 2021-02-03 16:52:50 +02:00
commit a69b8b23d5
7 changed files with 44 additions and 41 deletions

View file

@ -212,13 +212,13 @@ public abstract class OsmandPlugin {
return Collections.emptyList();
}
protected List<ImageCard> getImageCards(@NonNull Map<String, String> params,
protected List<ImageCard> getContextMenuImageCards(@NonNull Map<String, String> params,
@Nullable Map<String, String> 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<ImageCard> imageCards, @NonNull Map<String, String> params,
public static void populateContextMenuImageCards(@NonNull List<ImageCard> imageCards, @NonNull Map<String, String> params,
@Nullable Map<String, String> 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;
}

View file

@ -63,7 +63,7 @@ class GpxOrFavouritesImportTask extends BaseLoadAsyncTask<Void, Void, GPXFile> {
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);

View file

@ -49,7 +49,7 @@ class KmzImportTask extends BaseLoadAsyncTask<Void, Void, GPXFile> {
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);

View file

@ -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));
}
}
}));

View file

@ -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<ImageCard> doInBackground(Void... voids) {
TrafficStats.setThreadStatsTag(GET_IMAGE_CARD_THREAD_ID);
List<ImageCard> result = new ArrayList<>();
OsmandPlugin.populateContextMenuImageCards(result, listener);
try {
final Map<String, String> 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);

View file

@ -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;

View file

@ -87,7 +87,7 @@ public class OpenPlaceReviewsPlugin extends OsmandPlugin {
}
@Override
protected List<ImageCard> getImageCards(@NonNull Map<String, String> params,
protected List<ImageCard> getContextMenuImageCards(@NonNull Map<String, String> params,
@Nullable Map<String, String> additionalParams,
@Nullable GetImageCardsListener listener) {
List<ImageCard> 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");