Fix osm image/mapillary processing

This commit is contained in:
Alexey Kulish 2017-10-17 20:47:38 +03:00
parent 7eff262dca
commit 5df51ebe3c
5 changed files with 40 additions and 26 deletions

View file

@ -42,7 +42,6 @@ import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard;
import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder; import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask; import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard; import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard;
import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.render.RenderingIcons;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -56,6 +55,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import static android.util.TypedValue.COMPLEX_UNIT_DIP; import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.*;
public class MenuBuilder { public class MenuBuilder {
@ -350,7 +350,7 @@ public class MenuBuilder {
@Override @Override
public void onCollapseExpand(boolean collapsed) { public void onCollapseExpand(boolean collapsed) {
if (!collapsed && onlinePhotoCards == null) { if (!collapsed && onlinePhotoCards == null) {
startLoadingImages(MenuBuilder.this); startLoadingImages();
} }
} }
}); });
@ -360,14 +360,14 @@ public class MenuBuilder {
if (needUpdateOnly && onlinePhotoCards != null) { if (needUpdateOnly && onlinePhotoCards != null) {
onlinePhotoCardsRow.setCards(onlinePhotoCards); onlinePhotoCardsRow.setCards(onlinePhotoCards);
} else if (!collapsableView.isCollapsed()) { } else if (!collapsableView.isCollapsed()) {
startLoadingImages(this); startLoadingImages();
} }
} }
private void startLoadingImages(final MenuBuilder menuBuilder) { private void startLoadingImages() {
onlinePhotoCards = new ArrayList<>(); onlinePhotoCards = new ArrayList<>();
onlinePhotoCardsRow.setProgressCard(); onlinePhotoCardsRow.setProgressCard();
execute(new GetImageCardsTask(mapActivity, menuBuilder.getLatLon(), getAdditionalCardParams(), execute(new GetImageCardsTask(mapActivity, getLatLon(), getAdditionalCardParams(),
new GetImageCardsListener() { new GetImageCardsListener() {
@Override @Override
public void onPostProcess(List<ImageCard> cardList) { public void onPostProcess(List<ImageCard> cardList) {
@ -376,7 +376,7 @@ public class MenuBuilder {
@Override @Override
public void onFinish(List<ImageCard> cardList) { public void onFinish(List<ImageCard> cardList) {
if (!menuBuilder.isHidden()) { if (!isHidden()) {
List<AbstractCard> cards = new ArrayList<>(); List<AbstractCard> cards = new ArrayList<>();
cards.addAll(cardList); cards.addAll(cardList);
if (cardList.size() == 0) { if (cardList.size() == 0) {

View file

@ -518,10 +518,10 @@ public class AmenityMenuBuilder extends MenuBuilder {
String imageValue = additionalInfo.get("image"); String imageValue = additionalInfo.get("image");
String mapillaryValue = additionalInfo.get("mapillary"); String mapillaryValue = additionalInfo.get("mapillary");
if (!Algorithms.isEmpty(imageValue)) { if (!Algorithms.isEmpty(imageValue)) {
params.put("image", imageValue); params.put("osm_image", imageValue);
} }
if (!Algorithms.isEmpty(mapillaryValue)) { if (!Algorithms.isEmpty(mapillaryValue)) {
params.put("mapillary", mapillaryValue); params.put("osm_mapillary_key", mapillaryValue);
} }
return params; return params;
} }

View file

@ -16,6 +16,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -89,6 +90,13 @@ public abstract class AbstractCard {
}); });
final WebView wv = new WebView(ctx); final WebView wv = new WebView(ctx);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
WebSettings settings = wv.getSettings(); WebSettings settings = wv.getSettings();
if (hasImageUrl) { if (hasImageUrl) {

View file

@ -98,7 +98,8 @@ public abstract class ImageCard extends AbstractCard {
if (imageObject.has("ca") && !imageObject.isNull("ca")) { if (imageObject.has("ca") && !imageObject.isNull("ca")) {
this.ca = imageObject.getDouble("ca"); this.ca = imageObject.getDouble("ca");
} }
if (imageObject.has("lat") && imageObject.has("lon")) { if (imageObject.has("lat") && imageObject.has("lon")
&& !imageObject.isNull("lat") && !imageObject.isNull("lon")) {
double latitude = imageObject.getDouble("lat"); double latitude = imageObject.getDouble("lat");
double longitude = imageObject.getDouble("lon"); double longitude = imageObject.getDouble("lon");
this.location = new LatLon(latitude, longitude); this.location = new LatLon(latitude, longitude);
@ -113,19 +114,19 @@ public abstract class ImageCard extends AbstractCard {
if (imageObject.has("key")) { if (imageObject.has("key")) {
this.key = imageObject.getString("key"); this.key = imageObject.getString("key");
} }
if (imageObject.has("title")) { if (imageObject.has("title") && !imageObject.isNull("title")) {
this.title = imageObject.getString("title"); this.title = imageObject.getString("title");
} }
if (imageObject.has("username")) { if (imageObject.has("username") && !imageObject.isNull("username")) {
this.userName = imageObject.getString("username"); this.userName = imageObject.getString("username");
} }
if (imageObject.has("url")) { if (imageObject.has("url") && !imageObject.isNull("url")) {
this.url = imageObject.getString("url"); this.url = imageObject.getString("url");
} }
if (imageObject.has("imageUrl")) { if (imageObject.has("imageUrl") && !imageObject.isNull("imageUrl")) {
this.imageUrl = imageObject.getString("imageUrl"); this.imageUrl = imageObject.getString("imageUrl");
} }
if (imageObject.has("imageHiresUrl")) { if (imageObject.has("imageHiresUrl") && !imageObject.isNull("imageHiresUrl")) {
this.imageHiresUrl = imageObject.getString("imageHiresUrl"); this.imageHiresUrl = imageObject.getString("imageHiresUrl");
} }
if (imageObject.has("externalLink") && !imageObject.isNull("externalLink")) { if (imageObject.has("externalLink") && !imageObject.isNull("externalLink")) {
@ -498,6 +499,9 @@ public abstract class ImageCard extends AbstractCard {
downloading = false; downloading = false;
downloaded = true; downloaded = true;
ImageCard.this.bitmap = bitmap; ImageCard.this.bitmap = bitmap;
if (bitmap != null && Algorithms.isEmpty(getImageHiresUrl())) {
ImageCard.this.imageHiresUrl = getUrl();
}
update(); update();
} }
} }

View file

@ -13,21 +13,13 @@ public class UrlImageCard extends ImageCard {
public UrlImageCard(MapActivity mapActivity, JSONObject imageObject) { public UrlImageCard(MapActivity mapActivity, JSONObject imageObject) {
super(mapActivity, imageObject); super(mapActivity, imageObject);
final String url; if (!Algorithms.isEmpty(getSuitableUrl())) {
final boolean hasImageUrl;
if (Algorithms.isEmpty(getImageHiresUrl())) {
url = getUrl();
hasImageUrl = false;
} else {
url = getImageHiresUrl();
hasImageUrl = true;
}
if (!Algorithms.isEmpty(url)) {
OnClickListener onClickListener = new OnClickListener() { OnClickListener onClickListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
openUrl(getMapActivity(), getMyApplication(), getTitle(), url, isExternalLink(), hasImageUrl); openUrl(getMapActivity(), getMyApplication(), getTitle(), getSuitableUrl(),
isExternalLink() || Algorithms.isEmpty(getImageHiresUrl()),
!Algorithms.isEmpty(getImageHiresUrl()));
} }
}; };
if (!Algorithms.isEmpty(buttonText)) { if (!Algorithms.isEmpty(buttonText)) {
@ -37,4 +29,14 @@ public class UrlImageCard extends ImageCard {
} }
} }
} }
private String getSuitableUrl() {
final String url;
if (Algorithms.isEmpty(getImageHiresUrl())) {
url = getUrl();
} else {
url = getImageHiresUrl();
}
return url;
}
} }