This commit is contained in:
Alexey Kulish 2017-10-17 20:47:38 +03:00
parent 2bc6f59534
commit 053418c1c3
5 changed files with 112 additions and 5 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.ImageCard;
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.render.RenderingIcons;
import net.osmand.util.Algorithms;
@ -55,6 +54,7 @@ import java.util.LinkedList;
import java.util.List;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.*;
public class MenuBuilder {
@ -349,7 +349,7 @@ public class MenuBuilder {
@Override
public void onCollapseExpand(boolean collapsed) {
if (!collapsed && onlinePhotoCards == null) {
startLoadingImages(MenuBuilder.this);
startLoadingImages();
}
}
});
@ -359,18 +359,22 @@ public class MenuBuilder {
if (needUpdateOnly && onlinePhotoCards != null) {
onlinePhotoCardsRow.setCards(onlinePhotoCards);
} else if (!collapsableView.isCollapsed()) {
startLoadingImages(this);
startLoadingImages();
}
}
private void startLoadingImages(final MenuBuilder menuBuilder) {
private void startLoadingImages() {
onlinePhotoCards = new ArrayList<>();
onlinePhotoCardsRow.setProgressCard();
<<<<<<< HEAD
execute(new GetImageCardsTask(mapActivity, menuBuilder.getLatLon(),
=======
execute(new GetImageCardsTask(mapActivity, getLatLon(), getAdditionalCardParams(),
>>>>>>> dbb72952c7... Fix osm image/mapillary processing
new GetImageCardsListener() {
@Override
public void onFinish(List<ImageCard> cardList) {
if (!menuBuilder.isHidden()) {
if (!isHidden()) {
List<AbstractCard> cards = new ArrayList<>();
cards.addAll(cardList);
if (cardList.size() == 0) {

View file

@ -506,6 +506,24 @@ public class AmenityMenuBuilder extends MenuBuilder {
}
}
<<<<<<< HEAD
=======
@Override
protected Map<String, String> getAdditionalCardParams() {
Map<String, String> params = new HashMap<>();
Map<String, String> additionalInfo = amenity.getAdditionalInfo();
String imageValue = additionalInfo.get("image");
String mapillaryValue = additionalInfo.get("mapillary");
if (!Algorithms.isEmpty(imageValue)) {
params.put("osm_image", imageValue);
}
if (!Algorithms.isEmpty(mapillaryValue)) {
params.put("osm_mapillary_key", mapillaryValue);
}
return params;
}
>>>>>>> dbb72952c7... Fix osm image/mapillary processing
private static class AmenityInfoRow {
private String key;
private Drawable icon;

View file

@ -14,6 +14,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import net.osmand.plus.OsmandApplication;
@ -83,6 +84,13 @@ public abstract class AbstractCard {
});
final WebView wv = new WebView(ctx);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
WebSettings settings = wv.getSettings();
/*
settings.setDefaultTextEncodingName("utf-8");

View file

@ -85,6 +85,7 @@ public abstract class ImageCard extends AbstractCard {
public ImageCard(MapActivity mapActivity, JSONObject imageObject) {
super(mapActivity);
<<<<<<< HEAD
try {
if (imageObject.has("type")) {
this.type = imageObject.getString("type");
@ -102,6 +103,58 @@ public abstract class ImageCard extends AbstractCard {
this.timestamp = DATE_FORMAT.parse(imageObject.getString("timestamp"));
} catch (ParseException e) {
e.printStackTrace();
=======
if (imageObject != null) {
try {
if (imageObject.has("type")) {
this.type = imageObject.getString("type");
}
if (imageObject.has("ca") && !imageObject.isNull("ca")) {
this.ca = imageObject.getDouble("ca");
}
if (imageObject.has("lat") && imageObject.has("lon")
&& !imageObject.isNull("lat") && !imageObject.isNull("lon")) {
double latitude = imageObject.getDouble("lat");
double longitude = imageObject.getDouble("lon");
this.location = new LatLon(latitude, longitude);
}
if (imageObject.has("timestamp")) {
try {
this.timestamp = DATE_FORMAT.parse(imageObject.getString("timestamp"));
} catch (ParseException e) {
e.printStackTrace();
}
}
if (imageObject.has("key")) {
this.key = imageObject.getString("key");
}
if (imageObject.has("title") && !imageObject.isNull("title")) {
this.title = imageObject.getString("title");
}
if (imageObject.has("username") && !imageObject.isNull("username")) {
this.userName = imageObject.getString("username");
}
if (imageObject.has("url") && !imageObject.isNull("url")) {
this.url = imageObject.getString("url");
}
if (imageObject.has("imageUrl") && !imageObject.isNull("imageUrl")) {
this.imageUrl = imageObject.getString("imageUrl");
}
if (imageObject.has("imageHiresUrl") && !imageObject.isNull("imageHiresUrl")) {
this.imageHiresUrl = imageObject.getString("imageHiresUrl");
}
if (imageObject.has("externalLink") && !imageObject.isNull("externalLink")) {
this.externalLink = imageObject.getBoolean("externalLink");
}
if (imageObject.has("topIcon") && !imageObject.isNull("topIcon")) {
this.topIconId = getDrawableId(imageObject.getString("topIcon"));
}
if (imageObject.has("buttonIcon") && !imageObject.isNull("buttonIcon")) {
this.buttonIconId = getDrawableId(imageObject.getString("buttonIcon"));
}
if (imageObject.has("buttonText") && !imageObject.isNull("buttonText")) {
this.buttonText = imageObject.getString("buttonText");
>>>>>>> dbb72952c7... Fix osm image/mapillary processing
}
}
if (imageObject.has("key")) {
@ -465,6 +518,9 @@ public abstract class ImageCard extends AbstractCard {
downloading = false;
downloaded = true;
ImageCard.this.bitmap = bitmap;
if (bitmap != null && Algorithms.isEmpty(getImageHiresUrl())) {
ImageCard.this.imageHiresUrl = getUrl();
}
update();
}
}

View file

@ -12,11 +12,22 @@ public class UrlImageCard extends ImageCard {
public UrlImageCard(MapActivity mapActivity, JSONObject imageObject) {
super(mapActivity, imageObject);
<<<<<<< HEAD
if (!Algorithms.isEmpty(getUrl())) {
OnClickListener onClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
openUrl(getMapActivity(), getMyApplication(), "", getUrl(), isExternalLink());
=======
if (!Algorithms.isEmpty(getSuitableUrl())) {
OnClickListener onClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
openUrl(getMapActivity(), getMyApplication(), getTitle(), getSuitableUrl(),
isExternalLink() || Algorithms.isEmpty(getImageHiresUrl()),
!Algorithms.isEmpty(getImageHiresUrl()));
>>>>>>> dbb72952c7... Fix osm image/mapillary processing
}
};
if (!Algorithms.isEmpty(buttonText)) {
@ -26,4 +37,14 @@ public class UrlImageCard extends ImageCard {
}
}
}
private String getSuitableUrl() {
final String url;
if (Algorithms.isEmpty(getImageHiresUrl())) {
url = getUrl();
} else {
url = getImageHiresUrl();
}
return url;
}
}